How to make a USB flash drive function as a Ubuntu (or Kubuntu, Xubuntu, Edubuntu) Live CD. The base file system is ext3, it boots using extlinux and supports the same hardware as the Live CD. Instructions on how to update the Live CD and modify it's contents are also given. For the entire document /dev/sda is the USB device.
Booting from a USB device is ofter faster than from CD and USB drives are easier to carry. You should know why you want and or need this. We used Kubuntu 7.04 Feisty Fawn as our image for booting and a Gentoo system for building on.
Making the LiveUSB
Download a copy of the latest Ubuntu ISO, at this time Feisty, store that ISO some place. Ensure that you have squashfs-tools, initrd-tools and syslinux packages installed. We will re-partition and format the USB device, copy the LiveCD contents over and tune it up with extlinux.
Re-partition and format the USB drive. Ensure that the first partition is at least 1GiB in size and marked bootable. Any remaining space can be divided as necessary. When formatting choose ext2, do not put a journaling filesystem onto the USB device.
cfdisk /dev/sda mkfs.ext2 /dev/sda1 mkfs.ext2 /dev/sda2
Mount up the fresh partition and the ISO image.
mkdir /mnt/usb_disc mount /dev/sda1 /mnt/usb_disc mkdir /mnt/live_cd mount -o loop /tmp/kubuntu-7.04-desktop-i386.iso /mnt/live_cd cd /mnt/live_cd/ cp -aR casper disctree dists install pool preseed .disk /mnt/usb_disc
There is no need to copy the isolinux informations as extlinux will be used.
cd / mkdir /mnt/usb_disc/extlinux extlinux -i /mnt/usb_disc/extlinux
Now edit the config file /mnt/usb_disc/extlinux/extlinux.conf to read something like this.
DEFAULT /casper/vmlinuz APPEND file=preseed/kubuntu.seed boot=casper initrd=/casper/initrd.gz ramdisk_size=1048576 root=/dev/ram0 rw quiet splash --
Modifying or Updating the Image
The filesystem is stored in the squashfs image and is therefore not open for direct update. Below we will mount the image, copy the contents out, chroot into that environment and perform necessary actions.
mount -o loop -t squashfs /mnt/usb_disc/casper/filesystem.squashfs /mnt/ubuntu_usb mkdir /tmp/ubuntu_usb_image cp -aR /mnt/ubuntu_usb/* /tmp/ubuntu_usb_image/ mount -t proc none /tmp/ubuntu_usb_image/proc mount -o bind /dev /tmp/ubuntu_usb_image/dev chroot /tmp/ubuntu_usb_image /bin/bash
Now that we are in the new environment it can be modified in almost any possible way.
apt-get install aircrack-ng firefox kismet exit
Once finished then re-package the directory into a squashfs image.
cd /tmp mksquashfs ubuntu_usb_image ubuntu_usb.squashfs cp ubuntu_usb.squashfs /mnt/usb_disc/casper/filesystem.squashfs
Now it's ready to boot!
- 2007-05-05 - Created /djb