Read This First
- A new partition table erases access to everything on the disk: there is no undo.
- Identify the device first with
lsblk -f. Device names can change between boots, so check again each time. - Never partition the disk that holds the running system unless that is exactly what you intend. To use new space on the system disk, see how to grow a partition after a disk upgrade.
- Take a snapshot or backup if the disk may hold anything of value.
Step 1: Find the Empty Disk
lsblk -f
The new disk has no partitions, no file system, and no mount point. In the examples it is /dev/vdb. Reading the output is covered in how to list disks in Linux.
GPT or MBR?
| GPT | MBR (dos) | |
|---|---|---|
| Disk size | Far beyond 2 TiB | Up to 2 TiB |
| Partitions | 128 by default | 4 primary |
| Backup copy | At the end of the disk | None |
Use GPT for every new disk. MBR only matters for old systems that boot in BIOS mode from that disk.
With parted
sudo parted /dev/vdb
(parted) mklabel gpt
(parted) mkpart data ext4 0% 100%
(parted) print
(parted) quit
parted applies each command at once; there is no separate save step. data is the partition name, and ext4 is only a type hint: no file system is created yet. The same in one line, for scripts:
sudo parted /dev/vdb --script mklabel gpt mkpart data ext4 0% 100%
For a disk that will join LVM or software RAID, add a flag: set 1 lvm on or set 1 raid on.
With fdisk
fdisk keeps every change in memory until you write it, so you can quit with q to throw everything away:
sudo fdisk /dev/vdb
Command (m for help): g
Command (m for help): n
Partition number (1-128, default 1): [Enter]
First sector (..., default 2048): [Enter]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (...): [Enter]
Command (m for help): p
Command (m for help): w
g creates an empty GPT table, n adds a partition, and pressing Enter three times accepts the defaults: number 1, from the first aligned sector to the end. p shows the result and w writes it to the disk. If fdisk finds an old signature, it asks whether to remove it; answer yes only on the disk you confirmed is unused.
Make the Kernel See It
sudo partprobe /dev/vdb
lsblk /dev/vdb
Both tools normally tell the kernel themselves. partprobe, part of the parted package, repeats the request. The new partition appears as vdb1, or nvme1n1p1 on NVMe. If the kernel refuses because the disk is in use, reboot.
Alignment
Partitions should start on a 1 MiB boundary so that writes line up with the storage underneath. Both tools handle this: parted aligns when you give the start in percent or MiB, and fdisk aligns new partitions by default, which on most disks puts the first one at sector 2048 (1 MiB). Check with:
sudo parted /dev/vdb align-check optimal 1
Two Partitions on One Disk
sudo parted /dev/vdb --script mklabel gpt \
mkpart data1 ext4 0% 50% \
mkpart data2 ext4 50% 100%
Next Steps
A partition is empty until it holds a file system. Create one with how to format a disk in Linux, then attach it with how to mount a drive in Linux. For a pool that can grow over several disks, see LVM explained.