FreeBSD: Creating partitions and file systems

Table of Contents

Prepare the drive
Create GPT partitions and filesystems
Create MBR slices/partitions and filesystems

Create MBR slices/partitions and filesystems

by ross at 08:21:36 on November 18, 2012

Create MBR partition table

If the drive is empty:

# gpart create -s mbr ada1
ada1 created

# gpart show ada1
=>       63  976773105  ada1  MBR  (465G)
         63  976773105        - free -  (465G)

Create MBR slice for FreeBSD

# gpart add -t freebsd ada1
ada1s1 added
# gpart create -s bsd ada1s1
ada1s1 created

# gpart show ada1s1
=>        0  976773105  ada1s1  BSD  (465G)
          0  976773105          - free -  (465G)

If you need to create a slice with exact size (not all the available space) use -s flag to gpart slice creation command, i.e. "-s 100G". The same parameters applies to partitions inside slices (add command).

Create partitions

Create UFS partition:
# gpart add -s 20G -t freebsd-ufs ada1s1
ada1s1a added
# glabel label data0 /dev/ada1s1a

Create ZFS partition:
# gpart add -s 20G -t freebsd-zfs ada1s1
ada1s1b added
# glabel label tank0 /dev/ada1s1b

Here we have created two partitions and, as MBR does not support partition labels, we used glabel to assign names to the partitions. They will be available as /dev/label/data0 and /dev/label/tank0. This way you can refer to the partitions using their names not drive special files like ada1s1a which could change if you swap SATA ports.

After partition b there will be partition d, i.e. there will be no ada1s1c (or index -i 3) because partition "c" is a special entry covering entire slice and is not used for filesystem.

UFS filesystems

# newfs -U -L data0 /dev/label/data0
# mkdir /data
# mount /dev/ufs/data0 /data

This will create /dev/ufs/data0 using /dev/label/data0 with Soft Updates (-U).

Add an entry to /etc/fstab:

# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ufs/data0          /data           ufs     rw              2       2

ZFS filesystems

zpool create tank /dev/label/tank0

The filesystem will be mounted as /tank. No need for fstab entries for ZFS.


Many thanks!
-- Wellington Torrejais
Tuesday, October 6, 2015, 13:29:58