|
|
4. Creating and using squashed file systems4.1. Basic stepsIn order to create a squashed file system out of a single directory (say, /some/dir), and output it to a regular file (thus, producing a file system image), you need to say only one magic phrase:
mksquashfs will perform the squashing and print the resulting number of inodes and size of data written, as well as the average compression ratio. Now you have your /some/dir directory image in the dir.sqsh file. You can now use the mount command to mount it using a loopback device:
To check if you have what's expected:
If you want to output the file system directly into a device (say, your floppy at /dev/fd0):
Then just mount the device:
And check if it's okay:
4.2. Squashing file systemsOperations described here correspond to most cases where a read-only compressed file system can be used, whether you want it to be on a block device or in a file. This could be anything from large FTP/HTTP-served archives that don't change often, to having a squashed /usr partition and anything alike with these. 4.2.1. Example 1Let'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. Squash the directory, then mount it via loopback to test it:
If everything is as expected, make this file system mount automatically at boot time by adding this line to your /etc/fstab:
Unmount the file system from the temporary mount point, and mount using it's fstab entry:
Now just ensure that everything works fine:
4.2.2. Example 2Say 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):
In the same fashion as with the previous example:
If everything went fine, unmount /dev/hda7 (if needed) and use dd to copy /var/arch.sqsh to /dev/hda6:
Now change the line in /etc/fstab for /dev/hda7 to:
Mount the new file system and check to see if all went fine:
Don't forget to erase the unneeded file system image:
4.3. Creating tiny/embedded systemsBy saying "tiny/embedded", I mean Linux systems that are being built for booting from floppy disks, IDE/USB flash disks, iso9660 CD-ROMs, small-sized hard drives and the like. Whether you want to have your whole root file system on a single media (a single partition, a single floppy), or have a modular system (several floppies or disk partitions), the procedure is almost identical. Creating such Linux systems themselves is out of scope of this HOWTO - there are dedicated HOWTOs and guides for this (like the Bootdisk HOWTO and Linux From Scratch - visit www.tldp.org to retrieve these documents). 4.3.1. Squashed file systems on floppy/flash/hard disksIn order to use SquashFS for creating Linux systems on small disks, you just have to follow the usual steps for creating a minimal system, performing the following operations at respective points:
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:
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):
When done, unmount the root floppy, change the floppy to a /usr disk and use dd to transfer the usr file system:
4.3.2. Squashed file systems on CD-ROMsWith SquashFS, you can compress large file systems that will be used in live CDs (just as an example).
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). |