howtos:building_a_custom_liveusb
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | howtos:building_a_custom_liveusb [02/12/2018 21:34] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Download Ubuntu Hardy Heron iso (or whatever version you want). | ||
+ | Download {{: | ||
+ | |||
+ | |||
+ | Format your usb pen with fat32. | ||
+ | |||
+ | Make LiveUSB with unetbootin (just unpack unetbootin-linux-216.zip and execute unetbootin as root) or use the usb-builder tool within Ubuntu. | ||
+ | |||
+ | ===== Version 1 ===== | ||
+ | |||
+ | < | ||
+ | sudo mount -o loop -t squashfs / | ||
+ | sudo mkdir / | ||
+ | sudo cp -aR / | ||
+ | sudo mount -t proc none / | ||
+ | sudo mount -o bind /dev / | ||
+ | sudo chroot / | ||
+ | </ | ||
+ | |||
+ | Inside chroot edit / | ||
+ | |||
+ | To choose a different keyboard layout: | ||
+ | < | ||
+ | apt-get install console-data | ||
+ | dpkg-reconfigure console-data | ||
+ | </ | ||
+ | |||
+ | |||
+ | Make you apt-get install' | ||
+ | |||
+ | Start rebuilding the LiveUSB: | ||
+ | < | ||
+ | cd /tmp | ||
+ | sudo umount / | ||
+ | sudo mksquashfs ubuntu_usb_image ubuntu_usb.squashfs -no-sparse | ||
+ | sudo cp ubuntu_usb.squashfs / | ||
+ | </ | ||
+ | |||
+ | ===== Version 2 ===== | ||
+ | This is more or less copied from https:// | ||
+ | |||
+ | I also found it necessary to give tmpfs an upper size of 2GB, otherwise it ran out of space during updates. | ||
+ | |||
+ | ===== The manual way ===== | ||
+ | |||
+ | * Preparation: | ||
+ | < | ||
+ | mkdir / | ||
+ | mkdir /tmp/tmpfs | ||
+ | mkdir / | ||
+ | </ | ||
+ | |||
+ | * Mount the filesystems: | ||
+ | < | ||
+ | sudo modprobe unionfs | ||
+ | sudo mount -o loop -t squashfs <mount point for usb>/ | ||
+ | sudo mount -o size=2G -t tmpfs tmpfs /tmp/tmpfs | ||
+ | sudo mount -t unionfs -o dirs=/ | ||
+ | </ | ||
+ | |||
+ | * Make sure essential filesystems are mounted inside the image: | ||
+ | < | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | </ | ||
+ | |||
+ | Make sure packagelists are up to date and install the software you like: | ||
+ | |||
+ | < | ||
+ | LANG=C sudo chroot / | ||
+ | LANG=C sudo chroot / | ||
+ | </ | ||
+ | |||
+ | * Clean up: | ||
+ | < | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | sudo chroot / | ||
+ | </ | ||
+ | |||
+ | * Build a new squashfs with your changes: | ||
+ | < | ||
+ | sudo mksquashfs / | ||
+ | </ | ||
+ | |||
+ | * Clean up the temporary mountpoints: | ||
+ | < | ||
+ | sudo umount / | ||
+ | sudo umount /tmp/tmpfs | ||
+ | sudo umount / | ||
+ | </ | ||
+ | |||
+ | * Copy the new squashfs in place: | ||
+ | < | ||
+ | sudo cp / | ||
+ | </ | ||
+ | |||
+ | * Clean up the rest: | ||
+ | < | ||
+ | sudo rm -rf /tmp/tmpfs / | ||
+ | </ | ||
+ | |||
+ | Have fun with your changed imagefile .... | ||
+ | |||
+ | ===== The same as shellscript ===== | ||
+ | |||
+ | The script below uses the same setup as above and spawns a rootshell inside the squashfs, you can then run " | ||
+ | |||
+ | < | ||
+ | #!/bin/sh | ||
+ | |||
+ | if [ -z $1 ];then | ||
+ | echo 'I need a path to the usb mount point as first argument' | ||
+ | exit 0 | ||
+ | fi | ||
+ | |||
+ | SQUASHFS=/ | ||
+ | TMPFS=/ | ||
+ | MERGEMOUNT=/ | ||
+ | SQUASHFSFILE=/ | ||
+ | |||
+ | mkdir $SQUASHFSFILE | ||
+ | mkdir $SQUASHFS | ||
+ | mkdir $TMPFS | ||
+ | mkdir $MERGEMOUNT | ||
+ | |||
+ | sudo modprobe unionfs | ||
+ | |||
+ | sudo mount -o loop -t squashfs $1/ | ||
+ | sudo mount -o size=3G -t tmpfs tmpfs $TMPFS | ||
+ | sudo mount -t unionfs -o dirs=$TMPFS: | ||
+ | |||
+ | sudo chroot $MERGEMOUNT mount -t proc proc /proc | ||
+ | sudo chroot $MERGEMOUNT mount -t sysfs sysfs /sys | ||
+ | sudo chroot $MERGEMOUNT mkdir -p /dev/pts | ||
+ | sudo chroot $MERGEMOUNT mount -t devpts devpts -o noexec, | ||
+ | |||
+ | sudo cp / | ||
+ | |||
+ | LANG=C sudo chroot $MERGEMOUNT | ||
+ | |||
+ | sudo chroot $MERGEMOUNT rm / | ||
+ | sudo chroot $MERGEMOUNT umount /proc | ||
+ | sudo chroot $MERGEMOUNT umount /sys | ||
+ | sudo chroot $MERGEMOUNT umount /dev/pts | ||
+ | sudo chroot $MERGEMOUNT rm -rf /dev/pts | ||
+ | |||
+ | echo -n 'do you want to build a squashfs with the changes ? (y/n) ' | ||
+ | read yesno | ||
+ | if [ -z $yesno ];then | ||
+ | yesno=' | ||
+ | fi | ||
+ | |||
+ | if [ $yesno = ' | ||
+ | sudo mksquashfs $MERGEMOUNT $SQUASHFSFILE/ | ||
+ | fi | ||
+ | |||
+ | sudo umount -t unionfs $MERGEMOUNT | ||
+ | sudo umount -t tmpfs $TMPFS | ||
+ | sudo umount -t squashfs $SQUASHFS | ||
+ | |||
+ | if [ $yesno = ' | ||
+ | sudo cp $SQUASHFSFILE/ | ||
+ | fi | ||
+ | |||
+ | echo -n 'do you want to cleanup in /tmp ? (y/n) ' | ||
+ | read yesno | ||
+ | if [ -z $yesno ];then | ||
+ | yesno=' | ||
+ | fi | ||
+ | |||
+ | if [ $yesno = ' | ||
+ | sudo rm -rf $TMPFS $SQUASHFS $MERGEMOUNT $SQUASHFSFILE/ | ||
+ | fi | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Important Notes ===== | ||
+ | For unknown reasons the three mounted filesystems (tmpfs, squashfs and proc) are always lock by something, thus the cleanup phase will not work. I can only get it of by rebooting the computer (fairly annoying!). Because of the locks I was forced to include an exclude statement not digging into /proc. |
howtos/building_a_custom_liveusb.txt · Last modified: 02/12/2018 21:34 by 127.0.0.1