gpart

GPart is a partitioning tool commonly used in FreeBSD operating systems. It allows users to manage disk partitions effectively, create new partitions, resize existing partitions, and perform other partition-related tasks. GPart is a command-line tool that provides a flexible and efficient way to manage storage devices in FreeBSD.

gpart add

Add a new partition to the partitioning scheme given by geom. The partition type must be specified with -t type. The partition’s location, size, and other attributes will be calculated automatically if the corresponding options are not specified.

Options

OptionDescription
-aIf specified, then the gpart utility tries to align start offset and partition size to be multiple of alignment value.
-bThe logical block address where the partition will begin. An SI unit suffix is allowed.
-fAdditional operational flags.
-iThe index in the partition table at which the new partition is to be placed. The index determines the name of the device special file used to represent the partition.
-lThe label attached to the partition. This option is only valid when used on partitioning schemes that support partition labels.
-sCreate a partition of size size. An SI unit suffix is allowed.
-tCreate a partition of type type.

gpart backup

Dump a partition table to standard output in a special format used by the restore action.

gpart bootcode

Embed bootstrap code into the partitioning scheme’s metadata on the geom (using -b bootcode) or write bootstrap code into a partition (using -p partcode and -i index).

Options

OptionDescription
-NDo not preserve the Volume Serial Number for MBR. MBR bootcode contains Volume Serial Number by default, and gpart tries to preserve it when installing new bootstrap code. This option skips preservation to help with some versions of boot0cfg that do not support Volume Serial Number.
-bEmbed bootstrap code from the file bootcode into the partitioning scheme’s metadata for geom. Not all partitioning schemes have embedded bootstrap code, so the -b bootcode option is scheme-specific in nature. The bootcode file must match the partitioning scheme’s requirements for file content and size.
-fAdditional operational flags.
-iSpecify the target partition for -p partcode.
-pWrite the bootstrap code from the file partcode into the geom partition specified by -i index. The size of the file must be smaller than the size of the partition.

gpart commit

Commit any pending changes for geom geom. All actions are committed by default and will not result in pending changes. Actions can be modified with the -f flags option so that they are not committed, but become pending. Pending changes are reflected by the geom and the gpart utility, but they are not actually written to disk. The commit action will write all pending changes to disk.

gpart create

Create a new partitioning scheme on a provider given by provider. The scheme to use must be specified with the -s scheme option.

Options

OptionDescription
-f flagsAdditional operational flags.
-n entriesThe number of entries in the partition table. Every partitioning scheme has a minimum and maximum number of entries. This option allows tables to be created with a number of entries that is within the limits. Some schemes have a maximum equal to the minimum and some schemes have a maximum large enough to be considered unlimited. By default, partition tables are created with the minimum number of entries.
-s schemeSpecify the partitioning scheme to use. The kernel must have support for a particular scheme before that scheme can be used to partition a disk.

gpart delete

Delete a partition from geom geom and further identified by the -i index option. The partition cannot be actively used by the kernel.

Options

OptionDescription
-f flagsAdditional operational flags.
-i indexSpecifies the index of the partition to be deleted.

gpart destroy

Destroy the partitioning scheme as implemented by geom geom.

Options

OptionDescription
-FForced destroying of the partition table even if it is not empty.
-f flagsAdditional operational flags.

gpart modify

Modify a partition from geom geom and further identified by the -i index option. Only the type and/or label of the partition can be modified. Not all partitioning schemes support labels and it is invalid to try to change a partition label in such cases.

Options

OptionDescription
-f flagsAdditional operational flags.
-i indexSpecifies the index of the partition to be modified.
-l labelChange the partition label to label.
-t typeChange the partition type to type.

gpart resize

Resize a partition from geom geom and further identified by the -i index option. If the new size is not specified it is automatically calculated to be the maximum available from geom.

Options

OptionDescription
-a alignmentIf specified, then the gpart utility tries to align partition size to be a multiple of the alignment value.
-f flagsAdditional operational flags.
-i indexSpecifies the index of the partition to be resized.
-s sizeSpecifies the new size of the partition, in logical blocks. An SI unit suffix is allowed.

gpart restore

Restore the partition table from a backup previously created by the backup action and read from standard input. Only the partition table is restored. This action does not affect the content of partitions. After restoring the partition table and writing bootcode if needed, user data must be restored from backup.

Options

OptionDescription
-FDestroy partition table on the given provider before doing restore.
-f flagsAdditional operational flags.
-lRestore partition labels for partitioning schemes that support them.

gpart set

Set the named attribute on the partition entry. See the section entitled “ATTRIBUTES” below for a list of available attributes.

Options

OptionDescription
-a attribSpecifies the attribute to set.
-f flagsAdditional operational flags.
-i indexSpecifies the index of the partition on which the attribute will be set.

gpart show

Show current partition information for the specified geoms, or all geoms if none are specified. The default output includes the logical starting block of each partition, the partition size in blocks, the partition index number, the partition type, and a human readable partition size. Block sizes and locations are based on the device’s Sectorsize as shown by gpart list.

Options

OptionDescription
-lFor partitioning schemes that support partition labels, print them instead of partition type.
-pShow provider names instead of partition indexes.
-rShow raw partition type instead of symbolic name.

gpart undo

Revert any pending changes for geom geom. This action is the opposite of the commit action and can be used to undo any changes that have not been committed.

gpart unset

Clear the named attribute on the partition entry. See the section entitled “ATTRIBUTES” below for a list of available attributes.

Options

OptionDescription
-a attribSpecifies the attribute to clear.
-f flagsAdditional operational flags.
-i indexSpecifies the index of the partition on which the attribute will be cleared.

gpart list

List devices

Partitioning Schemes

Several partitioning schemes are supported by the gpart utility:

Partition SchemaDescription
APMApple Partition Map, used by PowerPC Macintosh computers. Requires the GEOM_PART_APM kernel option.
BSDTraditional BSD disklabel, usually used to subdivide MBR partitions. (This scheme can also be used as the sole partitioning method, without an MBR. Partition editing tools from other operating systems often do not understand the bare disklabel partition layout, so this is sometimes called “dangerously dedicated”.) Requires the GEOM_PART_BSD kernel option.
BSD6464-bit implementation of BSD disklabel used in DragonFly to subdivide MBR or GPT partitions. Requires the GEOM_PART_BSD64 kernel option.
LDMThe Logical Disk Manager is an implementation of volume manager for Microsoft Windows NT. Requires the GEOM_PART_LDM kernel option.
GPTGUID Partition Table is used on Intel-based Macintosh computers and gradually replacing MBR on most PCs and other systems. Requires the GEOM_PART_GPT kernel option.
MBRMaster Boot Record is used on PCs and removable media. Requires the GEOM_PART_MBR kernel option. The GEOM_PART_EBR option adds support for the Extended Boot Record (EBR), which is used to define a logical partition. The GEOM_PART_EBR_COMPAT option enables backward compatibility for partition names in the EBR scheme. It also prevents any type of actions on such partitions.

Partition Types

Partition types are identified on disk by particular strings or magic values. The gpart utility uses symbolic names for common partition types so the user does not need to know these values or other details of the partitioning scheme in question. The gpart utility also allows the user to specify scheme-specific partition types for partition types that do not have symbolic names. Symbolic names currently understood and used by FreeBSD are:

Partition TypeDescription
apple-bootThe system partition dedicated to storing boot loaders on some Apple systems. The scheme-specific types are “!171” for MBR, “!Apple_Bootstrap” for APM, and “!426f6f74-0000-11aa-aa11-00306543ecac” for GPT.
bios-bootThe system partition dedicated to the second stage of the boot loader program. Usually it is used by the GRUB 2 loader for GPT partitioning schemes. The scheme-specific type is “!21686148-6449-6E6F-744E-656564454649”.
efiThe system partition for computers that use the Extensible Firmware Interface (EFI). The scheme-specific types are “!239” for MBR, and “!c12a7328-f81f-11d2-ba4b-00a0c93ec93b” for GPT.
freebsdA FreeBSD partition subdivided into filesystems with a BSD disklabel. This is a legacy partition type and should not be used for the APM or GPT schemes. The scheme-specific types are “!165” for MBR, “!FreeBSD” for APM, and “!516e7cb4-6ecf-11d6-8ff8-00022d09712b” for GPT.
freebsd-bootA FreeBSD partition dedicated to bootstrap code. The scheme-specific type is “!83bd6b9d-7f41-11dc-be0b-001560b84f0f” for GPT.
freebsd-swapA FreeBSD partition dedicated to swap space. The scheme-specific types are “!FreeBSD-swap” for APM, and “!516e7cb5-6ecf-11d6-8ff8-00022d09712b” for GPT.
freebsd-ufsA FreeBSD partition that contains a UFS or UFS2 filesystem. The scheme-specific types are “!FreeBSD-UFS” for APM, and “!516e7cb6-6ecf-11d6-8ff8-00022d09712b” for GPT.
freebsd-vinumA FreeBSD partition that contains a Vinum volume. The scheme-specific types are “!FreeBSD-Vinum” for APM, and “!516e7cb8-6ecf-11d6-8ff8-00022d09712b” for GPT.
freebsd-zfsA FreeBSD partition that contains a ZFS volume. The scheme-specific types are “!FreeBSD-ZFS” for APM, and “!516e7cba-6ecf-11d6-8ff8-00022d09712b” for GPT.
apple-apfsAn Apple macOS partition used for the Apple file system, APFS.
apple-core-storageAn Apple Mac OS X partition used by logical volume manager known as Core Storage. The scheme-specific type is “!53746f72-6167-11aa-aa11-00306543ecac” for GPT.
apple-hfsAn Apple Mac OS X partition that contains a HFS or HFS+ filesystem. The scheme-specific types are “!175” for MBR, “!Apple_HFS” for APM, and “!48465300-0000-11aa-aa11-00306543ecac” for GPT.
apple-labelAn Apple Mac OS X partition dedicated to partition metadata that describes disk device. The scheme-specific type is “!4c616265-6c00-11aa-aa11-00306543ecac” for GPT.
apple-raidAn Apple Mac OS X partition used in a software RAID configuration. The scheme-specific type is “!52414944-0000-11aa-aa11-00306543ecac” for GPT.
apple-raid-offlineAn Apple Mac OS X partition used in a software RAID configuration. The scheme-specific type is “!52414944-5f4f-11aa-aa11-00306543ecac” for GPT.
apple-tv-recoveryAn Apple Mac OS X partition used by Apple TV. The scheme-specific type is “!5265636f-7665-11aa-aa11-00306543ecac” for GPT.
apple-ufsAn Apple Mac OS X partition that contains a UFS filesystem. The scheme-specific types are “!168” for MBR, “!Apple_UNIX_SVR2” for APM, and “!55465300-0000-11aa-aa11-00306543ecac” for GPT.
apple-zfsAn Apple Mac OS X partition that contains a ZFS volume. The scheme-specific type is “!6a898cc3-1dd2-11b2-99a6-080020736631” for GPT. The same GUID is being used also for illumos/Solaris /usr partition. See “CAVEATS” section below.
dragonfly-label32A DragonFly partition subdivided into filesystems with a BSD disklabel. The scheme-specific type is “!9d087404-1ca5-11dc-8817-01301bb8a9f5” for GPT.
dragonfly-label64A DragonFly partition subdivided into filesystems with a disklabel64. The scheme-specific type is “!3d48ce54-1d16-11dc-8696-01301bb8a9f5” for GPT.
dragonfly-legacyA legacy partition type used in DragonFly. The scheme-specific type is “!bd215ab2-1d16-11dc-8696-01301bb8a9f5” for GPT.
dragonfly-ccdA DragonFly partition used with Concatenated Disk driver. The scheme-specific type is “!dbd5211b-1ca5-11dc-8817-01301bb8a9f5” for GPT.
dragonfly-hammerA DragonFly partition that contains a Hammer filesystem. The scheme-specific type is “!61dc63ac-6e38-11dc-8513-01301bb8a9f5” for GPT.
dragonfly-hammer2A DragonFly partition that contains a Hammer2 filesystem. The scheme-specific type is “!5cbb9ad1-862d-11dc-a94d-01301bb8a9f5” for GPT.
dragonfly-swapA DragonFly partition dedicated to swap space. The scheme-specific type is “!9d58fdbd-1ca5-11dc-8817-01301bb8a9f5” for GPT.
dragonfly-ufsA DragonFly partition that contains an UFS1 filesystem. The scheme-specific type is “!9d94ce7c-1ca5-11dc-8817-01301bb8a9f5” for GPT.
dragonfly-vinumA DragonFly partition used with Logical Volume Manager. The scheme-specific type is “!9dd4478f-1ca5-11dc-8817-01301bb8a9f5” for GPT.
ebrA partition subdivided into filesystems with an EBR. The scheme-specific type is “!5” for MBR.
fat16A partition that contains a FAT16 filesystem. The scheme-specific type is “!6” for MBR.
fat32A partition that contains a FAT32 filesystem. The scheme-specific type is “!11” for MBR.
fat32lbaA partition that contains a FAT32 (LBA) filesystem. The scheme-specific type is “!12” for MBR.
hifive-fsblA raw partition containing a HiFive first stage bootloader. The scheme-specific type is “!5b193300-fc78-40cd-8002-e86c45580b47” for GPT.
hifive-bblA raw partition containing a HiFive second stage bootloader. The scheme-specific type is “!2e54b353-1271-4842-806f-e436d6af6985” for GPT.
linux-dataA Linux partition that contains some filesystem with data. The scheme-specific types are “!131” for MBR and “!0fc63daf-8483-4772-8e79-3d69d8477de4” for GPT.
linux-lvmA Linux partition dedicated to Logical Volume Manager. The scheme-specific types are “!142” for MBR and “!e6d6d379-f507-44c2-a23c-238f2a3df928” for GPT.
linux-raidA Linux partition used in a software RAID configuration. The scheme-specific types are “!253” for MBR and “!a19d880f-05fc-4d3b-a006-743f0f84911e” for GPT.
linux-swapA Linux partition dedicated to swap space. The scheme-specific types are “!130” for MBR and “!0657fd6d-a4ab-43c4-84e5-0933c84b4f4f” for GPT.
mbrA partition that is sub-partitioned by a Master Boot Record (MBR). This type is known as “!024dee41-33e7-11d3-9d69-0008c781f39f” by GPT.
ms-basic-dataA basic data partition (BDP) for Microsoft operating systems. In the GPT, this type is the equivalent to partition types fat16, fat32, and ntfs in MBR. This type is used for GPT exFAT partitions. The scheme-specific type is “!ebd0a0a2-b9e5-4433-87c0-68b6b72699c7” for GPT.
ms-ldm-dataA partition that contains Logical Disk Manager (LDM) volumes. The scheme-specific types are “!66” for MBR and “!af9b60a0-1431-4f62-bc68-3311714a69ad” for GPT.
ms-ldm-metadataA partition that contains Logical Disk Manager (LDM) database. The scheme-specific type is “!5808c8aa-7e8f-42e0-85d2-e1e90434cfb3” for GPT.
netbsd-ccdA NetBSD partition used with Concatenated Disk driver. The scheme-specific type is “!2db519c4-b10f-11dc-b99b-0019d1879648” for GPT.
netbsd-cgdAn encrypted NetBSD partition. The scheme-specific type is “!2db519ec-b10f-11dc-b99b-0019d1879648” for GPT.
netbsd-ffsA NetBSD partition that contains a UFS filesystem. The scheme-specific type is “!49f48d5a-b10e-11dc-b99b-0019d1879648” for GPT.
netbsd-lfsA NetBSD partition that contains an LFS filesystem. The scheme-specific type is “!49f48d82-b10e-11dc-b99b-0019d1879648” for GPT.
netbsd-raidA NetBSD partition used in a software RAID configuration. The scheme-specific type is “!49f48daa-b10e-11dc-b99b-0019d1879648” for GPT.
netbsd-swapA NetBSD partition dedicated to swap space. The scheme-specific type is “!49f48d32-b10e-11dc-b99b-0019d1879648” for GPT.
ntfsA partition that contains a NTFS or exFAT filesystem. The scheme-specific type is “!7” for MBR.
prep-bootThe system partition dedicated to storing boot loaders on some PowerPC systems, notably those made by IBM. The scheme-specific types are “!65” for MBR and “!9e1a2d38-c612-4316-aa26-8b49521e5a8b” for GPT.
solaris-bootAn illumos/Solaris partition dedicated to boot loader. The scheme-specific type is “!6a82cb45-1dd2-11b2-99a6-080020736631” for GPT.
solaris-rootAn illumos/Solaris partition dedicated to root filesystem. The scheme-specific type is “!6a85cf4d-1dd2-11b2-99a6-080020736631” for GPT.
solaris-swapAn illumos/Solaris partition dedicated to swap. The scheme-specific type is “!6a87c46f-1dd2-11b2-99a6-080020736631” for GPT.
solaris-backupAn illumos/Solaris partition dedicated to backup. The scheme-specific type is “!6a8b642b-1dd2-11b2-99a6-080020736631” for GPT.
solaris-varAn illumos/Solaris partition dedicated to /var filesystem. The scheme-specific type is “!6a8ef2e9-1dd2-11b2-99a6-080020736631” for GPT.
solaris-homeAn illumos/Solaris partition dedicated to /home filesystem. The scheme-specific type is “!6a90ba39-1dd2-11b2-99a6-080020736631” for GPT.
solaris-altsecAn illumos/Solaris partition dedicated to alternate sector. The scheme-specific type is “!6a9283a5-1dd2-11b2-99a6-080020736631” for GPT.
solaris-reservedAn illumos/Solaris partition dedicated to reserved space. The scheme-specific type is “!6a945a3b-1dd2-11b2-99a6-080020736631” for GPT.
vmware-vmfsA partition that contains a VMware File System (VMFS). The scheme-specific types are “!251” for MBR and “!aa31e02a-400f-11db-9590-000c2911d1b8” for GPT.
vmware-vmkdiagA partition that contains a VMware diagnostic filesystem. The scheme-specific types are “!252” for MBR and “!9d275380-40ad-11db-bf97-000c2911d1b8” for GPT.
vmware-reservedA VMware reserved partition. The scheme-specific type is “!9198effc-31c0-11db-8f-78-000c2911d1b8” for GPT.
vmware-vsanhdrA partition claimed by VMware VSAN. The scheme-specific type is “!381cfccc-7288-11e0-92ee-000c2911d0b2” for GPT.

Attributes

AttributesDescription
activeThe scheme-specific attributes for EBR: active
bootmeWhen set, the gptboot stage 1 boot loader will try to boot the system from this partition. Multiple partitions can be marked with the bootme attribute.
bootonceSetting this attribute automatically sets the bootme attribute. When set, the gptboot stage 1 boot loader will try to boot the system from this partition only once. Multiple partitions can be marked with the bootonce and bootme attribute pairs.
bootfailedThis attribute should not be manually managed. It is managed by the gptboot stage 1 boot loader and the /etc/rc.d/gptboot start-up script.
lenovofixSetting this attribute overwrites the Protective MBR with a new one where the 0xee partition is the second, rather than the first record. This resolves a BIOS compatibility issue with some Lenovo models including the X220, T420, and T520, allowing them to boot from GPT partitioned disks without using EFI.
activeThe scheme-specific attributes for MBR: active

Examples

GPT

In this example, we will format ada0 with the GPT scheme and create boot, swap and root partitions. First, we need to create the partition table:

/sbin/gpart create -s GPT ada0

Next, we install a protective MBR with the first-stage bootstrap code. The protective MBR lists a single, bootable partition spanning the entire disk, thus allowing non-GPT-aware BIOSes to boot from the disk and preventing tools which do not understand the GPT scheme from considering the disk to be unformatted.

/sbin/gpart bootcode -b /boot/pmbr ada0

We then create a dedicated freebsd-boot partition to hold the secondstage boot loader, which will load the FreeBSD kernel and modules from a UFS or ZFS filesystem. This partition must be larger than the bootstrap code (either /boot/gptboot for UFS or /boot/gptzfsboot for ZFS), but smaller than 545 kB since the first-stage loader will load the entire partition into memory during boot, regardless of how much data it actually contains. We create a 472-block (236 kB) boot partition at offset 40, which is the size of the partition table (34 blocks or 17 kB) rounded up to the nearest 4 kB boundary.

/sbin/gpart add -b 40 -s 472 -t freebsd-boot ada0
/sbin/gpart bootcode -p /boot/gptboot -i 1 ada0

We now create a 4 GB swap partition at the first available offset, which is 40 + 472 = 512 blocks (256 kB).

/sbin/gpart add -s 4G -t freebsd-swap ada0

Aligning the swap partition and all subsequent partitions on a 256 kB boundary ensures optimal performance on a wide range of media, from plain old disks with 512-byte blocks, through modern “advanced format” disks with 4096-byte physical blocks, to RAID volumes with stripe sizes of up to 256 kB. Finally, we create and format an 8 GB freebsd-ufs partition for the root filesystem, leaving the rest of the device free for additional filesystems:

/sbin/gpart add -s 8G -t freebsd-ufs ada0
/sbin/newfs -Uj /dev/ada0p3

MBR

In this example, we will format ada0 with the MBR scheme and create a single partition which we subdivide using a traditional BSD disklabel. First, we create the partition table as well as a single partition 64 GB in size and an alignment of 4 kB, then we mark that partition active (bootable) and install the first-stage boot loader:

/sbin/gpart create -s MBR ada0
/sbin/gpart add -t freebsd -s 64G -a 4k ada0
/sbin/gpart set -a active -i 1 ada0
/sbin/gpart bootcode -b /boot/boot0 ada0

Next, we create a disklabel in that partition (“slice” in disklabel terminology) with room for up to 20 partitions:

/sbin/gpart create -s BSD -n 20 ada0s1

We then create an 8 GB root partition and a 4 GB swap partition:

/sbin/gpart add -t freebsd-ufs -s 8G ada0s1
/sbin/gpart add -t freebsd-swap -s 4G ada0s1

Finally, we install the appropriate boot loader for the BSD label:

/sbin/gpart bootcode -b /boot/boot ada0s1

Deleting Partitions and Destroying the Partitioning Scheme

If a Device busy error is shown when trying to destroy a partition table, remember that all of the partitions must be deleted first with the delete action. In this example, da0 has three partitions:

/sbin/gpart delete -i 3 da0
/sbin/gpart delete -i 2 da0
/sbin/gpart delete -i 1 da0
/sbin/gpart destroy da0

Rather than deleting each partition and then destroying the partitioning scheme, the -F option can be given with destroy to delete all of the partitions before destroying the partitioning scheme. This is equivalent to the previous example:

/sbin/gpart destroy -F da0

Backup and Restore

Create a backup of the partition table from da0:

/sbin/gpart backup da0 > da0.backup

Restore the partition table from the backup to da0:

/sbin/gpart restore -l da0 < /mnt/da0.backup

Clone the partition table from ada0 to ada1 and ada2:

/sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2