> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.4-jie-ufs-ci-pan-kuai-zhao.md).

# 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**:

```sh
# 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:

```sh
# 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:

```sh
# 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 **/**:

```sh
# find / -flags snapshot
/.snap/snap1
/home/ykla/snapshot/snap
```

## 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:

```sh
# mdconfig -a -t vnode -f /home/ykla/snapshot/snap -u 4
# mount -r /dev/md4 /mnt
# ls /mnt/
.snap                dev             libexec         rescue          var
.sujournal   entropy         media           root
COPYRIGHT    etc             mnt             sbin
bin          home            net             tmp
boot         lib             proc            usr
```

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:

```sh
# umount /mnt
# mdconfig -d -u 4
```

## 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.4-jie-ufs-ci-pan-kuai-zhao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
