Mounting-Editing a squashfs filesystem in read-write

I have a Clonezilla installation on a USB stick and I’d like to make some modifications to the operating system. Specifically, I’d like to insert a runnable script into /usr/sbin to make it easy to run my own backup command to make backups less painful.

The main filesystem lives under /live/filesystem.squashfs on the USB FAT-32 partition.

How can I mount this read/write on my Linux machine in order to be able to add/remove/change files? I’m running an Ubuntu 12.04 derivative.

3 Answers

As root, copy filesystem.squashfs to some empty dir, e.g.:

Unpack the file then move it somewhere else (so you still have it as a backup):

Go in squashfs-root, add/modify as per your taste then recreate filesystem.squashfs:

copy the newly created filesystem.squashfs over the existing one on your USB drive, e.g.:

then reboot and use your LIVE USB.

Note: the above commands are part of squashfs-tools.

This works great, but unfortunately, I get a message for all the root directories telling me:

Source directory entry bin already used! – trying bin_1.

Sure enough, in my output filesystem, I have a /bin and a /bin_1, rather than merging the folder. Any ideas? If I run with -noappend, the filesystem simply doesn’t work.

@TKKocheran – I’m not getting any of those errors here after adding a custom script in /usr/bin and repacking with mksquashfs. USB drive boots fine and I can use my script from the live session. Make sure you no longer have the old filesystem.squashfs in the same directory with your modified squashfs-root before running mksquashfs.

Here, I found an other answer:

The above command will mount it read-only, which is better than not mounting it at all; alas, not a complete answer to the question at hand.

If your system supports some uion-filesystem, such as aufs or overlayfs, you don’t have to extract your original squashfs file.

For example the overlayfs is used( a kernel option to enable it): You can mount your squashfs.file to /fm or somewhere else first. Prepare a writable filesystem with 2 directories in it, say /to and/temp. prepare another writable directory /fin for the merged results. Mount them together as an overlayfs to your system —

Now you can add/modify files in /fin. Once everything done, you can mksquashfs /fin to a new squashfs file,

…..then clear/unmount all the other used directories as you will.

The squashfs and some unionfs are commonly used for a live-cd.

Linux - General

Leave a Reply

Your email address will not be published. Required fields are marked *