📜 ⬆️ ⬇️

Simple customization of Ubuntu LiveCD

This topic describes the simple and fast customization of the Ubuntu LiveCD.
Includes:
- installation of additional packages
- setting up a proxy server and TimeZone

Several times I already had to build my LiveCD. One for downloading over the network with a set of necessary tools, the other for burning to DVD with full support for the Japanese language and additional software. When building, I was guided by this link https://help.ubuntu.com/community/LiveCDCustomization . Everything was fine except for the time spent. Such manual assembly can sometimes take several hours, especially if the previous one was done long enough.

The last time I decided not to collect and use the Ubuntu Customization Kit described on Habré (http://habrahabr.ru/blogs/ubuntu/77331). Unfortunately at that time, and it was a few days ago, version 2.0.12 did not work (swears on unmounting .gvfs) on Ubuntu 10.04. The version from the trunk, on which I had hoped, did not work either, but with a different error.
')
As a result, I decided not to bother with the Ubuntu Customization Kit, but to write my own script based on WIKI articles with help.ubuntu.com, which covers my needs and follows the principle of KISS. The working version of the script and the description under the cut.


ubuntu-iso-customization.sh


#!/bin/bash # get configuration from the file [ -n "$1" ] && [ -f "$1" ] && source "$1" || exit 1 # prepare trap "exit 1" INT ISOMNTDIR=$LIVEDIR/mnt EXTRACTDIR=$LIVEDIR/extract-cd EDITDIR=$LIVEDIR/edit sudo aptitude install -y squashfs-tools genisoimage || exit 1 # mount livecd mkdir $LIVEDIR && cd $LIVEDIR || exit 1 mkdir $ISOMNTDIR || exit 1 sudo mount -o loop $ISODIR/ubuntu-${VERSION}.iso $ISOMNTDIR || exit 1 # extract squashfs mkdir $EXTRACTDIR || exit 1 rsync --exclude=/casper/filesystem.squashfs -a $ISOMNTDIR/ $EXTRACTDIR sudo unsquashfs $ISOMNTDIR/casper/filesystem.squashfs sudo mv squashfs-root $EDITDIR # umount livecd sudo umount $ISOMNTDIR # copy resolv.conf sudo cp /etc/resolv.conf $EDITDIR/etc/ # mount dev sudo mount --bind /dev/ $EDITDIR/dev # configure new live cd [ -n "$PROXY" ] && echo -e "$PROXY" | sudo tee -a $EDITDIR/etc/environment [ -n "$TIMEZONE" ] && echo "TZ=$TIMEZONE" | sudo tee -a $EDITDIR/etc/environment # create customization script and run it in chroot cat >> $EDITDIR/tmp/customize.sh << EOF #!/bin/bash # mount proc, sysfs, devpts mount -t proc none /proc mount -t sysfs none /sys mount -t devpts none /dev/pts # prepare choot export HOME=/root export LC_ALL=C dpkg-divert --local --rename --add /sbin/initctl ln -s /bin/true /sbin/initctl # install packages ( which software-properties-gtk && software-properties-gtk -e universe && software-properties-gtk -e multiverse ) || \ ( which software-properties-kde && software-properties-kde -e universe && software-properties-kde -e multiverse ) || \ sudoedit /etc/apt/sources.list aptitude update [ "$UPTODATE" -eq "1" ] && aptitude full-upgrade -y aptitude install -Ry $PACKAGES # clean aptitude clean rm -rf /tmp/* ~/.bash_history rm /etc/resolv.conf rm /sbin/initctl dpkg-divert --rename --remove /sbin/initctl # umount proc, sysfs, devpts umount /proc umount /sys umount /dev/pts # exit from chroot exit EOF # make customization script executable chmod +x $EDITDIR/tmp/customize.sh # chroot and run customization script sudo chroot $EDITDIR su -lc /tmp/customize.sh # umount dev sudo umount $EDITDIR/dev # regenerate manifest chmod +w $EXTRACTDIR/casper/filesystem.manifest sudo chroot $EDITDIR dpkg-query -W --showformat='${Package} ${Version}\n' > $EXTRACTDIR/casper/filesystem.manifest sudo cp $EXTRACTDIR/casper/filesystem.manifest $EXTRACTDIR/casper/filesystem.manifest-desktop sudo sed -i '/ubiquity/d' $EXTRACTDIR/casper/filesystem.manifest-desktop sudo sed -i '/casper/d' $EXTRACTDIR/casper/filesystem.manifest-desktop # compress filesystem [ -f $EXTRACTDIR/casper/filesystem.squashfs ] && \ sudo rm $EXTRACTDIR/casper/filesystem.squashs sudo mksquashfs $EDITDIR $EXTRACTDIR/casper/filesystem.squashfs # set an image name in $EXTRACTDIR/README.diskdefines sudoedit $EXTRACTDIR/README.diskdefines # remove old md5sum.txt and calculate new md5 sums cd $EXTRACTDIR sudo rm md5sum.txt find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt # create iso sudo mkisofs -D -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-$VERSION-custom.iso . 


config_example


 VERSION=10.04-desktop-i386 # Ubuntu LiveCD version ISODIR=/mnt/iso # Path to original ISO LIVEDIR=/mnt/live # Directory for building PACKAGES="mc htop testdisk chntpw" # Packages that have to be installed UPTODATE=0 # Whether "aptitude full-upgrade" have to be done TIMEZONE="Europe/Moscow" # Time Zone PROXY="http_proxy=http://172.18.0.1:3128\nftp_proxy=http://172.18.0.1:3128" # Proxy server configuration 


Description



Run:
  1. It is necessary to boot from the LiveCD (although not necessarily from the LiveCD).
  2. Mount an ext3 or ext4 file system on which at least 5Gb is free.
  3. Make yourself the owner of the directory in which we will collect the new image (LIVEDIR).
  4. Modify config_example to fit your needs.
  5. Run: ubuntu-iso-customization.sh config_example .


Config contains:
  1. LiveCD version.
  2. Directory where the original ISO is.
  3. The build directory (must be mounted with exec and dev options, the mount command does this by default).
  4. List of packages to install.
  5. The UPTODATE key, which tells you whether you need to upgrade all packages to the current versions in the repository.
  6. Time zone


How does it work:
  1. Mounts an image.
  2. Copies filesystem.squashfs and decompresses.
  3. Chroot into unpacked filesystem.squashfs, installs packages, configures proxies and Time Zone.
  4. Packs up what we got in the new filesystem.squashfs.
  5. Collects new iso.


Tested in Ubuntu 10.04 Desktop i386

Comments, suggestions, suggestions?

Source: https://habr.com/ru/post/93095/


All Articles