Partitioning
Related articles
Partitioning a hard drive allows one to logically divide the available space into sections that can be accessed independently of one another.
An entire hard drive may be allocated to a single partition, or one may divide the available storage space across multiple partitions. A number of scenarios require creating multiple partitions: dual- or multi-booting, for example, or maintaining a swap partition. In other cases, partitioning is used as a means of logically separating data, such as creating separate partitions for audio and video files. Common partitioning schemes are discussed in detail below.
Each partition should be formatted with to a file system type before being used.
Contents
Partition table
Partition information is stored in the partition table; today there are two main formats in use: the classic Master Boot Record, and the modern GUID Partition Table. The latter is an improved version that does away with several limitations that MBR layouts have.
Master Boot Record
MBR originally only supported up to 4 partitions. Later on extended and logical partitions were introduced to get around this limitation.
There are three types of partitions:
- Primary
- Extended
- Logical
Primary partitions can be bootable and are limited to four partitions per disk or RAID volume. If a partitioning scheme requires more than four partitions, an extended partition containing logical partitions is used. Extended partitions can be thought of as containers for logical partitions. A hard disk can contain no more than one extended partition. The extended partition as a primary partition so if the disk has an extended partition, only three additional primary partitions are possible (i.e. three primary partitions and one extended partition). The number of logical partitions residing in an extended partition is unlimited. A system that dual boots Windows will require that Windows reside in a primary partition.
See also Wikipedia:Master boot record.
GUID Partition Table
There is only one type of partition, primary, but GPT based partition doesn't have any limits on the amount of partitions that can be made.
See also Wikipedia:GUID Partition Table.
Choosing between GPT and MBR
GUID Partition Table (GPT) is an alternative, contemporary, partitioning style; it is intended to replace the old Master Boot Record (MBR) system. GPT has several advantages over MBR which has quirks back to MS-DOS times. With the recent developments to the formatting tools fdisk (MBR) and gdisk (GPT), it is equally easy to get good dependability and performance for GPT or MBR.
One should consider these to choose between GPT use MBR.
- If using GRUB legacy as the bootloader, one must use MBR.
- To dual-boot with Windows (both 32-bit and 64-bit) using Legacy BIOS, one must use MBR.
- To dual-boot with Windows 64-bit using UEFI install of BIOS, one must use GPT.
- If you are installing on older hardware, especially a laptop, consider choosing MBR because its BIOS might not support GPT.
- If none of the above apply, choose freely between GPT and MBR; since GPT is more modern, it is recommended in this case.
- It is recommended to always use GPT for UEFI boot as some UEFI firmwares do not allow UEFI-MBR boot.
Partition scheme
There are no strict rules for partitioning a hard drive, although one may follow the general guidance given below. A disk partitioning scheme is determined by various issues such as desired flexibility, speed, security, as well as the limitations imposed by available disk space. It is essentially personal preference. If you would like to dual boot PacBSD with some other operating system please see Dual booting.
Single root partition
This scheme is the simplest and should be enough for most use cases. It usually makes sense to start by considering a single / partition and then separate out others based on specific use cases like RAID, encryption, and shared media partition, etc. If planning on using ZFS this is the most plausible choice as it allows for creation of different datasets that can act as partitions.
Discrete partitions
Separating out a path as a partition allows for the choice of a different filesystem and mount options. In some cases like a media partition, they can also be shared between operating systems.
Mount points
The following mount points are possible choices for separate partitions, you can make your decision based on actual needs.
Root partition
The root directory is the top of the hierarchy, the point where the primary filesystem is mounted and from which all other filesystem stem. All files and directories appear under the root directory {ic|/}}, even if they are stored on different physical devices. The contents of the root filesystem must be adequate to boot, restore, recover, and/or repair the system. Therefore, certain directories under / are not candidates for separate partitions.
The / partition or root partition is necessary and it is the most important. The other partitions can be replaced by it.
/boot
The /boot directory contains programs and configuration file used during operating system bootstrap.
/home
The /home directory contains user-specific configuration files, caches, application data and media files.
Separating out /home allows / to be re-partitioned separately, but note that you can still reinstall PacBSD with /home untouched even if it is not separate - the other top-level directories just need to be removed, and then pacstarp can be run.
/var
The /var directory stores variable data such as spool directories and files, administrative and logging data, pacman's cache, etc. It is used, for example, for caching and logging, and hence frequently read or written. Keeping it in a separate partition avoids running out of disk space due to flunky logs, etc.
It exists to make it possible to mount {ic|/usr}} as read-only. Everything that historically went into /usr that is written to during system operation (as opposed to installation and software maintenance) must reside under /var.
/tmp
The /tmp directory stores temporary files which are usually not preserved across a system reboot. A memory-based file system is often mounted at /tmp. This can be automated using the tmpmfs-related variables of rc.conf(5) or with an entry in /etc/fstab; refer to mdmfs(8) for details.
Swap
A swap partition provides memory that can be used as virtual RAM. A swap file should be considered too, as they don't have any performance overhead compared to a partition but are much easier to resize as needed. A swap partition can potentially be shared between operating systems, but not if hibernation is used.
Partitioning tools
Partition alignment
Proper partition alignment is essential for optimal performance and longevity. This is due to the block nature of every I/O operation on the hardware level as well as file system level. The key to alignment is partitioning to (at least) the given block size, which depends on the used hardware. If the partitions are not aligned to begin at multiples of the block size, aligning the file system is a pointless exercise because everything is skewed by the start offset of the partition.
Hard disk drives
Historically, hard drives were addressed by indicating the cylinder, the head, and the sector at which data was to be read or written (also known as CHS addressing). These represented the radial position (cylinder), the axial position (drive head: platter and side), and the azimuth (sector) of the data respectively. Nowadays, with logical block addressing, the entire hard drive is addressed as one continuous stream of data and the term sector designates the smallest addressable unit.
The standard sector size is 512B, but modern high-capacity hard drives use greater value, commonly 4KiB. Using values greater than 512B is referred to as the Advanced Format.
Solid state drives
Solid state drives are based on flash memory, and thus differ significantly from hard drives. While reading remains possible in a random access fashion, erasure (hence rewriting and random writing) is possible only by whole blocks. Additionally, the erase block size (EBS) are significantly greater than regular block size, for example 128KiB vs. 4KiB, so it is necessary to align to multiples of EBS. NVMe drives should be aligned to 4KiB.
Partitioning tools
In the past, proper alignment required manual calculation and intervention when partitioning. Many of the common partition tools now handle partition alignment automatically:
- fdisk
- gdisk
- gparted
Partitioning Examples
The following example is for the simplest setup for running PacBSD.
The naming scheme for disk drives under PacBSD are: adaX for SATA drives, and daX for IDE/PATA drives, replace X with the number of your drive. Partitions (slices) use the sX naming convention for Primary and Extended partitions and sXa naming for logical partitions these are prefixed by the drive they are on, an example would be /dev/ada0s1 for the first partition on the first SATA drive in the system and /dev/ada0s2b for the second logical partition on the second partition of the first SATA drive.
MBR Partitioning
(Optional) If the disk drive that PacBSD is being installed on has a previous geom, it can be removed with the following command
# gpart destroy -F ada0
First the geom needs to be created, the geom contains information about the partition table for the disk.
# gpart create -s mbr ada0
Then create a BSD-geom, this creates an extended partition on the drive.
# gpart add -t freebsd ada0 # gpart create -s BSD ada0s1
First create the root partition, making sure assign enough space to store all data from program files and user data. Assuming the drive is a 120Gb drive, one may want to go with something like Free Space - Swap = root partition:
To create a partition for UFS use:
# gpart add -s 118G -t freebsd-ufs ada0s1
To create a partition for ZFS use:
# gpart add -s 118G -t freebsd-zfs ada0s1
Then create a partition for swap:
# gpart add -s 2g -t freebsd-swap ada0s1
GPT Partitioning
(Optional) If the disk drive that PacBSD is being installed on has a previous geom, it can be removed with the following command
# gpart destroy -F ada0
First create the geom:
# gpart create -s gpt ada0 # gpart add -s 512k -t freebsd-boot ada0
First create the root partition, making sure assign enough space to store all data from program files and user data. Assuming the drive is a 120Gb drive, one may want to go with something like Free Space - Swap = root partition:
To create a partition for UFS use:
# gpart add -s 118G -t freebsd-ufs ada0
To create a partition for ZFS use:
# gpart add -s 118G -t freebsd-zfs ada0
Then create a partition for swap:
# gpart add -s 2g -t freebsd-swap ada0