Send to Kindle
home » snippets » squashfs



sudo apt-get install squashfs-tools


mksquashfs --help

mksquashfs source... dest [options] [-e list of exclude dirs/files] [-ef exclude_file]

# Creating a squashfs file from a directory.
mksquashfs <directory> <squashfs_file.squashfs> -info

# Mounting it
sudo mount -t squashfs <squashfs_file.squashfs> <mount_point> -o loop

# Overlaying read only / read write.
# See: http://aufs.sourceforge.net/aufs.html#EXAMPLES
sudo mount -t aufs -o br:/rw_branch=rw:/ro_branch=ro none /merged_mount_point

# Uncompressing
unsquashfs -li <squashfs_file.squashfs>

Overlaying read-write directory over a read-only squashfs

/etc/fstab entry
# First mount the squashfs file as readonly
<squashfs_file.squashfs> <mount_directory_read_only> squashfs loop,ro 0 0

# Now mount final location with the union (via aufs)
# See: http://aufs.sourceforge.net/aufs.html#EXAMPLES
none <mount_directory_final> aufs br=<read_write_directory>=rw:<mount_directory_read_only>=ro 0 0

# This is a better way to go as we use rr instead of
# ro for the squashfs branch allowing optimization
# in aufs (no need of whiteouts, etc since
# underlying fs is really ro.)
none <mount_directory_final> aufs br=<read_write_directory>=rw:<mount_directory_read_only>=rr 0 0



Assume that you have /opt/local/data.squashfs which is a squashfs compressed file. You want to mount this such that /opt/local/data displays it's data, but anything written to it goes into /opt/local/data.read-write. So we mount the squashfs into /opt/local/data.read-only and then mount both this and read-write directory onto /opt/local/data.

/opt/local/data.squashfs /opt/local/data.read-only squashfs loop 0 0 none /opt/local/data aufs br=/opt/local/data.read-write=rw:/opt/local/data.read-only=ro 0 0