Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to create a fresh ISO image for use on a USB stick. I've partitioned my USB stick into 2 partitions, one vfat and one ext4. The vfat partition has the ISO and GRUB2 installed to it, such that GRUB2 boots the ISO.

The ext4 partition has the volume label casper-rw and is used as the persistent data store for the Live USB. I've modified the grub.cfg such that I get two options at boot, one to boot the ISO in persistent mode and one to boot normally.

However, when booting in "normal" mode, the casper-rw partition is mounted as a normal drive and changes made in persistent mode don't stay.

What I would like is the casper-rw partition to be mounted overlaid on the / filesystem, but when I ask Ubuntu to boot normally (i.e., without the persistent option in GRUB2), I'd like that partition to be mounted read-only so that changes made in the persistent mode persist.

What is the best way to achieve this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

What i did is I modify casper script inside initrd.lz.

The script will mount casper-rw as read-only and then on overlay it on top of /. It will then mount tmpfs on top of the overlay.

I use mint btw, not sure about ubuntu, hope it works for you.

Here are more details:

  1. Extract initrd using instruction from here.
  2. Edit scripts/casper, modify the setup_unionfs() function. You find the modified function here.

    ...
    p_ro_mount=""
    if [ -n "${PERSISTENT}" ]; then
          cowprobe=$(find_cow_device "${root_persistence}")
          if [ -b "${cowprobe}" ]; then
                p_ro_device=${cowprobe}
                p_ro_fstype=$(get_fstype "${cowprobe}")
                p_ro_mountopt="ro,noatime"
                p_ro_mount="/persistent"
                mkdir -p $p_ro_mount
                mount -t ${p_ro_fstype} -o ${p_ro_mountopt} \   
                  ${p_ro_device} \
                  ${p_ro_mount} || panic "Can not mount"
    ...
    case ${UNIONFS} in
    ...
       overlayfs)
           mounts=""
           for mount in /cow $p_ro_mount $rofslist
    ...
    
  3. Replace initrd.lz, or in my case, I just created a new one.

    find . | cpio --quiet -o -H newc | lzma -7 > ../ro-initrd.lz
    
  4. Add more boot option to syslinux.cfg

    append initrd=/casper/ro-initrd.lz file=/cdrom/preseed/linuxmint.seed boot=casper  splash -- persistent
    

Note: I use Mint 16 (x86) and unetbootin.

share|improve this answer
    
Could you add some more details about how you achieved this? Even a copy of the script would be fine. –  Chinmay Kanchi Jan 23 at 20:54
    
I add more detail –  David Lim Jan 24 at 3:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.