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

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:

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

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

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:

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:

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

Last updated