How to edit a squashfs image directly without extracting and re-packing

mountsquashfs

I have a squashfs image file that I copied from a bootable iso file.
When mounting the file, it always mounts it read-only.

Is it possible to directly edit the content without extracting the squashfs image first, or is it possible to mount squashfs images read-write?

Best Answer

It is possible to modify a squashfs image without extracting its contents, but there are limitations. If you specify an existing squashfs image as the destination parameter for mksquashfs, without specifying the -noappend option, it will attempt to add additional files from the specified source parameters. It appears that mksquashfs attempts to generate a new name if it encounters a conflict, which is probably not what you want if the goal is to edit files in place.

In principle, mksquashfs could allow files to be replaced (and preserve the name in the process) in append mode, but the version I'm using , mksquashfs version 4.3-git (2014/06/09) (from the current debian package in sid), doesn't seem to allow that. It should be possible to make arbitrary incremental changes to a squashfs image, with the right code (file deletions might not be space efficient, if they merely orphan existing blocks, and existing file offsets are reused, and new data is appended), but that seems unlikely to work well on a mounted image (you'd need to unmount the image before modifying it, and remount it afterward).

Related Question