Read-only compressed filesystems

Compressing data is useful if you don't have quite enough storage to fit everything in. Both JFFS2 and UBIFS do on-the-fly data compression by default. However, if the files are never going to be written, as is usually the case with the root filesystem, you can achieve better compression ratios by using a read-only compressed filesystem. Linux supports several of these: romfs, cramfs, and squashfs. The first two are obsolete now, so I will describe only squashfs.

squashfs

squashfs was written by Phillip Lougher in 2002 as a replacement for cramfs. It existed as a kernel patch for a long time, eventually being merged into mainline Linux in version 2.6.29 in 2009. It is very easy to use: you create a filesystem image using mksquashfs and install it to the flash memory:

$ mksquashfs rootfs rootfs.squashfs

The resulting filesystem is read-only so there is no mechanism to modify any of the files at runtime. The only way to update a squashfs filesystem is to erase the whole partition and program in a new image.

squashfs is not bad block-aware and so must be used with reliable flash memory such as NOR flash. It can be used on NAND flash as long as you use UBI to create an emulated, reliable, MTD volume on top of UBI. You have to enable kernel configuration CONFIG_MTD_UBI_BLOCK, which will create a read-only MTD block device for each UBI volume. The following diagram shows two MTD partitions, each with accompanying mtdblock devices. The second partition is also used to create a UBI volume which is exposed as a third, reliable, mtdblock device, which you can use for any read-only filesystem that is not bad block-aware:

squashfs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.79