Block devices and partitions

Intermediate · 17 min

Find disks with lsblk and blkid, read a real GPT partition table, and create aligned partitions with fdisk, sfdisk or parted without losing data.

Before thisudev and device files

DistroTube · 17 min

Block devices and partitions

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by DistroTubeReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A block device is storage the kernel reads in fixed-size blocks: /dev/sda, /dev/nvme0n1, /dev/vda. Partitions are numbered children of it.
  • `lsblk` shows the tree of disks, partitions and what is stacked on them. `blkid` reads the signatures on each one: filesystem type, UUID, label.
  • GPT is the partition table to use: up to 128 partitions by default, disks beyond 2 TiB, a backup copy at the end of the disk, and type GUIDs per partition.
  • MBR survives only for old BIOS-only systems. A GPT disk carries a protective MBR so old tools see it as in use.
  • Start partitions on 1 MiB boundaries. fdisk and parted do this by default when you give sizes like +20G.
  • Partition editors change a table, not data, but writing the wrong disk loses everything. Check with lsblk first, and back up the table with `sfdisk -d`.

A disk is a long row of numbered blocks

To the kernel, a disk is a sequence of fixed-size sectors, numbered from 0, that can be read and written in any order. That is a block device. It knows nothing about files. Everything else in this group, partitions, filesystems, LVM, RAID and encryption, is a layer that turns that row of blocks into something more useful.

Device names come from the driver: /dev/sda for SATA, SAS and USB, /dev/nvme0n1 for NVMe, /dev/vda and /dev/xvda for virtual disks. Partitions are numbered children: /dev/sda1, /dev/nvme0n1p1. These names depend on detection order and can change between boots, which is why the udev lesson introduced stable names under /dev/disk/by-uuid/.

Seeing what is there

Two commands answer “what disks do I have and what is on them”. From the util-linux man pages, not run here:

lsblk                      # tree: disks, partitions, LVM, RAID, crypt layers, mount points
lsblk -f                   # plus filesystem type, label, UUID and usage
blkid /dev/sdb1            # signatures read from the device itself

lsblk(8) says it reads sysfs and the udev database. blkid reads signatures, magic bytes at known offsets that identify a filesystem, a RAID member, an LVM physical volume or a LUKS header. When the two disagree, the man page calls blkid the authoritative source. And always run lsblk before touching a disk: it is how you confirm that /dev/sdb really is the empty new disk and not the database.

A real partition table

I had no Linux machine, so I fetched one. The Debian project publishes raw disk images for its cloud releases. I downloaded only the first megabyte of debian-13-generic-amd64.raw, a 3 GiB image dated 23 November 2026, with an HTTP range request, and decoded it with a short Python script I wrote following the GPT layout. The script and its labels are mine, the bytes are Debian’s:

MBR signature: 55aa
MBR partition 1 type: 0xee
GPT signature: EFI PART  revision: 00010000
disk GUID: f9504205-d343-400a-89e9-3b0731c10b33
usable LBAs: 2048 .. 6291422   backup header at LBA 6291455
entries: 128 x 128 bytes starting LBA 2
#   start      end        size      type                   name
1   262144     6289407    2.9G      Linux root (x86-64)       (start % 2048 = 0)
14  2048       8191       3M        BIOS boot                 (start % 2048 = 0)
15  8192       262143     124M      EFI System                (start % 2048 = 0)

Reading it top down:

  • Sector 0 is a protective MBR, a classic MBR with one partition of type 0xee covering the disk. A tool that only understands MBR sees the disk as full and leaves it alone.
  • Sector 1 is the GPT header, EFI PART. It points to the partition entries at sector 2, 128 slots of 128 bytes.
  • A backup header sits at the last sector, 6291455. If the start of the disk is damaged, the table can be rebuilt from the end. MBR has no such copy.
  • Each partition has a type GUID. 4f68bce3-... means “Linux root for x86-64” in the Discoverable Partitions Specification, which lets systemd find the root partition without being told. c12a7328-... is the EFI System Partition from the boot lesson. The 3 MB BIOS boot partition is for GRUB on machines that boot the old way.
  • Partition numbers need not be in disk order. Here the root is partition 1 but sits after 14 and 15, at the end of the disk, where it can grow.
  • Every partition starts at a multiple of 2048 sectors.

Alignment

2048 sectors of 512 bytes is 1 MiB. Modern disks use 4 KiB physical sectors, SSDs have larger erase blocks, and RAID arrays write in stripes. A partition that starts mid-block turns each filesystem block write into two physical writes. Starting at 1 MiB boundaries lines up with all of them. fdisk(8) says partitioning follows the device’s I/O limits by default and that sizes given as +<size> with a suffix like +20G are always aligned. The man page also says to ignore old advice about cylinder and head geometry. Take the defaults and alignment is handled.

MBR versus GPT

MBR, from the 1980s, keeps the table in the first sector: four primary partitions, or three plus an extended partition holding logical ones, and 32-bit sector addresses, which with 512-byte sectors stops at 2 TiB. GPT uses 64-bit addresses, 128 entries by default, names, type GUIDs, a CRC on the header and the backup copy. Use GPT for anything new. UEFI booting is designed around it. MBR is for legacy BIOS-only machines.

Making partitions

Three tools, all in util-linux or GNU parted. Not run here:

fdisk /dev/sdb              # interactive: g = new GPT, n = new partition, t = type, w = write
sfdisk -d /dev/sdb > sdb.table     # dump the table as a script, a backup
sfdisk /dev/sdb < sdb.table        # write a table from a script
parted /dev/sdb mklabel gpt mkpart data ext4 1MiB 100%

fdisk changes nothing until you press w, so q is a safe exit. sfdisk is the scriptable one, good for provisioning and for backups. parted applies each command immediately. gdisk and sgdisk from the gptfdisk project are GPT-specific alternatives. Creating a partition table writes a new table, it does not erase data, but it hides what was there, and the filesystem you put on next does destroy it.

After changing the table of a disk in use, the kernel may keep the old view until it re-reads it. partprobe or partx -u ask it to. And wipefs lists and removes old signatures, so a disk that once held RAID or LVM does not get auto-assembled by mistake.

About the video

The embed is all of DistroTube’s “Creating Partitions In Linux Using fdisk (and other tools)”, September 2021, 17 minutes. Its description says it shows the basics of fdisk, mkswap, mkfs and related command-line tools, in the context of a command-line install. It has no chapters, so I did not check every step. It is a desktop-oriented channel, and it does not cover reading a GPT, alignment reasoning or sfdisk backups, which the lesson adds. English was judged from the channel and its English auto-caption track. Learn Linux TV’s crash course in deeper continues into formatting and mounting.

What was run: fetching the first megabyte of Debian’s official cloud image and decoding its GPT with my own Python script, on macOS. Tool behaviour is from the util-linux 2.4x man pages on man7.org and the UAPI Group’s partition specification, checked 2026-11-28.

Where this fits

A partition is still a row of blocks. Turning it into files and directories is the filesystem’s job: creating filesystems: ext4, XFS and Btrfs.

Check yourself

  1. 01A new 4 TB disk is attached as /dev/sdb. Why use GPT rather than MBR?

    MBR with 512-byte sectors cannot address beyond 2 TiB and allows only four primary partitions. GPT has neither limit and keeps a backup header at the end of the disk.

  2. 02lsblk shows sdb with no partitions, but blkid prints a filesystem on /dev/sdb itself. What does that mean?

    Someone made a filesystem on the whole disk without a partition table. It works, but other tools may treat the disk as empty, so check before partitioning it.

  3. 03Why do the partitions on a modern disk start at sector 2048?

    2048 sectors of 512 bytes is 1 MiB. Starting there keeps every partition aligned to the physical blocks of 4K-sector disks, SSDs and RAID stripes, and leaves room for the GPT.

  4. 04How do you save a disk's partition table before editing it, and restore it?

    `sfdisk -d /dev/sdb > sdb.table` saves it in sfdisk's script format. `sfdisk /dev/sdb < sdb.table` writes it back.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark