How to Use Casper-rw File for Persistence on Live USB

filesystemslive-usbpersistenceUbuntu

I have my USB stick setup using Easy2Boot. It allows me to drop ISO files onto the USB drive and boot from there no config or tweaking needed.

I have been doing research on making it persistent. I have found that you can use a file or a partition called casper-rw.

It has info on how to use the file, but my question is. Can you have the casper-rw file directly in the root of the bootable ISO or does it need to go into a special folder on the ISO? For that matter can I even have the file in the ISO or do I need to have it directly on the USB drive?

Best Answer

ISO files cannot be mounted and then written to. ISO 9660 is a read-only file system.

So you'd need to situate a casper-rw file (it's a single file with a filesystem within too) in a location that's physically on the USB drive.

Making a writable filesystem

The Pendrive Linux website shows some details on how to go about creating a casper-rw filesystem. The article is titled: Create a larger casper-rw loop file in Linux. NOTE: A casper-rw filesystem is just a regular filesystem that's been tucked inside a single file. In that example they're using a EXT3 filesystem within it.

Example

  1. Make the "casper-rw" image

    $ dd if=/dev/zero of=casper-rw bs=1M count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 10.958 s, 98.0 MB/s
    
    $ ls -l casper-rw 
    -rw-rw-r--. 1 saml saml 1073741824 Apr  2 19:56 casper-rw
    
  2. Format it as EXT3

    $ mkfs.ext3 -F casper-rw
    mke2fs 1.42.7 (21-Jan-2013)
    Discarding device blocks: done                            
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    65536 inodes, 262144 blocks
    13107 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=268435456
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done
    
  3. Mount it

    $ sudo mount -o loop casper-rw /mnt/
    
  4. Check it out

    $ ls /mnt/
    lost+found
    
    $ df -h /mnt/
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/loop0      976M  1.3M  924M   1% /mnt
    
Related Question