Skip to content

Linux Foundations / Understand the system underneath ยท Step 3 of 38

Lesson: Anatomy of a DiskSwitch
โ† Linux Foundations

System administration

Anatomy of a Disk

Understand disk device names, sectors, partitions and partition tables.

Before you format or mount anything, it helps to know what a disk looks like to Linux.

Disks as devices

The kernel presents each disk as a block device in /dev. Names depend on the kind of disk:

  • /dev/sda, /dev/sdb: SATA, SCSI and USB disks.
  • /dev/nvme0n1: the first namespace on the first NVMe controller.
  • /dev/vda: virtio disks in many virtual machines.

Partitions get a number on the end. /dev/sda1 is the first partition of /dev/sda. When the disk name already ends in a digit, a p goes in between, as in /dev/nvme0n1p1.

These names are assigned as devices are detected, so sdb today might be sdc after a hardware change. For anything permanent, use a UUID or label.

Sectors

A disk is addressed in sectors. The traditional size is 512 bytes. Many newer drives use 4096-byte physical sectors, often while still presenting 512-byte logical sectors. Partitions are normally aligned to 1 MiB boundaries, which suits both.

Partitions and the partition table

A partition is a contiguous slice of a disk that behaves like a smaller disk. The partition table records where each one starts and ends. There are two common formats:

  • MBR (also called dos) is older. It allows four primary partitions. To get more, one of them becomes an extended partition that holds logical partitions. With 512-byte sectors it cannot address beyond about 2 TiB.
  • GPT is the modern format, used with UEFI. It typically allows 128 partitions, has no need for extended partitions, supports very large disks and keeps a backup copy of the table at the end of the disk.

A filesystem is then created inside a partition. The layers are: disk, partition table, partition, filesystem. Tools such as LVM or software RAID can add layers in between.

Looking at your disks

lsblk shows the tree without changing anything:

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   40G  0 disk
โ”œโ”€sda1   8:1    0  512M  0 part /boot/efi
โ””โ”€sda2   8:2    0 39.5G  0 part /

fdisk -l prints the table itself and needs root:

$ sudo fdisk -l /dev/sda
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Disklabel type: gpt

The output above is shortened. The Disklabel type line says whether the disk uses gpt or dos.

Try it

Run lsblk and identify each disk and its partitions. Then run sudo fdisk -l and find the disklabel type and sector size. Both commands only read, so they are safe.

Check your understanding

Anatomy of a Disk

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.