4

To chroot into 'normal' installation requires just mount of common /, /proc, /sys and /dev to do normal administration tasks.

But how to proceed with so called 'persistent' installation (see here)? How to simulate 'persistent' parameter on boot process (how does the system handle this issue)?

This question is perhaps related to How do I recover my username and password on a persistent LiveUSB?

(I do not have a specific problem to solve, I am just interested in.)

1 Answer 1

6

The persistant usb drive uses a compressed read-only filesystem (squashfs) and overlays a writable filesystem layer on top that stores changed files. The writable filesystem is stored in a single file (like a zip file, but without the compression - it is actually ext3, but that is unimportant)

To put everything 'back together':

  1. Create the locations where things will go.
  2. Make the filesystems look like whole filesystems and not files (like they do at the moment.
  3. Join the filesystems together.
  4. Play around with the filesystem, like like chrooting
  5. Clean-up

I am assuming the usb drive is mounted on

 /media/usb/

Change this to the directory that contains your persistant installation when you follow these instructions.

You need to be root, or prepend sudo to every command

1. Creating stuff

Some directories need to be created:

  • /media/rootfs - Location where we will put the read-only filesystem
  • /media/cow - The location of the writable overlay
  • /media/persist_usb - The location where the two filesystems will be joined

    this can be done with

    mkdir /media/{rootfs,cow,persist_usb}

2. Make files look like filesystems

First the compressed filesystem

mount -t squashfs -o loop,ro /media/usb/casper/filesystem.squashfs /media/rootfs

(Description: Mount the filesystem.squashfs file on /media/rootfs using squashfs)

Next the writable filesystem

mount -o loop,rw /media/usb/casper-rw /media/cow

(Description: Mount the file casper-rw' on '/media/cow using a loop device)

3. Join the filesystems together

Now we are ready to join the two directories together

mount -t aufs -o dirs=/media/cow=rw:/media/rootfs=ro unionfs /media/persist_usb

(Description: Mount the union of the two directories using aufs (see unionfs) onto /media/persist_usb with /media/cow as writable and /media/rootfs as readonly)

4. Play around

I'll leave that step up to you.

5. Cleanup

Once you have finished having fun with the installation (like chrooting) you need to get rid of the stuff that was created.

First to undo step 3:

 umount /media/persist_usb

Next to undo step 2. We can do both filesystem together:

 umount /media/{rootfs,cow}

(Description: unmount /media/rootfs and /media/cow)

Finally, to undo step 1:

 rmdir /media/{rootfs,cow,persist_usb}

The changes you have made to the filesystem have been kept and you can now unmount the USB drive (if you want to).

1
  • Wow, very nice ! After installation of aufs-tools it is working like a charm. This week I will add your approach to German ubuntu wiki :) .
    – Lasall
    Nov 13, 2011 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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