10

Obviously, I don't want to actually modify a squashfs. What I would like to do though is take an existing squashfs, a set of files and create a new squashfs which is identical to the old one except that the files in the set either replace similar files in the squasfs or are just added if there is no similar files.

OK, that last part sounded weird. So let me give an example:

There is a squashfs called mfs.squash. Inside it there is a file ./a/foo. I want to create a new squashfs which is identical to the old squashfs – except that there is a new file a/b and I overwrite the ./a/foo with one of my specification.

3 Answers 3

11

Mount the squashfs:

mkdir /mnt/squishy
mount mfs.sqash /mnt/squishy -t squashfs -o loop

Copy the squashfs to another place:

mkdir /tmp/squooshtacular
find /mnt/squishy -xdev -print0 | cpio -pa0V /tmp/squooshtacular

Copy the new files into place:

cp ./a.foo /tmp/squooshtacular/a.foo

Make the new squashfs:

mksquashfs /tmp/squooshtacular mfs_with_bbq_sauce.squash
3
  • 3
    I think this should read: find /mnt/squishy -xdev -print0 | cpio -pd0V /tmp/squooshtacular
    – fpmurphy
    Jun 30, 2011 at 22:15
  • @fpmurphy Why? -d isn't necessary since find is producing all the directory names, and there's no reason to remove -a. Jun 30, 2011 at 23:46
  • 4
    Did not work for me without the -d option
    – fpmurphy
    Jul 1, 2011 at 2:42
3

you can append new_or_modified files_dir on a squashfs_file without unsquash nor cpio mounted_squashfs as above. See the detailed response at:

Append to sub-directory inside squashfs file

0

Unpacking a squashfs to a r/w filesystem, making changes, and then repacking works well for small volumes. Alternately, you can use mksquashfs to add stuff to the top level directory ("append") and it's super fast.

But if you have a huge squashfs volume for which space to unpack and repack is an issue, or performance is an issue, then overlayfs (man mount --> overlayfs options) is what you want.

  • Mount the squashfs volume mount -t squashfs stuff.sq /mnt/stuff
  • Create the overhead directories for overlayfs mkdir -p /overlay/{upper,work}/stuff /mnt/stuff-new
  • mount it mount -t overlay -o lowerdir=/mnt/stuff,upperdir=/overlay/upper/stuff,workdir=/overlay/work/stuff overlay /mnt/stuff-new (check man page for additional options)
  • Make your changes in /mnt/stuff-new as normal
  • then repack mksquashfs /mnt/stuff-new stuff-new.sq
  • When done, unmount the overlay and delete the scratch directories (and maybe the original squash)

If you want to merge multiple overlapping directory hierarchies, it's only a bit more complicated than this, but you can also list multiple lower directories in the overlay mount and then patch up any overlaps that didn't work out, and repack....

You must log in to answer this question.

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