LFS is a standard Linux file-system. It is mounted as any other file-system and standard utilities like mkfs for managing it are provided. The following table presents a list of all support programs and their counterparts for the ext2 file-system for the convenience.
program | ext2 | description |
mkfs.lfs | mke2fs | Creates an empty file-system on a disk partition and fills it with an empty root directory. |
lfs-gc | -- | Garbage-collector that frees unused space. It is started automatically in the mount time. |
# mkfs.lfs /dev/hdb1 mkfs.lfs: version = 1.0 mkfs.lfs: device = /dev/hdb1 mkfs.lfs: volume name = LFS mkfs.lfs: device size = 987966 kB (0.94 GB) mkfs.lfs: block size = 4 kB mkfs.lfs: segment size = 1024 kB = 256 blocks mkfs.lfs: reserved space = 1024 kB = 256 blocks (1 segments) writing data..... ................................ ifile has 15472 bytes addresses per indirect block : 512 writing 0. super block at 0x0000000001000000 (checksum is 0xb29a8d3b) ... OK writing 1. super block at 0x000000000fc00000 (checksum is 0xb29a8d3b) ... OK writing 2. super block at 0x000000001e800000 (checksum is 0xb29a8d3b) ... OK writing 3. super block at 0x000000002d400000 (checksum is 0xb29a8d3b) ... OK syncing ... LFS successfully created on /dev/hdb1
# mount -t lfs /dev/hdb1 /mnt/lfs
After successfully completing all steps, LFS can be used.
Snapshot is a special ability of LFS that has no counterpart in ext2-like file-systems. Sometime you want to make copy of frequently updated data or simply just to read them. The problem is that some data are changing to often and your copy would not be consistent. This problem is often encountered when one makes a backup copy. Solution is to stop all writing, so data are not change, while the copy is being made. Of course this solution has its disadvantages.
Solution provided by LFS is simple. Just mount file-system once more in a special snapshot-mode. Snapshot contains state of the whole file-system in the time of mount. It will never change even if the underlying LFS file-system does.
To take a snapshot you have to know an id of the mounted system. Because one file-system can be mounted to multiple places with different options we do not use a path (mount-point) as the identifier. Rather each LFS file-system has its own special id that can be used to reference it.
If you do not provide an id when mounting the file-system, an unused id is generated. You can check the /sys/filesystems/lfs/ directory for all LFS file-systems in use. Each mounted LFS has its own subdirectory, which name is equal to its id Files in this directory export various runtime data - mainly for debugging purposes. Generated ids have the format lfs%d. Identifier lfs0 is assigned to the first mounted LFS file-system.
Once you know the id of a file-system you can mount a snapshot, e.g. to /mnt/snap, using command:
#mount -t lfs-snap lfs0 /mnt/snap
To close snapshot just umount the snapshot file-system by:
#umount /mnt/snap
Prior to mounting a file-system, it must be created on a device using the mkfs.lfs utility. Program first checks the size of the supplied device, it checks whether the device is large enough (the lower limit is 100MB) and prints out the file-system parameters (device size, segment size, block size, etc.)
mkfs.lfs cleans all segment summaries before any other data are written to the disk. This can take a while, depending on the device size. Program signals that the process wasn't finished yet by printing dots.
In the next stage, .ifile and the super blocks are written. After this, all
the data must be written back from caches to the device. Since cleaning
segment summaries means writing a lot of bytes for a large disks, flushing
cashes takes some time as well.
Finally, message LFS
successfully created on <device> signals that the file-system was successfully
created and is ready to be used.
If you do not specify noatime option it will be added. LFS cannot be mounted without this option.
Snapshot is mounted as a special read-only file-system. Its type is lfs-snap. Original file-system is synced during mounting the snapshot. Snapshot represents the LFS state after that sync. Snapshot file-system doesn't support any additional options.
The device used to mount a snapshot is always an id of the original file-system.
Once a snapshot is mounted all included data is still remaining on the disk. This means that if you delete a file from the live system, the space it was using is not freed until the snapshot is umounted. When you edit the file created before a snapshot was taken, a new version of this file will be stored on the disk along with the old one, consuming additional space. Notice that if a snapshot is mounted and the live file-system is being concurrently modified, all new data takes extra space even if old data is overwritten. On the other hand appending extra data to a file will not double the whole size of the file. Snapshot acts in the copy-on-write fashion.
After umount all obsolete (deleted or modified) data is freed and free space on disk increases.
$ dump.lfs /dev/hdb1 sb fs.sb.@address = 0x01000000 fs.sb.s_segment_count = 101 fs.sb.s_log_blocks_per_seg = 8 (256) fs.sb.s_reserved_segment = 1 fs.sb.s_free_blocks_count = 25600 fs.sb.s_free_seg_count = 93 fs.sb.s_first_free_inode = 3 fs.sb.s_used_inodes = 3 fs.sb.s_log_block_size = 12 (4 KiB (4096 bytes)) fs.sb.s_ifile_addr = 0x00406000 fs.sb.s_next_block = 0x408 fs.sb.s_segment_counter = 5 fs.sb.s_mtime = Sun Aug 20 18:26:56 2006 fs.sb.s_wtime = Sun Aug 20 18:29:50 2006 fs.sb.s_mnt_count = 0 fs.sb.s_max_mnt_count = 0 fs.sb.s_magic = 0x1234 fs.sb.s_state = 0x00000000 fs.sb.s_errors = 0x00000000 fs.sb.s_minor_rev_level = 0 fs.sb.s_lastcheck = Sun Aug 20 18:26:56 2006 fs.sb.s_checkinterval = 0 fs.sb.s_rev_level = 0 fs.sb.s_feature_compat = 0x00000000 fs.sb.s_feature_incompat = 0x00000000 fs.sb.s_feature_ro_compat = 0x00000000 fs.sb.s_volume_name = "LFS" fs.sb.s_checksum = 0x02d4e8f7
Mounted LFS file system provide a a lot of of information about its internal state, which can be read through sysfs. There is a subdirectory for each mounted instance in /sys/filesystems/lfs. A comprehensive overview of all the files is shown in table 3.1. Please note that values prefixed with stat_ are not present if the LFS module is compiled without statistical data.
Viliam Holub 2006-12-04