Ubuntu – How to create a live system on usb-drive with persistent changes on disk/hdd

boothard drivelive-usbusb

I was trying to install Ubuntu live on a USB-drive with persistent changes. However i wanted to write the changes to HDD instead of USB for various reasons (Performance, Space).

I found out, that the changes are handled within a file with a ext3 file-system that is mounted by the system (casper-rw).
But it seem to be auto-detected on flash-drive on startup.

How can i create a new casper-rw file on HDD and reroute the Ubuntu live system on the USB-drive to HDD?

edit 2015-07-14:

Thank you for the answers so far. They are very interesting and help a lot to understand the mechanics of the "live system persistent save feature" better, and show good approaches to solve the problem.
Unfortunately i was trying to overcome some limitations that i had in mind when asking the question regarding access to the host system and/or access to new hardware i did not clearly state (sorry for that).

If partitioning is an option, i think the answer stated here is very good, since it only requires you to create a new partition, label it casper-rw and you're done (work's great, i tested it).

If buying new hardware is an option, usb3.0 Flash-Drive (MLC or SLC), portable HDDs, eSATA and other options come to mind that have a far better performance than an average USB2.0 flash-drive.

So i was wondering if there is a way to just create a casper-rw file instead of a partition on a disk with limited access to (or copy/link the one on the flash-drive).

This way it would be easy to just copy the casper-rw file back to the flash-drive and use it from there again or move it to an other computer, granting great flexibility, minimal changes to the HDD and easy removal of changes done to the system.

Best Answer

You can easily put the writable filesystem (in the casper-rw file) for a live media onto a hard disk. The limitation is that the casper-rw file must go on a FAT partition. Newer machines (UEFI) all have a FAT EFI partition, but that's typically too small to hold a 1G-4G casper-rw file. On another big enough FAT partition, you can make directories, each holding a casper-rw file for possibly different live medias. Suppose sda11 is 10G and has a 10G FAT filesystem, mounted at /mnt/sda11,on which there are directories /A , /B , /C , /D , and /E. Assume we will use /A for our persistent media, putting a casper-rw there.

cd /mnt/sda11/A
dd if=/dev/zero of=casper-rw bs=1M  count=4096
mkfs.ext4 -F -O^has_journal -L casper-rw casper-rw

Take your live media created with persistence, and edit the /boot/grub/grub.cfg file and the /syslinux/txt.cfg file, adding after the word "persistent"

"persistent-path=/A"

/boot/grub/grub.cfg ...

menuentry "Try Ubuntu without installing" {
    set gfxpayload=keep
    linux   /casper/vmlinuz.efi  file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --- cdrom-detect/try-usb=true noprompt persistent persistent-path=/A
    initrd  /casper/initrd.lz
}

/syslinux/txt.cfg

default live
label live
menu label ^Try Ubuntu without installing
kernel /casper/vmlinuz.efi
append noprompt cdrom-detect/try-usb=true persistent persistent-path=/A file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash ---
label live-install
...

That's it. You don't even need to rename/remove the casper-rw file on the USB media.


If there's room on the USB media, you can even copy the hard disk's casper-rw back to the USB, and take your changes with you.


The persistent-path does not allow any explicit disk reference, so should be unique across all FAT partitions. Tested with 1 or 2 FAT partitions (one being the EFI partition). Will not work on an ext2 or ntfs filesystem instead of FAT. If you also add the "toram" word on the same line as "persistent", your compressed filesystem on the slow USB will be copied into ram and give much better performance, however, there seems to be a shutdown issue, with the FAT partition not being cleanly unmounted (which does not seem to cause any problems but...)