Skip to content

Instantly share code, notes, and snippets.

@kalxas
Forked from gdamjan/README
Created July 23, 2016 00:15
Show Gist options
  • Save kalxas/bb6b51c2cccd30e93228ecc80d90a9fb to your computer and use it in GitHub Desktop.
Save kalxas/bb6b51c2cccd30e93228ecc80d90a9fb to your computer and use it in GitHub Desktop.
Customize ubuntu live image
# get the iso first
sudo mkdir -p /tmp/custom/{_fs,_work,iso,newiso,newlive,project}
sudo mount -o loop ~/Downloads/ubuntu-15.04-desktop-amd64.iso /tmp/custom/iso
sudo mount -t squashfs /tmp/custom/iso/casper/filesystem.squashfs /tmp/custom/_fs
sudo mount -t overlay overlay -olowerdir=/tmp/custom/_fs,upperdir=/tmp/custom/project,workdir=/tmp/custom/_work /tmp/custom/newlive
# customize the live fs (a better chroot)
sudo systemd-nspawn --bind-ro=/etc/resolv.conf:/run/resolvconf/resolv.conf --setenv=RUNLEVEL=1 -D /tmp/custom/newlive
apt-get update
apt-get upgrade
apt-get install --no-install-recommends ...
...
apt-get purge ...
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
printf $(sudo du -s --block-size=1 /tmp/custom/newlive | cut -f1) | sudo tee /tmp/custom/newiso/casper/filesystem.size
(cd /tmp/custom/newiso && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" ) | sudo tee /tmp/custom/newiso/md5sum.txt
# remove leftovers
sudo umount /tmp/custom/iso /tmp/custom/_fs /tmp/custom/newlive
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"
sudo genisoimage -r -cache-inodes -J -l \
-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \
-V "$VOLUME_NAME" \
-o /tmp/new-image.iso /tmp/custom/newiso/
sudo isohybrid /tmp/new-image.iso
# optionaly update isolinux/isolinux.bin and isolinux/*.c32 with newer from syslinux, might make it more compatible with isohybrid below
sudo dd if=/tmp/new-image.iso of=/dev/sdb bs=4M status=progress
sudo sed -i '/^ui / d' /tmp/custom/newiso/isolinux/isolinux.cfg # disable gfxboot
sudo sed -i 's/quiet splash/quiet splash persistent/' /tmp/custom/newiso/isolinux/txt.cfg /tmp/custom/newiso/boot/grub/grub.cfg
# make persistent usb
# sudo fdisk /dev/sdb # n <enter> <enter> <enter> <enter> w
sudo mkfs.vfat /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 mv /tmp/custom/newiso/isolinux /tmp/custom/newiso/syslinux
sudo mv /tmp/custom/newiso/syslinux/isolinux.cfg /tmp/custom/newiso/syslinux/syslinux.cfg
sudo syslinux -d syslinux /dev/sdb1
sudo umount /mnt
sudo dd if=/usr/lib/syslinux/bios/mbr.bin of=/dev/sdb
sudo cp ubuntu-all.list /tmp/custom/newlive/etc/apt/sources.list.d/ubuntu-all.list
sudo rm /tmp/custom/newlive/etc/skel/examples.desktop
sudo systemd-nspawn --bind-ro=/etc/resolv.conf:/run/resolvconf/resolv.conf --setenv=RUNLEVEL=1 -D /tmp/custom/newlive \
apt-get update
sudo systemd-nspawn --bind-ro=/etc/resolv.conf:/run/resolvconf/resolv.conf --setenv=RUNLEVEL=1 -D /tmp/custom/newlive \
apt-get install --no-install-recommends \
git vim-nox python-pip python3-pip ipython3-notebook ipython-notebook haskell-platform clisp firmware-b43-installer
sudo systemd-nspawn --bind-ro=/etc/resolv.conf:/run/resolvconf/resolv.conf --setenv=RUNLEVEL=1 -D /tmp/custom/newlive \
apt-get clean
sudo sed -i 's/us/us,mk/' /tmp/custom/newlive/etc/default/keyboard
sudo sed -i 's/^XKBOPTIONS=.*/XKBOPTIONS="grp:alt_shift_toggle"/' /tmp/custom/newlive/etc/default/keyboard
qemu-system-x86_64 -enable-kvm -m 2048 -drive file=/tmp/new-image.iso,media=cdrom,format=raw
qemu-system-x86_64 -enable-kvm -m 2048 -bios OVMF-pure-efi.fd -drive file=/tmp/new-image.iso,media=disk,format=raw
deb http://archive.ubuntu.com/ubuntu/ vivid multiverse universe
deb http://security.ubuntu.com/ubuntu/ vivid-security multiverse universe
deb http://archive.ubuntu.com/ubuntu/ vivid-updates multiverse universe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment