Xathrya Sabertooth |
Posted: 04 Sep 2013 12:17 AM PDT SquashFS is a compressed read-only file system. SquashFS compress files, inodes, and directories, and supports block sizes up to 1 MB for greater compression. SquashFS is intended for general read-only file system use and in constrained block device / memory systems (e.g. embedded systems) where low overheaded is needed. Originally it use gzip compression, now it support LZMA, LZMA2 and LZO compression. In this article, we will discuss about some notes about how we can manage SquashFS. The term manage in this arcitle including: creating, mounting, and modifying SquashFS file. In this article I use Slackware64 14.0 as host. However you can use any Linux distribution which has SquashFS tools installed. You can always skip all basic and introduction, but I recommend you to read it. PreparationCheck whether you have installed required tools. Test by invoking following binaries: mksquashfs unsquashfs If you don’t have it yet, you can download or compile it from source. Just go to their official site. For Slackware, go to Slackbuilds site for SquashFS. I assume you have the required tools. OverviewAs stated before, SquashFS is a compressed read-only file system. You can imagine it as a file which are exactly a file system. It’s like database file for sqlite, or a disk image for various Virtual Machine apps but only serve a purpose as a filesystem. The read-only filesystem means it can only be read, no write operation allowed. Modification will require dissection of the file. Other important things:
SquashFS Capable KernelThe on-disk format of SquashFS has stabilized enough that it has been merged into the 2.6.29 version of Linux kernel. I assume you use kernel with version greater than 2.6.29. If you are not, you should patch your kernel. But, I think today distribution has ship kernel greater than 2.6.29. The ToolsYou should check the command-line options for mksquashfs and unsquashfs for each capabilities. Using mksquashfsmksquashfs is the tool for creating new squashed file systems, and for appending new data to existing squashed file systems. The general command-line format for mksquashfs is: mksquashfs source1 source2 ... destination [options] Where:
Notes, for default mksquashfs behavior:
Using unsquashfsunsquashfs is the tool for extracting data from squashed file systems. The general command-line format for unsquashfs is: unsquashfs [options] target [files/directories to extract] Where the target is the squashed file system to extract. Notes for unsquashfs behavior:
Managing SquashFSThis section will describe the use of mksquashfs and unsquashfs for managing SquashFS file. Creating a SquashFS FileCreating Simple SquashFSCreating a squashed file system out of a single directory (for ex: /some/dir), and output it to a regular file as image.sqsh. mksquashfs /some/dir image.sqsh Note that the output filename could be anything and any extension. mksquashfs then will perform the squashing and print the resulting number of inodes and size of data written, as well as the average compression ratio. Now we have /some/dir directory image in image.sqsh file. The content of image.sqsh would be any file or directory inside of /some/dir. If you want to output the filesystem directly into a device, i.e. USB flash disk at /dev/sdb1: mksquashfs /some/dir /dev/sdb1 Squashing File SystemsThis section will describe how to create read-only compressed file system. Mounting SquashFS FileTo loop SquashFS file, you will use loopback device. The command is: mount -o loop -t squashfs image.sqsh /mnt/dir For image.sqsh as the SquashFS file and /mnt/dir as the mount point. You should see that the SquashFS can only be accessed read-only. To mount at boot time, you should at this entry to /etc/fstab (assume the image is image.sqsh and the mount point is /mnt/dir): /some/dir/image.sqsh /mnt/dir squashfs loop 0 0 SquashFS and Write Operation using UnionFSUnionfs provides copy-on-write semantics for the read-only file systems (such as SquashFS) which enhancing the possibilities. More detail on the UnionFS can be seen at http://www.filesystems.org/project-unionfs.html Basically, UnionFS is a union of both writable filesystem and read-only filesystem, merged to a single mount point. 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: mksquashfs /home/user1 ro.fs mkdir /home/rw.fs Mount the squashed ro.fs file system using the loopback device: mount -t squashfs -o loop ro.fs /mnt Mount the unionfs filesystem as union of /mnt/and /home/rw.fs. This will be merged under /home/user1 location: cd /home mount -t unionfs -o dirs=rw.fs=rw:/mnt=ro unionfs user1 The write operations under rw.fs will be done to /home/rw.fs. To mount squashed directory tree at startup, you should load the squashfs and unionfs modules at boot time. Change the owner of the writable branch to match user1. Here is the complete command list: echo squashfs >> /etc/modules echo unionfs >> /etc/modules chown user1 /home/rw.fs Add appropriate entry to /etc/fstab to mount the SquashFS and UnionFS at boot time. /home/ro.fs /mnt/squashfs loop 0 0 unionfs /home/user1 unionfs dirs=/home/rw.fs=rw:/mnt=ro 0 0 Extract the File SystemAlso known as unsquashing. The unsquash operation will decompress the squashed file. Suppose we have a file image.sqsh and want to unsquash it: unsquashfs image.sqsh A new directory will be created, as squashfs-root. The content of squashfs-root will be the content of file you or directory you use to create the squashed filesystem. |
You are subscribed to email updates from Xathrya Sabertooth To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Tidak ada komentar:
Posting Komentar