What is NILFS?
NILFS is a New Implementation of Log-structured File System (LFS) that supports continuous snapshot taking. In addition to full file system versioning, this feature of NILFS allows users to restore accidentally deleted or overwritten files to their previous state. Like traditional LFS, NILFS can guarantee file system consistency after a system crash or unclean shutdown, and like journaling file systems, can quickly recover.
NILFS generates checkpoints every few seconds to tens of seconds unless there are no changes, or more frequently if there are a lot of updates. Users can select any of the many checkpoints generated and later turn them into snapshots, which will remain until they are reverted to checkpoints.
There is no limit on the number of snapshots until the volume gets full. Each snapshot can be mounted as a read-only file system. Snapshots can coexist with a writable mount (they can be mounted on different mount points at the same time), which helps you take consistent backups during use.
Snapshot management is easy and fast, allowing users to easily enjoy the benefits of file system level snapshots. The possible use of NILFS includes, versioning, tamper detection, SOX compliance logging, and so forth. It can serve as an alternative filesystem for Linux enviroments, or as the basis for storage appliances.
The current major version of NILFS is version 2, which is referred to as NILFS2. NILFS2 realized an online garbage collection feature that allows disk blocks that are no longer referenced to be reclaimed and reused as free space while retaining 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.
Using NILFS
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 -p /mnt/nilfs # mount -t nilfs2 /dev/sdb1 /mnt/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.
-
Make snapshots
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 BLKCNT ICNT 1 2024-03-16 23:49:26 cp - 4 1 2 2024-03-16 23:49:44 cp - 4 1 3 2024-03-16 23:50:55 cp - 3208 625 4 2024-03-16 23:51:18 cp - 2207 506 5 2024-03-16 23:51:23 cp - 2204 503 6 2024-03-16 23:51:29 cp - 2684 829 7 2024-03-16 23:51:34 cp - 2784 761 8 2024-03-16 23:51:39 cp - 2777 789 9 2024-03-16 23:51:44 cp - 3250 644
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 BLKCNT ICNT 1 2024-03-16 23:49:26 cp - 4 1 2 2024-03-16 23:49:44 ss - 4 1 3 2024-03-16 23:50:55 cp - 3208 625 4 2024-03-16 23:51:18 cp - 2207 506 5 2024-03-16 23:51:23 cp - 2204 503 6 2024-03-16 23:51:29 cp - 2684 829 7 2024-03-16 23:51:34 cp - 2784 761 8 2024-03-16 23:51:39 cp - 2777 789 9 2024-03-16 23:51:44 cp - 3250 644 10 2024-03-16 23:51:49 cp - 3187 624
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.
-
Mount snapshots.
Snapshots are mounted with two options, a read-only option (``-r'' or ``-o ro'') and a ``cp'' option that specifies the number of checkpoint you want to mount.
# mkdir -p /mnt/snapshot # mount -t nilfs2 -r -o cp=2 /dev/sdb1 /mnt/snapshot # df -at nilfs2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 4186108 49148 3923968 2% /mnt/nilfs /dev/sdb1 4186108 49148 3923968 2% /mnt/snapshot # mount -t nilfs2 /dev/sdb1 on /mnt/nilfs type nilfs2 (rw,relatime) /dev/sdb1 on /mnt/snapshot type nilfs2 (ro,relatime,cp=2)
The ``current'' filesystem and snapshots are mountable independently.
-
Unmount snapshots or rw-mount.
# umount /mnt/nilfs # umount /mnt/snapshot
The GC daemon will be shutdown on umount.
Copyright © 2014 - 2024, NILFS Community.