Skip to content
Visual explainer 3h to learn 4 steps

Disks & partitions

Inspect block devices and create GPT partitions with parted or fdisk.

By Invicly Tech, , in Linux Administration (RHCSA-style). About 11 minutes to read.

Topic 18 of 42

In short

Before a disk can hold file systems or LVM it is usually divided into partitions recorded in a partition table. GPT is the modern standard and supports large disks and many partitions; MBR is the legacy format. lsblk shows the layout and fdisk, gdisk or parted change it.

Explained simply

A new disk is like an empty warehouse floor. Before you store anything, you usually paint lines on the floor to mark separate areas. Those areas are partitions, and the small map that says where each area starts and ends is the partition table.

Linux shows every disk as a file in /dev. A SATA or SCSI disk is /dev/sda, a virtual disk in KVM is often /dev/vda, and an NVMe disk is /dev/nvme0n1. Partitions add a number: /dev/sda1, /dev/vdb2, or /dev/nvme0n1p1 (NVMe puts a p before the number).

There are two kinds of partition table. MBR is the old one from the 1980s. GPT is the modern one and is what you should use on new disks. Tools like fdisk, gdisk and parted write the table, and lsblk shows you the result.

Partitioning is one of the few admin tasks where a typo can wipe real data in a second. So the habit to build is simple: look first with lsblk, check the size and the device name twice, and only then write.

Press Play on a diagram to walk through it one step at a time.

CompareMBR vs GPT
MBR (msdos)
  • Disks up to 2 TiB
  • 4 primary partitions, or extended plus logical
  • Single copy of the table
  • Legacy BIOS boot
GPT
  • Disks far larger than 2 TiB
  • 128 partitions by default
  • Backup table at the end of the disk
  • Required for UEFI boot
MapHow Linux names disks and partitions
/dev
  • SATA, SAS, USB, SCSI
    • /dev/sda is the first disk
    • /dev/sda1 is its first partition
  • KVM virtio disks
    • /dev/vda, /dev/vdb
    • /dev/vdb1, /dev/vdb2
  • NVMe
    • /dev/nvme0n1: controller 0, namespace 1
    • /dev/nvme0n1p1: partition 1
  • Stable names
    • /dev/disk/by-id (model and serial)
    • /dev/disk/by-uuid
    • /dev/disk/by-partuuid
FlowSafe routine for partitioning a new disk
  1. 1
    Identify

    lsblk -f: right size, no mount points

  2. 2
    Wipe old labels

    wipefs -a only if it is truly unused

  3. 3
    Create table

    GPT with fdisk g or parted mklabel gpt

  4. 4
    Add partitions

    Set sizes and types

  5. 5
    Reload

    partprobe, then udevadm settle

  6. 6
    Verify

    lsblk and blkid show the new layout

In depth

What is actually written on the disk

An MBR disk keeps everything in the very first 512-byte sector: boot code, a 64-byte table with room for four 16-byte entries, and the signature 55 AA. Each entry stores a start sector and a length as 32-bit numbers, which is where the 2 TiB limit comes from on disks with 512-byte sectors. To get more than four partitions, one entry becomes an extended partition that holds logical partitions, numbered from 5.

GPT starts with a protective MBR in sector 0 so old tools see the disk as in use. Sector 1 holds the GPT header, followed by the partition entries (128 entries of 128 bytes by default). A full copy of the header and entries sits at the end of the disk, and both carry CRC32 checksums, so damage to one copy can be detected and repaired from the other.

  • Every GPT partition has its own unique PARTUUID
  • Type GUIDs mark a partition as Linux data, LVM, swap or EFI
  • gdisk can rebuild a damaged main table from the backup
LayersLayout of a GPT disk, start to end
  1. 1
    Sector 0: protective MBR

    Tells old tools the whole disk is in use

  2. 2
    Sector 1: GPT header

    Disk GUID, table location, checksums

  3. 3
    Partition entries

    128 slots of 128 bytes each by default

  4. 4
    Partitions

    Usually start at 1 MiB for alignment

  5. 5
    Backup entries and header

    Last sectors of the disk

Reading lsblk and blkid properly

lsblk reads information the kernel already has, so it is safe and needs no root. The TYPE column tells disks, partitions, LVM volumes (lvm) and optical drives (rom) apart. RM marks removable devices and RO read-only ones. lsblk -f adds FSTYPE, LABEL, UUID and the mount points, and lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS lets you pick columns.

blkid looks at the content of each device and prints signatures it finds: TYPE (xfs, ext4, swap, LVM2_member), UUID, LABEL and, for GPT partitions, PARTUUID and PARTLABEL. The same IDs appear as symbolic links under /dev/disk/by-uuid, /dev/disk/by-partuuid and /dev/disk/by-id. Those links stay stable when sda and sdb swap names between boots, which happens more often than people expect on servers with several controllers.

  • lsblk -d lists whole disks only
  • lsblk -p prints full /dev paths
  • ls -l /dev/disk/by-id maps serial numbers to device names

fdisk, gdisk and parted: which and when

fdisk from util-linux handles both MBR and GPT today. It is interactive and nothing touches the disk until you press w, so q is always a safe way out. Key letters: g creates a new empty GPT table, o a new MBR table, n adds a partition, t changes its type, p prints, w writes. Sizes can be typed as +2G.

gdisk is GPT only and uses two-to-four digit type codes such as 8300 (Linux filesystem), 8e00 (Linux LVM) and 8200 (swap). parted works on both tables and accepts the whole job on one command line, which makes it the easiest choice for scripts. Be careful: parted applies each command immediately, with no final write step.

Always leave the first 1 MiB free. Starting partitions at 1 MiB (sector 2048) keeps them aligned to the internal block sizes of SSDs and RAID arrays; all three tools do this by default.

Telling the kernel, and cleaning up

Writing a new table changes the disk, but the kernel keeps its own in-memory copy. If a partition on that disk is in use, fdisk may warn that re-reading failed. partprobe /dev/vdb (from the parted package) or partx -u /dev/vdb asks the kernel to load the new layout, and udevadm settle waits until udev has created the /dev entries. If the disk holds your root file system, a reboot may be the only safe way.

To reuse a disk that held something before, remove old signatures first with wipefs. wipefs /dev/vdb lists them and wipefs -a /dev/vdb erases them, including old RAID or LVM labels that would otherwise confuse tools later. Before you change a working disk, save its table: sfdisk -d /dev/vdb > vdb.table can be restored with sfdisk /dev/vdb < vdb.table.

  • partprobe or partx -u: reload partitions
  • udevadm settle: wait for device links
  • wipefs -a: erase old signatures
  • sfdisk -d: back up the table as text

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    List devices with lsblk and blkid~45m
  2. 2
    Compare MBR and GPT~45m
  3. 3
    Create partitions with fdisk or parted~45m
  4. 4
    Inform the kernel with partprobe~45m

Key points

  • lsblk -f shows devices, partitions, file systems and mount points together.
  • Partition types matter: Linux, Linux LVM and Linux swap.
  • Run partprobe or udevadm settle so the kernel sees new partitions.
  • Double-check the device name; partitioning the wrong disk destroys data.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
lsblk -f
sudo parted /dev/vdb mklabel gpt
sudo parted /dev/vdb mkpart data xfs 1MiB 2GiB
sudo parted /dev/vdb mkpart lvm 2GiB 6GiB set 2 lvm on
sudo parted /dev/vdb mkpart swap linux-swap 6GiB 7GiB
sudo partprobe /dev/vdb && lsblk /dev/vdb

A GPT disk with data, LVM and swap partitions in one go.

Two partitions with fdisk, step by step

A new 10 GiB disk /dev/vdb needs a 4 GiB Linux partition and a 2 GiB swap partition. Step 1: confirm with lsblk that vdb has no partitions and no mount points. Step 2: open fdisk and press g for a GPT table. Step 3: n, accept number 1 and the default first sector, then type +4G. Step 4: n again for partition 2 with +2G, then t, choose partition 2 and enter the swap type (type L to list the names if you are unsure). Step 5: p to review, then w to write. Step 6: reload and check.

bash
lsblk /dev/vdb
sudo fdisk /dev/vdb
# g          new GPT table
# n, 1, Enter, +4G
# n, 2, Enter, +2G
# t, 2, swap
# p          review
# w          write and exit
sudo partprobe /dev/vdb && sudo udevadm settle
lsblk -o NAME,SIZE,TYPE,PARTTYPENAME /dev/vdb

Back up a partition table and copy it to a twin disk

You are building a mirror and need /dev/vdc partitioned exactly like /dev/vdb. Step 1: dump the table of vdb as text with sfdisk -d and keep the file as a backup too. Step 2: feed the dump to vdc. Because GPT IDs must be unique, step 3 gives vdc a fresh disk GUID and new partition GUIDs with sgdisk -G (from the gdisk package). Step 4: reload and compare both disks.

bash
sudo sfdisk -d /dev/vdb > vdb.table
sudo sfdisk /dev/vdc < vdb.table
sudo sgdisk -G /dev/vdc
sudo partprobe /dev/vdc
lsblk -o NAME,SIZE,PARTTYPENAME,PARTUUID /dev/vdb /dev/vdc

Quick reference

  • lsblk -f shows devices, partitions, file system types, UUIDs and mount points
  • sudo blkid /dev/vdb1 prints TYPE, UUID, PARTUUID and LABEL of one device
  • fdisk keys: g new GPT, o new MBR, n new, t type, p print, w write, q quit without saving
  • sudo parted /dev/vdb print free shows the table and the unused gaps
  • sudo partprobe /dev/vdb or sudo partx -u /dev/vdb makes the kernel re-read partitions
  • sudo wipefs -a /dev/vdb erases old file system, RAID and LVM signatures
  • sudo sfdisk -d /dev/vdb > vdb.table saves the partition table as text
  • MBR: max 2 TiB and 4 primary partitions; GPT: 128 partitions by default, needed for UEFI boot

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Where does GPT keep its backup copy of the partition table?

Question 2

2You type n, set sizes and type in fdisk, then press q. What happens to the disk?

Question 3

3Which name is the second partition on the first NVMe disk?

Question 4

4Why do partitioning tools start the first partition at 1 MiB?

Question 5

5fdisk wrote a new table but lsblk still shows the old partitions. What should you try first?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List only the whole disks on your machine with their size, model and whether they are rotational (HDD) or not (SSD).

  2. Exercise 2medium

    On a spare disk /dev/vdb, create a GPT table with one 1 GiB partition named data and one LVM partition using the rest, all in one non-interactive parted command.

  3. Exercise 3hard

    Write a small script that refuses to partition a disk if any of its partitions are mounted or it is not exactly the size you expect, and otherwise creates a single GPT partition.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Should I use MBR or GPT for a new disk?
Use GPT unless an old BIOS-only system or tool forces MBR. GPT has no 2 TiB limit, allows many partitions and keeps a backup table.
Do I need partitions at all if I use LVM?
No. pvcreate works on a whole disk such as /dev/vdc. Many admins still add one partition of type Linux LVM so that other tools clearly see the disk is in use.
Is fdisk safe to use on a disk with data?
It is safe to look: fdisk -l and p only print. Changes are kept in memory until you press w, but deleting or moving a partition that holds data and then writing will lose that data.
What is the EFI System Partition?
A small FAT32 partition, usually mounted at /boot/efi, that UEFI firmware reads boot loaders from. You need one on the boot disk of any UEFI machine.

Go deeper

ShareXLinkedInWhatsApp