sudo parted -s /dev/vdb mklabel gptnew table (wipes the old one)
sudo parted -s /dev/vdb mkpart data ext4 1MiB 100%
sudo parted /dev/vdb unit MiB print freepartitions and free space
sudo fdisk /dev/vdbstep by step: g, n, w
sudo partprobe /dev/vdbkernel re-reads the table
Overview
A new disk is a row of empty blocks. Before it can hold files it is partitioned: a
partition table is written at the start of the disk, saying
where each partition begins and ends. The kernel shows each
partition as a device of its own: /dev/vdb1 on disk /dev/vdb, /dev/nvme0n1p1 on
NVMe, /dev/loop0p1 on a loop device. Then a filesystem is created on the
partition (mkfs) and mounted (mount).
Table
Where you meet it
GPT (gpt)
modern systems; up to 128 partitions, disks over 2 TiB
MBR (msdos)
older systems; 4 primary partitions, disks up to 2 TiB
Both tools do the same job but save differently:
fdisk keeps changes in memory and writes them only on the w command. Quitting
with q changes nothing, which makes it safe to practise.
parted applies every command at once. With -s (--script) it asks no
questions, so it suits scripts and machine setup.
The type in mkpart data ext4 is only a mark in the table. parted does not create
the filesystem: after partitioning you still need mkfs.
Options
10
parted has few options; the work is done by commands: mklabel, mkpart, print,
rm, resizepart, name. Inside fdisk you type one-letter commands; m lists
them. The full lists are in man parted and man fdisk.
Option
What it does
Example
-s--script
Never prompt — not even before wiping a partition table. dangerous
sudo parted -s /dev/vdb mklabel gpt
mklabelgpt|msdos
Write a new empty partition table; existing partitions are lost. dangerous
sudo parted -s /dev/vdb mklabel gpt
mkpartNAME FS START END
Create a partition; on MBR the first word is the type primary, not a name.
sudo parted -s /dev/vdb mkpart data ext4 1MiB 100%
print
Show the table; with free, the free space too.
sudo parted /dev/vdb unit MiB print free
-l--list
List the partition tables of disks and exit.
sudo fdisk -l /dev/vdb
g / o
Commands inside fdisk — a new empty GPT (g) or MBR (o) table. dangerous
sudo fdisk /dev/vdb
n / p / w / q
New partition, print the table, write and quit, quit without saving.
sudo fdisk /dev/vdb
unitMiB|GiB|s|%
Units for printing and reading partition boundaries.
sudo parted /dev/vdb unit MiB print
rmN
Remove partition number N from the table. dangerous
sudo parted -s /dev/vdb rm 2
partprobeDISK
Ask the kernel to re-read the disk's partition table.
sudo partprobe /dev/vdb
Nothing found. Try a shorter query.
Recipes
6
Partition an empty disk in one command
bash
lsblk /dev/vdb # right disk? empty?
sudo parted -s /dev/vdb mklabel gpt mkpart data ext4 1MiB 100%
lsblk /dev/vdb # vdb1 has appeared
The partition starts at 1 MiB: the table sits at the start of the disk, and this
offset keeps the partition aligned to the disk's blocks. 100% means up to the end.
This is a 512 MiB practice disk after the command:
text
student@ubuntu:~$ sudo parted /dev/loop0 unit MiB print free
Model: Loopback device (loopback)
Disk /dev/loop0: 512MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
0.02MiB 1.00MiB 0.98MiB Free Space
1 1.00MiB 511MiB 510MiB data
511MiB 512MiB 0.98MiB Free Space
The small free pieces at both ends hold the GPT table and its backup copy.
sudo parted /dev/vdb unit MiB print free # where the Free Space is
sudo parted -s /dev/vdb mkpart logs ext4 2048MiB 100%
No mklabel here: it would replace the table and drop the existing partitions.
The same in fdisk, step by step
text
sudo fdisk /dev/vdb
g new empty GPT table (o — MBR)
n new partition: number, start, end — Enter
p preview the result
w write and quit (q — quit without writing)
For the end you can type a size such as +10G instead of Enter.
On MBR the first word after mkpart is the partition type (primary), not a name.
The kernel does not see the new partitions
bash
sudo partprobe /dev/vdb # re-read the table
lsblk /dev/vdb
Troubleshooting
5
SymptomCause and fix
Error: /dev/vdb: unrecognised disk label
The disk has no partition table yet — the normal state of a new disk: print shows
Partition Table: unknown. Create a table: sudo parted -s /dev/vdb mklabel gpt.
mount: wrong fs type, bad option, bad superblock
You are mounting a disk or partition that has no filesystem. Partitioning creates only
partitions; mkfs creates the filesystem. More in mount.
The partition was created but there is no /dev/vdb1
The kernel has not re-read the table: the disk is busy, or the change was made behind
its back. Run sudo partprobe /dev/vdb. On a loop device, partitions appear when it is
attached with losetup -P — see loop device.
The kernel still uses the old table
fdisk wrote the table, but the kernel keeps the old one because a partition of this
disk is mounted. Unmount the disk's partitions and run partprobe; the system disk
picks up the change after a reboot.
Warning: The resulting partition is not properly aligned
The start is given in sectors or bytes that do not match the disk's blocks. Give
boundaries in MiB or percent: 1MiB, 50%.
Danger zone
2
mklabel on a partitioned disk
mklabel writes a new empty table. The old partitions vanish from it, and with them
access to the data. With -s, parted does not even ask. Before partitioning, check
the disk name and its partitions with lsblk and findmnt.
The wrong disk
/dev/vdb on one machine and /dev/vdb on another (or after a reboot) can be
different disks. Look at the size and contents in lsblk -f right before the command.
A contiguous region of a disk recorded in the partition table. The kernel shows it as a device of its own (/dev/vdb1, /dev/loop0p1) that holds a filesystem.Also appears in:
mkfs, blkid, Loop device, Filesystems: ext4, xfs, fsck and 11 more
A record at the start of a disk of where each partition begins and ends. The formats are GPT (modern systems) and MBR (msdos); fdisk or parted creates it, and blkid -p shows its type (PTTYPE).Also appears in:
blkid, mkfs
See also
lsblk — find the new disk and check the partitions afterwards.