What is NILFS?
NILFS is a new implementation of a log-structured file system (LFS) supporting continuous snapshotting. In addition to versioning capability of the entire file system, users can even restore files mistakenly overwritten or destroyed just a few seconds ago. Since NILFS can keep consistency like conventional LFS, it achieves quick recovery after system crashes.
NILFS creates a number of checkpoints every few seconds or per synchronous write basis (unless there is no change). Users can select significant versions among continuously created checkpoints, and can change them into snapshots which will be preserved until they are changed back to checkpoints.
There is no limit on the number of snapshots until the volume gets full. Each snapshot is mountable as a read-only file system. It is mountable concurrently with a writable mount and other snapshots, and this feature is convenient to make consistent backups during use.
Snapshot administration is easy and quickly performable. NILFS will make snapshotting or versioning of the POSIX filesystem much familiar to you. The possible use of NILFS includes, versioning, tamper detection, SOX compliance logging, and so forth. It can serve as an alternative filesystem for Linux desktop environment, or as a basis of advanced storage appliances.
The current major version of NILFS is version 2, which is referred to as NILFS2. NILFS2 realized online garbage collection that reclaims disk space with keeping multiple snapshots.
Other NILFS features include:
- B-tree based file and inode management.
- Immediate recovery after system crash.
- 64-bit data structures; support many files, large files and disks.
- 64-bit on-disk timestamps which are free of the year 2038 problem.
- On-line resize; support both enlarging and shrinking the size of a mounted file system.
Here we illustrate by examples how to use NILFS version 2:
Format a disk partition with mkfs(8).
e.g. # mkfs -t nilfs2 /dev/sdb1 mkfs.nilfs2 ver 2.0 Start writing file system initial data to the device Blocksize:4096 Device:/dev/sdb1 Device Size:73402366464 File system initialization succeeded !!
Mount it on a mount-point with mount(8) command,
# mkdir /nilfs # mount -t nilfs2 /dev/sdb1 /nilfs
This will invoke a garbage collector (GC) through mount.nilfs2(8) helper program. The garbage collector is separately implemented as a user space daemon nilfs_cleanerd(8) and can be executed manually.
Use the nilfs mount point as usual
It's available as an ordinary POSIX filesystem.
NILFS makes ``checkpoints'' at regular intervals (unless there is no change) or with synchronous writings. Each checkpoint represents a consistent state of NILFS filesystem, and a number of checkpoints are created continuously. There is no practical limit on the number of checkpoints and snapshots.
These checkpoints can be listed with lscp(1) command.
$ lscp CNO DATE TIME MODE FLG NBLKINC ICNT 1 2008-05-08 14:45:49 cp - 11 3 2 2008-05-08 14:50:22 cp - 200523 81 3 2008-05-08 20:40:34 cp - 136 61 4 2008-05-08 20:41:20 cp - 187666 1604 5 2008-05-08 20:41:42 cp - 51 1634 6 2008-05-08 20:42:00 cp - 37 1653 7 2008-05-08 20:42:42 cp - 272146 2116 8 2008-05-08 20:43:13 cp - 264649 2117 9 2008-05-08 20:43:44 cp - 285848 2117 10 2008-05-08 20:44:16 cp - 139876 7357
A snapshot is the checkpoint marked not to be deleted by GC. It is possible to make a snapshot of the current state by mkcp(8) command, and is also possible to change an existing checkpoint into a snapshot. Checkpoints and snapshots are manipulated through the following userland tools:
lscp lists checkpoints. mkcp makes a checkpoint. mkcp -s makes a snapshot. chcp changes an existing checkpoint to a snapshot or vice versa. rmcp invalidates specified checkpoint(s).
In the following example, an existing checkpoint with checkpoint number two, is changed into a snapshot after a period of time.
$ sudo chcp ss 2 $ lscp CNO DATE TIME MODE FLG NBLKINC ICNT 1 2008-05-08 14:45:49 cp - 11 3 2 2008-05-08 14:50:22 ss - 200523 81 3 2008-05-08 20:40:34 cp - 136 61 4 2008-05-08 20:41:20 cp - 187666 1604 5 2008-05-08 20:41:42 cp - 51 1634 6 2008-05-08 20:42:00 cp - 37 1653 7 2008-05-08 20:42:42 cp - 272146 2116 8 2008-05-08 20:43:13 cp - 264649 2117 9 2008-05-08 20:43:44 cp - 285848 2117 10 2008-05-08 20:44:16 cp - 139876 7357 11 2008-05-08 21:05:23 cp - 10 7357
The recent checkpoints are protected from GC during the period given by a GC parameter ``protection_period''; GC never deletes checkpoints whose age from its creation time is less than the value given by the protection_period on the second time scale.
GC parameters are described in /etc/nilfs_cleanerd.conf(5) and the behavior of GC is tunable by rewriting the config file.
Snapshots are mounted with two options, a read-only option (``-r'' or ``-o ro'') and a ``cp'' option which specifies the number of checkpoint you want to mount.
# mount -t nilfs2 -r -o cp=2 /dev/sdb1 /nilfs-cp # df -t nilfs2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 71679996 3203068 64888832 5% /nilfs /dev/sdb1 71679996 3203068 64888832 5% /nilfs-cp # mount -t nilfs2 /dev/sdb1 on /nilfs type nilfs2 (rw,gcpid=13296) /dev/sdb1 on /nilfs-cp type nilfs2 (ro,cp=2)
The ``current'' filesystem and snapshots are mountable independently.
Unmount snapshots or rw-mount.
# umount /nilfs # umount /nilfs-cp
The GC daemon will be shutdown on umount.
Copyright © 2014 - 2017, NILFS Community.