Squashfs Howto
Squashfs Howto
Squashfs Howto
Artemiy I. Pavlov
ArtemioLabs
Marco Cecchetti
<mrc (dot) ildp (at) gmail (dot) com>
Revision History
Revision 1.8 2008-01-06 Revised by:
Changes according to SquashFS release 3.3. Some parts added.
Revision 1.7 2005-03-25 Revised by:
Changes according to SquashFS release 2.1.
Revision 1.6 2004-11-10 Revised by:
Changes according to SquashFS release 2.0. Text corrections.
Revision 1.5 2004-06-07 Revised by:
Changes according to SquashFS release 2.0 alpha. Lots of description improvements and clarifications. Split
instructions for Linux kernels of 2.6.x (new) and 2.4.x series.
Revision 1.1 2004-05-22 Revised by:
Changes according to SquashFS release 1.3r3.
Revision 1.0 2004-02-19 Revised by:
Initial Release, reviewed by LDP.
Revision 0.2 2003-12-08 Revised by:
Text corrections, license added.
Revision 0.1 2003-11-24 Revised by:
Initial version. Instructions for SquashFS release 1.3r2.
Abstract
This HOWTO describes the usage of SquashFS - a highly-compressed read-only file system for Linux, which
is intended for use in tiny-sized and embedded systems, and anywhere else you'd want to use a compressed
file system. With this document, you'll learn how to prepare a SquashFS-ready Linux kernel, create a
squashed file system and happily use it.
Table of Contents
1. What is SquashFS...........................................................................................................................................1
1.1. Introduction.......................................................................................................................................1
1.2. Overview of SquashFS.....................................................................................................................1
1.3. Making it clear..................................................................................................................................1
5. Acknowledgements.......................................................................................................................................15
6. License............................................................................................................................................................16
i
1. What is SquashFS
1.1. Introduction
When creating tiny-sized and embedded Linux systems, every byte of the storage device (floppy, flash disk,
etc.) is very important, so compression is used everywhere possible. Also, compressed file systems are
frequently needed for archiving purposes. For huge public archives, as well as for personal media archives,
this is essential.
SquashFS brings all this to a new level. It is a read-only file system that lets you compress whole file systems
or single directories, write them to other devices/partitions or to ordinary files, and then mount them directly
(if a device) or using a loopback device (if it is a file). The modular, compact system design of SquashFS is
bliss. For archiving purposes, SquashFS gives you a lot more flexibility and performance speed than a tarball
archive.
SquashFS is distributed as a Linux kernel source patch (which enables SquashFS read support in your kernel),
the mksquashfs tool, which creates squashed file systems (in a file or on a block device) and the unsquashfs
tool, which extracts multiple files from an existing squashed file system.
The latest SquashFS release tree is 3.x, the former one was 2.x. This document describes both these releases
with proper notes given. For example, if some feature or parameter is different in these release trees, it will be
written as follows: new value (3.x) or old value (2.x)
1. Patching and recompiling the target Linux kernel to enable SquashFS support
2. Compiling the mksquashfs and the unsquashfs tools
3. Creating a compressed file system with mksquashfs
4. Testing: mounting a squashed file system to a temporary location
1. What is SquashFS 1
SquashFS HOWTO
5. Modifying the /etc/fstab or startup scripts of your target Linux system to mount the new
squashed file system when needed
1. What is SquashFS 2
2. Getting ready for SquashFS
2.1. Acquiring SquashFS
The SquashFS home site is located at http://squashfs.sourceforge.net/ - it contains news for the latest release
and it's changelog, as well as general information about SquashFS. You can grab the latest version at the
SquashFS project page at SourceForge.
Change to the SquashFS source directory and copy the kernel patch (we'll assume it's named
squashfs-patch) to /usr/src/linux.
bash# cd /usr/src/squashfs
bash# cp linux-2.x.y/squashfs-patch /usr/src/linux
Go to the linux kernel source directory /usr/src/linux:
bash# cd /usr/src/linux
Note: please remember that we will not be leaving this directory during all further kernel-related procedures,
and all paths will be given relative to /usr/src/linux.
bash# make
1. In the "File systems"section, enable the "Squashed filesystem"option, whether as module or bundled
with the kernel. It is only obligatory to compile SquashFS inside the kernel if you plan using squashed
initial RAM disks (initrd).
2. If you would like to use a squashed initial RAM disk, enable the "Initial RAM disk support"in the
"Block devices"section.
3. If you want to be able to mount the squashed file system via a loopback devicein future, you should
enable " Loopback device support "in the "Block devices "section.
We assume that the kernel was compiled for a x86 architecture, and the compressed kernel image is located in
the arch/i386/boot/ subdirectory of the kernel tree. Now copy the kernel to the /boot directory (and
name it bzImage-sqsh for convenience, if you like):
bash# cd /usr/src/squashfs/squashfs-tools
Compile and install the tools:
bash# make
bash# cp mksquashfs /usr/sbin
bash# cp unsquashfs /usr/sbin
If everything went fine, typing mksquashfs or unsquashfs at the shell prompt should print the "usage"
message.
Then you have to add the squashfs module to /etc/modules file if you need it loaded at boot time.
• source1, source2, etc.: files and directories to be added to the resulting file system, given with
relative and/or absolute paths
• destination: a regular file (filesystem image file), or a block device (such as /dev/fd0or
/dev/hda3) where you want to have your squashed file system
• When the new files are added to the new file system or appended to an existing one, mksquashfs will
automatically rename files with duplicate names: if two or more files named textwill appear in the
same resulting directory, the second file will be renamed to text_1, third one to text_2and so on.
• Duplicate files will be removed, so there will be only one physical instance (By the SquashFS 2.x,
you can disable the detection/removal of the duplicates with the -no-duplicates option).
• If destination has a pre-existing SquashFS file system on it, by default, the new sourceitems will be
appended to the existing root directory. Examine the options table below to force mksquashfs to
overwrite the whole destination and/or change the way new source items are added.
• If a single source file or directory is given, it becomes the root in a newly created file system. If two
or more source files and/or directories are given, they will all become sub-items in the root of the new
file system.
• The resulting filesystem will be padded to a multiple of 4 Kb: this is required for filesystems to be
used on block devices. If you are very sure you don't need this, use the -nopad option to disable this
operation.
See the next section for more details about all possible options.
Option Description
-2.0 force mksquashfs version 2.1 to create a version 2.0 filesystem
-all-root or -root-owned make all files in the target file system owned by root (UID=0, GID=0)
divide all files greater than block size into fragments (by the version 2.x). It
-always-use-fragments
will result in greater compression ratios
use [block size] filesystem block size (32 Kbytes default for 2.x, 128 kbytes
-b [block size]
for 3.x) - this can be either 4096, 8192, 16384, 32768, 65536 or 131072
• Not specifying any destination path, unsquashfs extracts the compressed file system in the
./squashfs-root directory.
• The tool does not extract a squashed file system on already exsisting directory unless the -foption is
specified.
• You can specify on the command line, a multiple number of files/directories to extract and the items
to be extracted can be also be given in a file with -e [file]option.
All possible options for unsquashfs are shown in the table below.
Option Description
-v[ersion] print the version, licence and copyright message
-i[nfo] print the files as they are extracted from the file system
-l[ist] list the squashed file system without extracting files
-li list files with theyr attributes as they are unsquashed (3.3)
-ll list the squashed file system files with attributes without any extraction (3.3)
-d[estination]
specify a destination path for unsquashed items
path
-f[orce] if files exist overwrite them
display file system's superblock informations (it can discover the file system version and
-s[tat]
the options used to compress it - 3.3)
-e[f] [extract file] list of directories or files to extract (entries given one per line) (3.3)
-r[egex] treat extract names as POSIX regular expressions (3.3)
Note that by 3.x release you can extract 1.x and 2.x squashed file system too.
bash# ls /mnt/dir
If you want to output the file system directly into a device (say, your floppy at /dev/fd0):
bash# ls /mnt/floppy
4.2.1. Example 1
Let's suppose you have a /var/arch directory with lots of files and that you want to turn it into a squashed
file system and keep it on your root partition as a file (it will be a file system image that you will mount via a
loopback device). The operations needed to perform are as follows.
bash# ls /var/arch
4.2.2. Example 2
Say you have two hard disk partitions, /dev/hda6 (which is empty) and /dev/hda7 (which is bigger than
/dev/hda6, mounted at /var/arch, contains some data and is full). Now, say you want to squash the
/dev/hda7 file system and move it to /dev/hda6, then use /dev/hda7 for some other purposes. We
will suppose you have the following line in /etc/fstab (reiserfs is just an example file system used on
/dev/hda7):
bash# rm /var/arch.sqsh
1. When developing a kernel for your system, make sure you enable SquashFS support so it can mount
squashed file systems
2. Use mksquashfs for creating read-only initial ram disks and/or root and/or other file systems
3. Don't forget to set file system types to squashfs in /etc/fstab and/or the startup scripts of your
system for mounting squashed file systems
Floppy example. Let's say you have your floppy system tree at /home/user/floppylinux and you want
to place the root file system on one floppy and /usr on another. What you should do is:
bash# cd /home/user
bash# mksquashfs floppylinux root.sqsh -e usr
bash# mksquashfs floppylinux/usr usr.sqsh
Note 1: you can see here how we use the -e option to exclude the /usr directory for root file system's image.
Note 2: don't forget to specify squashfs in your root disk's /etc/fstab or startup scripts when mounting
the /usr file system.
Insert a root disk in your 3.5" floppy drive (I assume you have a lilo or grub on it, and, thus, a file system
exists on this floppy, and the root file system will reside under the /boot directory of this file system):
If you create a root file system out of a running Linux system, use the -e option for mksquashfs to exclude all
pseudo-filesystems such as /proc, /sys (on linux kernels after 2.5.x) and /dev (when using DevFS). Also,
don't forget to add the file system image itself that is being created with mksquashfs (I think you know the
reasons for these exclusions).
Just to make an example, you may want to make your /home/user squashed, to compress and backup your
files without losing the possibility to apply changes or writing new files.
Create the ro.fs squashed file system and the rw.fs dir.
bash# cd /home
bash# mount -t unionfs -o dirs=rw.fs=rw:/mnt=ro unionfs user1
As you can see now you can apparently create new files in /home/user1.
bash# cd /home/user1
bash# touch file1
bash# ls
umount the unionfs and the squashfs file systems and list the content of /home/user1 and /home/rw.fs dir
bash# cd ..
bash# umount /home/user1
bash# umount /mnt
bash# ls /home/user1
bash# ls /home/rw.fs
You can see that the new file1 was created in /home/rw.fs that's the phisical location of the real
writeble branch of the "merged" file system.
When you want to add the new created files to the stable and compressed squashed file system, you have to
add them to the exsisting one.
• Phillip Lougher - for his brilliant work under squashfs, for creating an exculsive patch for
linux-2.4.18, for his help with polishing this howto and answers to my mails
• Tabatha Marshall at TLDP for helping me with bringing this HOWTO to the final 1.0 release
• Everybody at The Linux Documentation Projectfor their great work under all the HOWTOs and
guides that helped me a lot with exploring and hacking Linux
• All those at the TLDP mailing lists who helped me with getting started
• Endless thanks and respect to everybody who develops open-source software
Artemiy I. Pavlov
I want to thank Artemiy for his patience answering my emails allowing me to work to this howto. I would
express also my thanks and respect to everybody who is involved in free software.
Marco Cecchetti
5. Acknowledgements 15
6. License
This document may be used and distributed under the terms and conditions set forth in the Open Content
licence. In short, this means that you can freely modify and re-distribute the HOWTO under the main
condition that you keep the author and copyright the article along. The full text of the licence is available at
http://www.opencontent.org/opl.shtml
6. License 16