> 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.3-jie-ufs-ci-pan-kuo-zhan.md).

# 27.3 UFS Disk Expansion

> **Warning**
>
> UFS file systems can only be expanded, not shrunk.

Use the `gpart show` command to view the partition layout of all disks in the system:

```sh
# gpart show
=>       3  41943035  da0  GPT  (20G)
         3       122    1  freebsd-boot  (61K)
       125     66584    2  efi  (33M)
     66709   2097152    3  freebsd-swap  (1.0G)
   2163861  10486633    4  freebsd-ufs  (5.0G)
  12650494  29292544       - free -  (14G)
```

The UFS partition on the system disk has an initial size of 5 GB. The output shows that the **da0** disk contains only one UFS partition.

> **Note**
>
> This method only works for expanding backward; if there is free space before the `freebsd-ufs` partition, this method cannot be used for expansion.

## Executing the Expansion Command

> **Warning**
>
> If using a GPT partition table, the expansion operation may corrupt the GPT partition table in virtual machine or cloud server environments. This is because virtual machines or cloud platforms may not correctly update the backup copy of the GPT partition table when resizing disks. Therefore, you need to recover the partition table of the `da0` disk first:
>
> ```sh
> # gpart recover da0
> ```
>
> After performing the above operation, the subsequent steps remain the same.

Resize partition number 4 (the `freebsd-ufs` partition) on disk da0:

```sh
# gpart resize -i 4 da0
da0p4 resized
```

The `-i` option specifies the partition number to expand. In this example, it is used to expand the `freebsd-ufs` partition.

## Expanding the File System

Use the `growfs` service to expand the file system. This operation only needs to be performed once and does not need to be repeated:

```sh
# service growfs onestart
Growing root partition to fill device
da0 recovering is not needed
da0p4 resized
growfs: no room to allocate last cylinder group; leaving 7.7MB unused
super-block backups (for fsck_ffs -b #) at:
 11544384, 12827072, 14109760, 15392448, 16675136, 17957824, 19240512, 20523200, 21805888, 23088576, 24371264,
 25653952, 26936640, 28219328, 29502016, 30784704, 32067392, 33350080, 34632768, 35915456, 37198144, 38480832
```

growfs is a FreeBSD tool for expanding UFS file systems. It utilizes the newly added partition space by adjusting cylinder groups and superblocks. You can use `growfs -N` in test mode to preview expansion parameters without actually executing the operation.

## Verifying the Expansion Result

View the disk usage of mounted file systems:

```sh
# df -hl
Filesystem         Size    Used   Avail Capacity  Mounted on
/dev/gpt/rootfs     18G    4.8G     12G    29%    /
devfs              1.0K      0B    1.0K     0%    /dev
/dev/gpt/efiesp     32M    651K     31M     2%    /boot/efi
tmpfs               20M    4.0K     20M     0%    /tmp
tmpfs               32M    156K     32M     0%    /var
```

Parameter descriptions:

* `-h`: Display in human-readable format, with units such as KB, MB, GB, etc.
* `-l`: Only show local file systems.

The output shows that the partition expansion operation is complete and the file system has been adjusted to the new size.

## References

* FreeBSD Project. ffs -- Berkeley fast file system\[EB/OL]. \[2026-04-14]. <https://man.freebsd.org/cgi/man.cgi?query=ffs&sektion=4>. UFS/FFS file system overview manual page, describing the design and implementation of the Berkeley Fast File System.
* FreeBSD Project. mount\_ufs -- mount a UFS file system\[EB/OL]. \[2026-04-14]. <https://man.freebsd.org/cgi/man.cgi?query=mount&sektion=8>. UFS file system mount command manual page.
* FreeBSD Project. growfs -- expand a UFS file system\[EB/OL]. \[2026-04-14]. <https://man.freebsd.org/cgi/man.cgi?query=growfs&sektion=8>. UFS file system expansion tool manual page.
* FreeBSD Project. fsck\_ffs -- file system consistency check and interactive repair\[EB/OL]. \[2026-04-14]. <https://man.freebsd.org/cgi/man.cgi?query=fsck_ffs&sektion=8>. UFS file system consistency check and repair tool manual page.


---

# 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.3-jie-ufs-ci-pan-kuo-zhan.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.
