42

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.

36

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

cp /mnt/clonezilla/live/filesystem.squashfs /path/to/workdir
cd /path/to/workdir

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

unsquashfs filesystem.squashfs
mv filesystem.squashfs /path/to/backup/

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

cd /path/to/workdir
mksquashfs squashfs-root filesystem.squashfs -b 1024k -comp xz -Xbcj x86 -e boot

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

cp filesystem.squashfs /mnt/clonezilla/live/

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. – Naftuli Kay Jun 23 '13 at 19:25
  • 1
    @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. – don_crissti Jun 23 '13 at 19:53
  • @Naftuli: You seem to have skipped the "mv ... backup/" step. – Joachim Wagner Jun 14 '18 at 7:14
  • Does this work not under (fake)root? Just from extracting I get the error create_inode: could not create character device squashfs-root/dev/audio, because you're not superuser! – Wilf Aug 8 '18 at 9:43
  • @Wilf - you cannot create device files (squashfs-root/dev/*) as regular user, you need root privileges. – don_crissti Aug 8 '18 at 10:26
5

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 ---

mount -t overlay -o lowerdir=/fm,upperdir=/to,workdir=/temp overlay /fin

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

mksquashfs /fin newfile; umount /fin

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

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

  • If you delete a file from the mounted /fin, will it be removed from the final squashfs you create? – localhost Feb 3 '18 at 12:34
1

Here, I found an other answer:

bash# mount dir.sqsh /mnt/dir -t squashfs -o loop
  • 7
    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. – harperville Mar 23 '17 at 16:25
  • I agree that it is not a complete answer. Together with unix.stackexchange.com/a/377269/27328 you can build an answer where you do not need to unpack your file system to modify it - less space, less time. – User Mar 2 at 19:16
  • Simplest method, worked on CentOS 7 – Seff Apr 11 at 6:02
0

Using overlayfs as shown is the best way to have pseudo "squashfs rw" ; It requires however to run on > 4.x kernel (or ubuntu >14.x trusty ).

An alternative solution when one is sitting on older live cd without any overlayfs/aufs/unionfs is to make use of squashfs'own capabilities

important:

 without unsquashfs, so this can be done on low storage system

example:

modify squashfs's "usr" directory

1    mount squashfs_file /mnt

2    cp -a /mnt/usr $HOME  ##modify whatever $HOME/usr as needed

3    mksquashfs /mnt new_squashfs_file -wildcards -e usr

4    mksquashfs $HOME/usr new_squashfs_file -keep-as-directory

5    umount /mnt  # cleanup

line 3 builds temporarily squashfsfile excluding olddir_usr

line 4 appends modified-usr-dir into new_squashfsfile

see here append squashfs Append to sub-directory inside squashfs file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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