Linux Partition Tables
Partition Tables are binary data written to a specific part of a disk drive. By reading this data according to the corresponding protocol, instructions for how to read and mount the disk drive can be programmatically determined. Generally this is the job of an operating system, not an end user or software programmer.
The modern protocol is GUID Partition Tables (GPT), part of the UEFI standard. Historically, the prevailing standard was Master Boot Record (MBR).
Note the follow-up article for setting up a file system.
Contents
gdisk
gdisk(8) is the primary utility for formatting and partitioning a drive. Calling it starts a REPL.
In order to format /dev/sde:
$ gdisk /dev/sde GPT fdisk (gdisk) version 1.0.4 Partition table scan: MBR: hybrid BSD: not present APM: not present GPT: present Found valid GPT with hybrid MBR; using GPT. Command (? for help):
Some useful commands:
Command |
Action |
o |
Create a new GPT (i.e. Delete all partitions) |
d |
Delete a partition |
n |
Create a partition |
p |
Print partition table |
l |
List known partition types |
w |
Write partition table to disk and exit |
q |
Exit |
fdisk
fdisk(8) is the predecessor to gdisk(8) and should only be used when GPT is not an option.
Accordingly, the first thing to do is to verify that a device is not using GPT. Check the 'Disklabel type' attribute shown in the printed partition table (see commands below).
$ fdisk /dev/sde Welcome to fdisk (util-linux 2.35.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help):
Some useful commands:
Command |
Action |
g |
Create a new GPT (i.e. Delete all partitions) |
o |
Create a new MBR (i.e. Delete all partitions) |
M |
Coerce partition table into MBR |
d |
Delete a partition |
n |
Create a partition |
a |
Apply the boot flag to a partition |
p |
Print partition table |
t |
Change partition type |
l |
List known partition types |
w |
Write partition table to disk and exit |
q |
Exit |