Squash Your Read-Only Data to Save Disk Space

SquashFS is a compressed read-only file system for Linux. Most live-cd distributions compress the data on their CDs with (you guessed) SquashFS.

It used to be necessary to patch and recompile the kernel to get SquashFS to work, but in modern distributions it seems to work out of the box – at least in Ubuntu it does. All you have to do is install the squashfs-tools package.

sudo aptitude install squashfs-tools

I’ll give an example of how to create and mount a SquashFS image. I will compress two directories: kdelibs-apidocs (the API for KDE 3.5, about 280MB) and jdk-1_5_0-doc (the API for Java SDK 5.0, about 225MB). To create the image, use the command mksquashfs <list of directories> <image name>

mksquashfs kdelibs-apidocs/ jdk-1_5_0-doc/ doc.squashfs

Pure magic! 505MB of data compressed into a reasonable-sized 71MB image!

But that’s not all. Now you can mount the image and browse the directories in it at a speed almost as high as if they wouldn’t be compressed.

sudo mount -o loop -t squashfs doc.squashfs /mnt/doc

And unmount it with

sudo umount /mnt/doc

You can put these into scripts and have them on your desktop, only one click away!

Here’s a tip for the more adventurous folk: You can have LZMA compression with SquashFS, but that requires some dirty kernel patching. LZMA is one of the best compression algorithms out there, as you may know from the 7-Zip file archiver. The default SquashFS uses mere gzip compression.


//offtopic:
I’m kinda busy these days, preparing for the National Programming Olympiad, which will take place this weekend. After that I’m going to Romania for the .Campion final. Forgive my silence for one more week (or so).

Comments are closed.

%d bloggers like this: