Ubuntu – How to get a live-USB to use a partition for persistence

grub2initramfslive-usbpersistence

I want to install Ubuntu to a USB hard drive so that it will run on all systems, that can run the LiveCD and store persistent data on a regular ext4 partition rather than a casper-rw file. In every other way it should behave like a regular Ubuntu installation.

The problem

With Startup Disk Creator one is able to put the LiveCD image on a USB-device. Changes can be made persistent but are stored in a file that is limited to a few GB in size. Said persistent file (additionally to being size restricted) has the problem that it isn't readable like data on a normal partition.*

My question

So how do I get the LiveCD on a USB disk in such a way that the changes are stored in a normal partition rather than a persistence file? Also the persistent changes shouldn't be restricted to a few GB in size but use whole partition of many 100 GB if need be.

I suspect there is a tutorial out there for this, but my google-fu is just not good enough to find it.

tl;dr:

Sytem should run on all hardware configurations, have full functionality of the LiveCD and be stored on a regular ext4 partiton without using ramdisks and casper-rw. FU casper-rw.


*I know one could mount the casper-rw file from another OS and get to the data this way but that's a hassle.

Best Answer

This is very easy to do, although the "casper-rw" name will still show up once :)

  1. Your target USB disk must have at least two partitions; I recommend using GParted to create a new partition table.

    • The first partition must be vfat/FAT32, and minimum size 750 MB (or more if you are using a live DVD image).
    • The second partition should be ext4, sized to whatever you want your persistent storage to be (no limits), but it must be labeled casper-rw (all lower case, no quotes)

    Enter image description here

    • You can, of course, add third, fourth, extended/logical partitions, etc. if you would like to.

    Note: I prefer to use UNetbootin because it makes editing the syslinux configuration easy. You can use your own USB creator, but you should then modify the below steps appropriately. Also note that GParted 0.18.0 seems to have problems partitioning the USB stick. So if you have the issue then use live GParted CD for partitioning.

  2. Use UNetbootin to write your chosen live CD ISO to the first (vfat) USB partition.

    • Put a tiny size for UNetbootin's persistence option (say, 10 MB) to make life easier; don't worry, we won't actually be using this casper-rw file.

    Enter image description here

  3. Once everything is done, the final step is to delete the small casper-rw file created on the vfat partition you installed the live CD on, so that the large ext4 casper-rw partition is used instead. Mount this partition (here, sdb1), and delete /casper-rw.

  4. Persistence (via the persistent kernel option) should already be set up if you used UNetbootin, so safely eject the USB and you're ready to go!

PS: If you don't want to use UNetbootin and you are using the "Startup disk creator" in Ubuntu then you need to do some edits to your syslinux/txt.cfg file as follows:

default live
label live
  menu label ^Try Ubuntu without installing
  kernel /casper/vmlinuz.efi
  append  file=/cdrom/preseed/ubuntu.seed boot=casper cdrom-detect/try-usb=true persistent noprompt floppy.allowed_drive_mask=0 ignore_uuid initrd=/casper/initrd.lz quiet splash --
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz.efi
  append  file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity cdrom-detect/try-usb=true persistent noprompt floppy.allowed_drive_mask=0 ignore_uuid initrd=/casper/initrd.lz quiet splash --
label check
  menu label ^Check disc for defects
  kernel /casper/vmlinuz.efi
  append  boot=casper integrity-check cdrom-detect/try-usb=true persistent noprompt floppy.allowed_drive_mask=0 ignore_uuid initrd=/casper/initrd.lz quiet splash --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80