Disk partitioning and filesystem management are among the most fundamental sysadmin skills. Understanding how storage is organized helps administrators troubleshoot systems, prepare new disks, recover environments, and deploy infrastructure with confidence.
In this post, I’ll walk through the basic workflow using gpart, newfs, and mount, which are essential tools for managing traditional UFS storage on FreeBSD.
Modern FreeBSD deployments often rely on ZFS, which handles storage differently through pools and datasets. However, UFS remains useful for lightweight systems, boot partitions, embedded deployments, and compatibility scenarios.
Physical disk
↓
Partition table (GPT / MBR)
↓
Partitions
↓
Filesystem (UFS)
↓
Mount point
↓
Accessible storage
Step 1 – Inspect Existing Disk Layout
Before modifying storage, inspect the current disk configuration:
gpart show
Inspect a specific disk:
gpart show da0
This displays:
- Partition scheme, such as GPT or MBR
- Existing partitions
- Free space
- Partition types
Understanding the current layout helps prevent accidental data loss.
Step 2 – Create a GPT Partition Table
For a new disk, create a GPT partition table:
gpart create -s GPT da0
What this command means:
- gpart – FreeBSD partition manager
- create – create a partition table
- -s GPT – use the GPT partition scheme
- da0 – target disk
After this command, the disk has a GPT layout but no partitions yet.
Warning: This destroys existing partition information on the disk.
Why GPT?
| Feature | MBR | GPT |
|---|---|---|
| Maximum disk size | About 2 TB | Very large disks supported |
| Partitions | 4 primary partitions | Many partitions |
| Redundancy | No | Yes |
| Checksums | No | Yes |
| UEFI support | Not native | Native |
GPT is the modern standard and should be preferred for new installations.
Step 3 – Create a UFS Partition
Create a partition using the remaining free space:
gpart add -t freebsd-ufs -a 1M da0
Typical result:
da0p1
Explanation:
- -t freebsd-ufs – partition type intended for UFS
- -a 1M – align the partition to 1 MB boundaries
1 MB alignment is recommended for SSDs, NVMe devices, modern HDDs, and virtual disks. It helps avoid misalignment penalties and is generally considered best practice.
Check the result:
gpart show da0
Example:
=> 40 41942960 da0 GPT (20G)
40 41942000 1 freebsd-ufs (20G)
Step 4 – Create the UFS Filesystem
A partition is not usable for storing files until it contains a filesystem. Create a UFS filesystem with:
newfs -U /dev/da0p1
Explanation:
- newfs – create a new filesystem
- -U – enable soft updates
- /dev/da0p1 – target partition
After running newfs, the partition is formatted and ready to be mounted.
Step 5 – Mount the Filesystem
A filesystem is not usable until it is mounted. Mounting attaches it to a directory in the system hierarchy.
Create a mount point:
mkdir -p /mnt/mydisk
Mount the filesystem:
mount /dev/da0p1 /mnt/mydisk
Verify:
mount
Example output:
/dev/da0p1 on /mnt/mydisk (ufs, local)
Test write access:
touch /mnt/mydisk/testfile
ls /mnt/mydisk
Making the Mount Persistent
Manual mounts disappear after reboot. To mount the filesystem automatically, add it to:
/etc/fstab
Example entry:
/dev/da0p1 /mnt/mydisk ufs rw 2 2
Then test the configuration:
mount -a
Understanding FreeBSD Device Names
With GPT, devices usually look like this:
/dev/da0
/dev/da0p1
/dev/da0p2
With MBR and BSD labels, devices may look like this:
/dev/da0
/dev/da0s1
/dev/da0s1a
| Device | Meaning |
|---|---|
| da0 | Physical disk |
| da0p1 | GPT partition |
| da0s1 | MBR slice |
| da0s1a | BSD partition inside an MBR slice |
Example: Legacy MBR Layout
Older FreeBSD systems often used MBR slices with BSD partitions inside them.
root@freebsd02:~ # gpart show
=> 63 16777153 da0 MBR (8.0G)
63 1 - free - (512B)
64 16777152 1 freebsd [active] (8.0G)
=> 0 16777152 da0s1 BSD (8.0G)
0 15935488 1 freebsd-ufs (7.6G)
15935488 839680 2 freebsd-swap (410M)
16775168 1984 - free - (992K)
Mounted root filesystem:
root@freebsd02:~ # mount
/dev/da0s1a on / (ufs, local, soft-updates, journaled soft-updates)
devfs on /dev (devfs)
This represents:
Physical disk
└── MBR slice
├── UFS root partition
└── swap partition
Example: GPT Layout
Modern FreeBSD systems usually use GPT directly on the disk.
root@freebsd:~ # gpart show da0
=> 40 41942960 da0 GPT (20G)
40 1024 1 freebsd-boot (512K)
1064 41942000 2 freebsd-ufs (20G)
This represents:
Physical disk
└── GPT
├── freebsd-boot
└── freebsd-ufs
The Complete Workflow
gpart show da0
gpart create -s GPT da0
gpart add -t freebsd-ufs -a 1M da0
newfs -U /dev/da0p1
mkdir -p /mnt/mydisk
mount /dev/da0p1 /mnt/mydisk
Why This Matters
Storage management remains a foundational skill for every Unix administrator. Whether you manage home labs, FreeBSD servers, virtual machines, enterprise infrastructure, or cloud environments, understanding disks, partitioning, and filesystems helps build confidence and operational independence.
FreeBSD exposes these concepts transparently, which is one reason it remains a favorite platform for learning how operating systems actually work.
No comments:
Post a Comment