Install (K)ubuntu on a USB stick

Requirements

Note: This guide is based on my own trials and the following articles, which did not work for me but were a tremendous help:

Setup (K)ubuntu

  1. If you do not plan to use a Windows XP partition on the same stick, then you need to replace all future references to partition 2 with partition 1, partition 3 with partition 2, etc. This guide will assume you setup partition 1 with Windows XP. Note that XP only recognizes partition 1 to be a valid USB stick partition.
  2. If you are not running (K)ubuntu Edgy 6.10 reboot your computer into Ubuntu from the Live CD
  3. Insert your USB flash drive
  4. Open a terminal window and type sudo -s
  5. Type fdisk -l to list available drives/partitions. Note which device is your flash drive (In my case: /dev/sdb). Throughout this tutorial, replace b with your flash drive letter. For example, if your flash drive is sdf, replace b with f.
  6. type umount /dev/sdb1
  7. repeat for other partitions if you stick contains more than one partition
  8. type fdisk /dev/sdb
  9. type p to show the existing partition and d to delete it
  10. if your stick contains more than one partition: enter partition number to confirm delete, then repeat until all partitions are deleted
  11. type n to make a new partition
  12. type p for primary partition
  13. hit enter to use the default 1st cylinder
  14. type +sizeM to set the partition size to size MB. For a 16GB stick, a reasonable size would be 12GB, e.g. type +12000M. verify with p that the partition is allocated with the correct size.
  15. type t to change the partition filesystem
  16. type 7 to select the NTFS file system
  17. type n to make a new partition. This will be the “live” partition which will not be modified during usage and needs to have a FAT file system.
  18. type p for primary partition
  19. type 2 to make this the second partition
  20. hit enter to use the default cylinder
  21. type +700M to set the partition size
  22. type a to make this partition active
  23. type 2 to select partition 2
  24. type t to change the partition filesystem
  25. type 2 to select partition 2
  26. type 6 to select the FAT16 file system
  27. type n to make another new partition
  28. type p for primary partition
  29. type 3 to make this the third partition
  30. hit enter to use the default cylinder
  31. hit enter again to use the default last cylinder
  32. type w to write the new partition table and quit fdisk
  33. Type umount /dev/sdb2 to ensure the 2nd partition is unmounted
  34. Type mkfs.vfat -F 16 -n edgy /dev/sdb2 to format the 2nd partition which is the Ubuntu live partition the boot loader will boot into (note: you may choose any name to replace edgy)
  35. Type umount /dev/sdb3 to ensure the 3rd partition is unmounted
  36. Type mkfs.ext2 -b 4096 -L casper-rw /dev/sdb3 to format the 3rd partition which is the extension partition where all your later changes to the base system will be safed (note: the partition label casper-rw must be entered with the exact spelling and in lower case. This partition will be invisible once you run (K)ubuntu from the stick)
  37. formatting the Windows XP partition must be done from a running XP system (see next paragraph)
  38. Remove and Re-insert your flash drive
  39. Type apt-get install syslinux mtools (to obtain the boot manager)
  40. Type syslinux -sf /dev/sdb2
  41. Download this custom usyslinux.tar file and extract the syslinux.cfg file to /media/edgy (the root directory of /dev/sdb2)
  42. Type cd /media/cdrom0 (running installed Edgy) or cd /cdrom (running the Edgy LiveCD)
  43. Type cp -rf casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines kubuntu.ico casper/vmlinuz casper/initrd.gz install/mt86plus /media/edgy/
  44. If you are installing Ubuntu from a running Ubuntu Edgy, replace kubuntu.ico with ubuntu.ico. Note that there are 2 error messages when the copy finishes, indicating that 2 sym links could not be copied. Just ignore the message, these sym links are not necessary to be copied.
  45. Type apt-get install lilo. You can later uninstall lilo after having installed the MBR to the stick.
  46. Type lilo -M /dev/sdb to install a bootable MBR
  47. Reboot your computer and set your system BIOS to allow booting from USB devices. Also set the boot priority if necessary. Leave the stick in the USB port to boot from the stick.

If everything has gone as it should, you should now be able to boot Ubuntu from the USB flash device and it should save your changes, restoring them on boot.

Setup Windows XP

  1. When the USB stick is inserted in your computer, start the Device Manager in the Control Panel and find the USB drive
  2. Select tab Policies in Properties and select “Optimize for performance”. This is necessary to allow the partition to be formatted with the NTFS file system.
  3. Go to My Computer, right-click the drive icon of your USB stick, select Format and format the stick with NTFS file system (if the partition is smaller than 4GB you can also choose FAT32 as file system, but NTFS is recommended unless you need to access the stick from Windows 95/98/ME)
  4. Install TrueCrypt 4.3a or a later version to your computer (you find the latest version at http://www.truecrypt.org)
  5. Copy the files TrueCrypt.exe and truecrypt.sys from the installed directory (usually C:\Program Files\TrueCrypt) to the directory \TrueCrypt on your stick
  6. Download the custom autorun.zip and extract to the root of the USB stick. Change the content if you choose different file names from the proposed installation.
  7. Start TrueCrypt on your computer and create your truecrypt container on the USB stick. Name the container “usb-xp.tc” to match the settings in the autorun.inf file.

Note: this setup only allows to open the truecrypt container on the stick. If you need the full functionality of truecrypt when working on a different client machine where truecrypt is not installed, then you need to copy all the files from the installed directory. When opening the container on a different client machine, nothing will be installed to that client, but you need to have administrator privileges to be able to open the container.