Suppose we have filesystem.squashfs, we can append to it by:

mksquashfs somefile filesystem.squashfs

which appends somefile to root of squashfs file. appending directory:

mksquashfs somedir/ filesystem.squashfs

would append files and directories inside somedir/ to the root of squashfs file. and if a directory or file exist in the tree of squashfs then mksquashfs would rename new files, not changing old files and directories. well it make sense the phrase of "append".

I'm aware of unsquashfs which decompress the squashfs, but I'm curious if perhaps there is a way to add a new file or directory to existing sub-directory inside squashfs tree without decompressing?

  • Have you found any solution to this?
    – NiKiZe
    Commented Jul 24, 2017 at 15:56
  • 2
    Unfortunately no, the only solution I know so far is to uncompress the file, do changes and then compress it again. I suppose squashfs is not meant to write changes to its content.
    – 2i3r
    Commented Jul 24, 2017 at 16:49

2 Answers 2


Of course ;it is possible to append directory or file to a squashfs_file.

One has to understand the way mksquashfs works : Roughly speaking it is incrementally adding compression blocks of data in similar way as growisofs writes to dvd ; and at the end update the TOC ,kind of table contents of the image. You cannot "clear" the old directory of course, because incremental writing only cares about future and not the past !!!!

But there is a very simple way of modifying a squashfs file without unsquashfs the whole image ( which could take a lot of space on ram or storage device ... think of dvd_iso 3-5 GB image ! ). The guiding idea works like this :

1 mount squashfs_file /mnt ( mounting is far less using storage than unsquashfs )

2 Re build squashfs_file by excluding the directory to modify then append the new directory we want.

Details ex:

  • cp /mnt/specific_dir $home ##modify $home/specific_dir as needed
  • mksquashfs /mnt new_squashfs_file -wildcards -e specific_dir
  • mksquashfs $home/specific_dir new_squashfs_file -keep-as-directory
  • umount /mnt # cleanup

of course all other options for mksquashfs can be added as ususal (block size;compression scheme ....-b 1048576 -comp xz ....)

The example show one directory modification for clarification purpose ; but on a rootfs you can exclude etc usr ....then append the modified etc usr in 2nd line append mechanism .

This is the way to go if you need to remaster a whole livecd ubuntu on a 4GB ram "windows10 laptop" without any touching on ntfs original partition .

HopeThatHelp, wangji.


When trying something as to remaster a live-CD, the reproducing and excluding of folders can only go so far (in my case, I had to touch /etc, /lib and /usr, which amounts almost to unpacking all).

BUT, using the idea of recompressing without uncompressing, and adding to that the beauty of overlayfs, I came eventually up with the following:


mkdir /tmp/lower /tmp/upper /tmp/work /tmp/joined
mount $SQFS /tmp/lower
mount -t overlay none -olowerdir=/tmp/lower,upperdir=/tmp/upper,workdir=/tmp/work  /tmp/joined
rsync -a $ADD /tmp/joined
mksquashfs /tmp/joined ${SQFS}_new -comp xz -b 1M -noappend
umount /tmp/joined /tmp/lower
rm -rf /tmp/lower /tmp/upper /tmp/work /tmp/joined
mv ${SQFS}_new $SQFS

It still needs to create a new SQFS, but nothing of the old SQFS needs to be unpacked, and the overlay takes care of new files in old directories, etc.

P.S. I had hoped, it would also be faster than uncompressing the SQFS first and recompressing, but that isn't the case. After all, it still needs to read through the entire old SQFS in order to create the new one.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .