FreeBSD: Creating partitions and file systems


by ross at 05:58:44 on November 25, 2011

Show drives in the system

# camcontrol devlist
<SAMSUNG SV0221H SJ200-16>         at scbus0 target 0 lun 0 (ada0,pass0)
<ASUS DRW-2014S1T 1.01>            at scbus2 target 0 lun 0 (cd0,pass1)
<WDC WD5000AAJS-00YFA0 12.01C02>   at scbus3 target 0 lun 0 (ada1,pass2)

The drive special file is /dev/adaN. Which N is which you can see in the command output. These are IDE/SATA drives.

To see the list of drives that use any driver, not just attached to the system through a host adapter supported by the CAM subsystem (for example, hardware raid controllers):

# sysctl kern.disks
kern.disks: mfid0

We see that this system is built using LSI MegaRAID SAS driver (mfi).

Partition schemes

FreeBSD supports many partition schemes. Two most popular are MBR and GPT. Usually you use MBR if you need to dual boot and GPT when the drive is dedicated to FreeBSD only.

MBR partitions are known as "slices" in FreeBSD world. These slices are containers for FreeBSD filesystems which are referred to as "partitions". FreeBSD can only use primary slices (not extended).

GPT doesn't use such containers and all the filesystems are referred to as "partitions".

Gpart uses numerical indexes when working with slices/partitions. But the actual entries in /dev/* are not.

If the drive is known as /dev/ada1 then the first MBR slice becomes s1 (/dev/ada1s1), the second — s2 (/dev/ada1s2) and so on (up to 4 primary slices).

First partition inside s1 slice is known as partition a (/dev/ada1s1a), second — b (/dev/ada1s1b) and so on (up to 16 entries).

GPT is simplier: first partition of the ada1 drive becomes /dev/ada1p1, second — /dev/ada1p2 and so on (up to 128 entries).


Gpart knows several partition types:

  • freebsd-boot (GPT only, 64k in size)
  • freebsd-swap
  • freebsd-ufs
  • freebsd-zfs

Pass these names as parameter -t to gpart.


This is awesome, thanks.
-- anonymous
Friday, June 8, 2012, 19:54:46