Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Storage and Filesystems

Disks, Partitions and lsblk: MBR, GPT and Device Names

Identify block devices with lsblk and blkid, understand MBR and GPT partition tables, create partitions with fdisk or parted and avoid destroying the wrong disk.

Before a disk can hold files it needs three layers: a partition table that divides the disk, a filesystem that organizes each partition, and a mount point that attaches it to the directory tree. This lesson covers the first layer, identifying devices and partitioning them, which is also where the most irreversible mistakes happen.

Device names

Disks appear as files in /dev.

Name Meaning
/dev/sda, /dev/sdb SATA, SAS and USB disks (letters by detection order)
/dev/sda1 First partition on sda
/dev/nvme0n1 First NVMe drive; partitions are nvme0n1p1
/dev/vda Virtual disk in a KVM or cloud guest
/dev/mapper/..., /dev/vg0/lv Device-mapper devices, such as LVM

Letters can change between boots when disks are added or reordered. For that reason configuration files should refer to UUIDs or labels, not sdb1.

Looking at what exists

Terminal
lsblk
lsblk -f                    # with filesystem type, label, UUID, mount point
lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS
sudo blkid                  # UUIDs and types
sudo fdisk -l               # partition tables
df -h                       # mounted filesystem usage
findmnt

lsblk draws a tree: disks, their partitions and what is mounted. Run it before and after attaching a new disk, and the new device is the one that appeared.

Partitioning tools act on the device you name. Confirm size and model with lsblk and make sure the device is the new, empty one. A wrong letter wipes the wrong disk.

MBR and GPT

Property MBR (msdos) GPT
Max disk size 2 TiB Practically unlimited
Primary partitions 4 (or 3 plus extended) 128 by default
Firmware BIOS (also some UEFI) UEFI (also BIOS with a BIOS boot partition)
Redundancy None Backup table at the end of the disk

Use GPT for new disks. Use MBR only for legacy systems.

Partitioning with fdisk

fdisk is interactive. Changes stay in memory until you write them with w.

Terminal
sudo fdisk /dev/sdb
# g   create a new GPT table
# n   new partition (accept defaults, set +20G for 20 GiB)
# t   change type (e.g. Linux filesystem, Linux LVM, EFI System)
# p   print table
# w   write and exit      q   quit without saving

parted handles large disks and scripting:

Terminal
sudo parted /dev/sdb --script mklabel gpt mkpart data ext4 1MiB 100%
sudo parted /dev/sdb print

Then tell the kernel to re-read the table if needed:

Terminal
sudo partprobe /dev/sdb
lsblk /dev/sdb

Partitions should start on 1 MiB boundaries, which both tools do by default, for good performance on modern disks and SSDs.

Layers at a glance

flowchart TD
    A["Physical disk /dev/sdb"] --> B["Partition table GPT"]
    B --> C["Partition /dev/sdb1"]
    C --> D["Filesystem ext4 or XFS"]
    D --> E["Mounted at /data"]

Disk, table, partition, filesystem, mount.

Sizes: GB versus GiB

Disk vendors count in powers of ten (1 GB = 10^9 bytes) while tools often use powers of two (1 GiB = 2^30 bytes). A "1 TB" disk is about 931 GiB, which is not a defect. In lsblk, sizes use binary units by default; lsblk -b prints exact bytes.

Swap

Swap space gives the kernel somewhere to move rarely used memory. It can be a partition or a file.

Terminal
sudo mkswap /dev/sdb2
sudo swapon /dev/sdb2
swapon --show
free -h

Make it permanent with an /etc/fstab entry (next lesson).

A stand-in: sector arithmetic

Partition tables record sizes in 512-byte sectors, and the first partition usually starts at sector 2048 (1 MiB). This model converts between sectors and sizes.

Python Stand-in: sectors to sizes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: planning a partition table

This model lays out partitions one after another on a made-up disk and checks that the plan fits.

Python Stand-in: does the plan fit the disk?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Partitioning the wrong disk because device letters changed.
  • Using MBR on disks larger than 2 TiB.
  • Referring to /dev/sdb1 in fstab instead of a UUID.
  • Forgetting to write changes (w) or to re-read the table.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command shows a tree of disks, partitions and mount points?

    lsblk lists block devices with their partitions and mounts.
  2. 2. Why prefer GPT over MBR for new disks?

    MBR is limited to 2 TiB and four primary partitions.
  3. 3. Which name format is used by the first NVMe drive's first partition?

    NVMe partitions add a p before the partition number.
  4. 4. Why use UUIDs in configuration instead of /dev/sdb1?

    UUIDs stay with the filesystem even if device order changes.

Summary

  • Layers: disk, partition table, partition, filesystem, mount.
  • Use lsblk, blkid, fdisk -l to identify devices before touching them.
  • Use GPT for new disks; align to 1 MiB.
  • Reference filesystems by UUID or label.

Next: Filesystems, mkfs, mount and fstab