For the complete documentation index, see llms.txt. This page is also available as Markdown.

27.4 UFS Disk Snapshots

FreeBSD provides file system snapshot functionality that works in conjunction with Soft Updates. UFS snapshots allow users to create images of a specified file system, which can be handled as files.

Snapshot files must be created within the file system being snapshotted, and up to 20 snapshots can be created per UFS file system. Active snapshots are recorded in the superblock and persist across system reboots. When a snapshot is no longer needed, it can be deleted using rm(1). Although snapshots can be deleted in any order, not all used space may be fully reclaimed since other snapshots may occupy some of the freed blocks. When a snapshot is created, the kernel sets the SF_SNAPSHOT file flag to prevent accidental modification.

Creating Snapshots

You can use mksnap_ffs(8) to create a snapshot of / and store it in /.snap/snap1:

# mksnap_ffs /.snap/snap1

Tip

mksnap_ffs automatically creates a snapshot of the file system where the specified directory resides; it does not support directly specifying a file system. The above example is based on a standard UFS installation, so it will create a snapshot of the entire root partition.

You can also create a snapshot through mount(8). To save a snapshot of / to the file /home/ykla/snapshot/snap, use the following command:

# mkdir -p /home/ykla/snapshot/
# mount -u -o snapshot /home/ykla/snapshot/snap /

The size of a UFS snapshot file equals the size of its source file system, but the actual space occupied is similar to ZFS:

# ls -loh /home/ykla/snapshot/snap      # Logical storage usage
-r--------  1 root ykla snapshot   19G May  1 01:55 /home/ykla/snapshot/snap
# du -hl /home/ykla/snapshot/snap       # Actual storage usage
6.1M /home/ykla/snapshot/snap

File Flags

The SF_SNAPSHOT file flag is set when a snapshot file is created (whether through mksnap_ffs(8) or the snapshot operation of mount(8)). This flag prevents accidental modification of the snapshot file. However, rm(1) makes an exception for snapshot files — they can be deleted even with the SF_SNAPSHOT flag set, without needing to clear the flag first.

You can use find(1) to locate snapshot files in a file system, for example /:

Mounting Snapshots

Snapshots can be mounted as frozen images of a file system. To mount the snapshot /home/ykla/snapshot/snap in read-only mode, run the following commands:

Option descriptions:

Parameter
Meaning

-a

Create an md device

-t vnode

Use a file as a disk

-f file

Specify the snapshot file

-u 4

Assign to md4 to avoid conflicts

After mounting, the frozen / is accessible through /mnt, with all contents preserved in the state at the time the snapshot was created. The only exception is that any earlier snapshots will appear as empty files. To unmount the snapshot, run the following commands:

References

  • McKusick M. McKusick.com[EB/OL]. [2026-04-30]. https://www.mckusick.com/. For more information about Soft Updates and file system snapshots (including technical papers), visit Kirk McKusick's website.

Last updated