Skip to content

Instantly share code, notes, and snippets.

@gdamjan
Last active November 6, 2020 20:10
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gdamjan/62ccd8a4878112e35456 to your computer and use it in GitHub Desktop.
Save gdamjan/62ccd8a4878112e35456 to your computer and use it in GitHub Desktop.
Customize ubuntu live image
# first, get the iso from http://releases.ubuntu.com/
# make working dir hierarchy in /tmp (you'll need enough ram for this)
sudo mkdir -p /tmp/custom/{_squash,_work,iso,newiso,newlive,project}
sudo mount -o loop ~/Downloads/ubuntu-18.10-desktop-amd64.iso /tmp/custom/iso
sudo mount -t squashfs /tmp/custom/iso/casper/filesystem.squashfs /tmp/custom/_squash
sudo mount -t overlay overlay -onoatime,lowerdir=/tmp/custom/_squash,upperdir=/tmp/custom/project,workdir=/tmp/custom/_work /tmp/custom/newlive
# customize the live fs with systemd-nspawn (a better chroot)
sudo systemd-nspawn --bind-ro=/run/systemd/resolve/resolv.conf:/etc/resolv.conf --setenv=RUNLEVEL=1 -D /tmp/custom/newlive
apt-get update
apt-get upgrade
apt-get install --no-install-recommends ...
...
apt-get purge ... # make some space by removing thunderbird* libreoffice* rhythmbox* ubuntu-web-launchers
apt-get autoremove --purge
apt-get clean
<ctrl-d>
sudo rm /tmp/custom/newlive/root/.bash_history
sudo rm /tmp/custom/newlive/var/lib/dbus/machine-id
# prepare new image content
sudo rsync -av --exclude casper/filesystem.squashfs /tmp/custom/iso/ /tmp/custom/newiso/
sudo mksquashfs /tmp/custom/newlive /tmp/custom/newiso/casper/filesystem.squashfs -noappend -b 1048576 -comp xz -Xdict-size 100%
printf $(sudo du -s --block-size=1 /tmp/custom/newlive | cut -f1) | sudo tee /tmp/custom/newiso/casper/filesystem.size
# remove leftovers
sudo umount /tmp/custom/_squash /tmp/custom/newlive /tmp/custom/iso
sudo rm -rf /tmp/custom/newiso
# /tmp/custom/project now has the delta of your changes, you could keep it for later reuse
VOLUME_NAME="Ubuntu KIKA"
(cd /tmp/custom/newiso && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" ) | sudo tee /tmp/custom/newiso/md5sum.txt
sudo genisoimage -r -cache-inodes -J -l \
-b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \
-V "$VOLUME_NAME" \
-o /tmp/custom-image.iso /tmp/custom/newiso/
sudo isohybrid /tmp/custom-image.iso
# optionaly update syslinux/isolinux.bin and syslinux/*.c32 with newer from syslinux, might make it more compatible with isohybrid below
sudo dd if=/tmp/custom-image.iso of=/dev/sdb bs=4M status=progress
# make persistent usb
sudo sfdisk /dev/sdb <<EOF
/dev/sdb1 : start= 2048, size= 6291456, type=b, bootable
/dev/sdb2 : start= 6293504, size= 8857664, type=83
EOF
sudo mkfs.vfat -n kika-101 /dev/sdb1
sudo mkfs.ext4 -L casper-rw -O ^has_journal /dev/sdb2
sudo mount /dev/sdb1 /mnt
sudo rsync -av /tmp/custom/newiso/ /mnt
sudo syslinux -d syslinux /dev/sdb1
(cd /tmp/custom/newiso && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" ) | sudo tee /tmp/custom/newiso/md5sum.txt
sudo umount /mnt
sudo dd if=/usr/lib/syslinux/bios/mbr.bin of=/dev/sdb
alias nspawn='sudo systemd-nspawn --bind-ro=/run/systemd/resolve/resolv.conf:/etc/resolv.conf \
-D /tmp/custom/newlive \
--setenv=RUNLEVEL=1 \
--setenv=http_proxy=http://192.168.88.49:3142'
DISTRO=`nspawn lsb_release -sc`
nspawn add-apt-repository "deb http://archive.ubuntu.com/ubuntu $DISTRO universe multiverse"
nspawn add-apt-repository "deb http://security.ubuntu.com/ubuntu $DISTRO-security universe multiverse"
nspawn add-apt-repository "deb http://archive.ubuntu.com/ubuntu $DISTRO-updates universe multiverse"
nspawn apt-get update
nspawn apt-get install --no-install-recommends \
git vim-nox python-pip python3-pip ipython3-notebook ipython-notebook haskell-platform clisp php5-cli firmware-b43-installer
nspawn apt purge 'thunderbird*' 'libreoffice*' rhythmbox* ubuntu-web-launchers
nspawn apt-get autoremove --purge
nspawn apt-get clean
ROOT=/tmp/custom/newlive
sudo rm $ROOT/etc/skel/examples.desktop
sudo sed -i 's/us/us,mk/' $ROOT/etc/default/keyboard
sudo cp kika-wallpaper.png $ROOT/usr/share/backgrounds/warty-final-ubuntu.png
sudo cp KIKA $ROOT/etc/NetworkManager/system-connections/
# lets rename these so it's the same for syslinux and isolinux (usb & cd)
sudo mv /tmp/custom/newiso/isolinux /tmp/custom/newiso/syslinux
sudo mv /tmp/custom/newiso/syslinux/isolinux.cfg /tmp/custom/newiso/syslinux/syslinux.cfg
sudo cp kika-logo-splash.png /tmp/custom/newiso/syslinux/splash.png
sudo sed -i '/^ui / d' /tmp/custom/newiso/syslinux/syslinux.cfg # disable gfxboot
sudo sed -i 's/quiet splash/quiet splash persistent/' /tmp/custom/newiso/syslinux/txt.cfg /tmp/custom/newiso/boot/grub/grub.cfg
qemu-system-x86_64 -enable-kvm -m 2048 -drive file=/tmp/custom-image.iso,media=cdrom,format=raw
qemu-system-x86_64 -enable-kvm -m 2048 -bios OVMF-pure-efi.fd -drive file=/tmp/custom-image.iso,media=disk,format=raw
@gdamjan
Copy link
Author

gdamjan commented Oct 24, 2015

TODO:

  • maybe customize gfxboot instead of disabling it
  • change the wallpaper without overwriting the file
  • customize unity launcher (sidebar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment