Partitions and filesystems

Turning a raw disk into something usable: partitioning it with MBR or GPT, putting a filesystem on the partitions, and preparing swap.

Lesson 1 of 6 in objective 104. Devices, Linux filesystems, filesystem hierarchy standard, part of LPIC-1 Exam 101-500.

Two partition schemes, and where the four-partition rule comes from. MBR — Primary partitions: Four; Largest disk: About 2 TB; Backup of the table: None; To get more: An extended partition holding logical ones. GPT — Primary partitions: 128 by default; Largest disk: Far beyond any disk; Backup of the table: Yes, at the far end; To get more: Nothing — just add one MBR GPT Primary partitions Four 128 by default Largest disk About 2 TB Far beyond any disk Backup of the table None Yes, at the far end To get more An extended partition holding logical ones Nothing — just add one
Two partition schemes, and where the four-partition rule comes from.

Two partition schemes

The MBR scheme keeps its table in the first sector and allows four primary partitions; getting more means turning one of them into an extended partition that contains logical ones. It cannot address disks beyond 2 TB. GPT replaces it with a much larger table, keeps a backup copy at the end of the disk, and has no primary/extended distinction — which is why every modern install uses it, and why questions about the four-partition limit are always about MBR.

fdisk edits MBR tables (and, in current versions, GPT too), gdisk is the GPT-specific equivalent, and parted handles both and can also resize. A partition carries a type id: 83 is a Linux filesystem, 82 is Linux swap, and on GPT there is an EFI system partition type that the firmware looks for. Changing a type id does not change what is on the partition — it is a label, and a wrong one merely misleads.

fdisk -l is the non-interactive half of the same tool and the quickest inventory of what a machine has: given -l, or the long form --list, it prints the partition table of every disk it can find and exits without ever offering its editing prompt. Naming a disk restricts the report to it. Because it reads the tables by opening the block devices directly, an ordinary user gets nothing back at all, which is why it is normally run as sudo fdisk -l and why "it printed nothing" is a permissions answer rather than an empty machine.

Filesystems, and picking one

mkfs creates a filesystem, dispatching to a type-specific tool: mkfs.ext4, mkfs.xfs, mkfs.vfat, or mkfs -t ext4 spelled the other way. ext4 is the general-purpose default across most distributions; ext3 is its predecessor and ext2 the version before journaling, which is why ext2 is still occasionally chosen for small /boot partitions and USB sticks. XFS is the default on Red Hat family systems and is strong on large files; it can be grown but not shrunk. Btrfs adds snapshots and its own volume management, and that second half changes how it is created: mkfs.btrfs accepts a LIST of devices and stripes or mirrors across them itself, with -d choosing the profile for data and -m the profile for metadata, so mkfs.btrfs -d raid1 -m raid1 /dev/sdc /dev/sdd builds a mirrored filesystem with no md array or LVM layer beneath it. vfat exists for interoperability, which is why the EFI system partition uses it, and mkfs.fat (formerly mkfs.vfat) chooses FAT12, FAT16 or FAT32 from the partition size unless you say otherwise.

Behind all three ext filesystems there is one program, and it is worth knowing by name because a question will use it instead of the friendly spelling. mke2fs is the real tool; mkfs.ext2, mkfs.ext3 and mkfs.ext4 are the same binary deciding what to build from the name it was called by, and mke2fs -t ext4 /dev/sdb1 is exactly mkfs.ext4 /dev/sdb1. mkfs itself is only a front end that appends the type to its own name and runs whatever it finds, which is why a filesystem with no mkfs.<type> installed fails with "command not found" rather than an error about the filesystem.

Swap is prepared with mkswap and enabled with swapon; swapon -s or /proc/swaps shows what is active, and an entry in /etc/fstab makes it come back after a reboot. A swap FILE works as well as a partition and is created with dd or fallocate, then given to mkswap the same way.

Three spellings of one program, and the front end that builds nothing itself. Left column, The command you type; right column, The program behind the name. mkfs.ext2, mkfs.ext3 and mkfs.ext4 all point at mke2fs (One binary, and the name it was called by picks the type). mkfs -t ext4 points at mkfs.ext4 (mkfs appends the type to its own name. No such program, command not found), which in turn reaches mke2fs, under another name (Whatever was on the partition is gone). The command you type The program behind the name mkfs.ext2 mkfs.ext3 mkfs.ext4 mke2fs One binary, and the name it was called by picks the type mkfs -t ext4 mkfs.ext4 mkfs appends the type to its own name. No such program, command not found mke2fs, under another name Whatever was on the partition is gone
Three spellings of one program, and the front end that builds nothing itself.

Worth carrying in

fdisk /dev/sda
Partition editor. gdisk for GPT specifically, parted for both.
type 83 / 82
Linux filesystem and Linux swap partition type ids on MBR.
mkfs.ext4 /dev/sda1
Create a filesystem. mkfs -t ext4 and mke2fs -t ext4 are the same thing.
mke2fs
The program behind mkfs.ext2, mkfs.ext3 and mkfs.ext4 — they are all it, under different names.
mkswap /dev/sda2
Prepare swap. swapon activates it, swapoff releases it.
lsblk
The block device tree, with sizes and mount points.
blkid
UUID, LABEL and filesystem type of each block device.
fdisk -l
Print every partition table and exit. Needs the privilege to open the devices, so usually sudo.
mkfs.btrfs -d raid1 -m raid1
Btrfs spans devices itself: -d sets the data profile, -m the metadata one. No md or LVM underneath.

What the exam does with this

Objective
104. Devices, Linux filesystems, filesystem hierarchy standard
Share of the exam
25% (the whole objective)
Questions in this lesson
12
Signed for by a person
0

Partly checked. None of the 12 questions here has been read against the cited source by a person. 12 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Partitions and filesystems

Questions in this lesson

Practise Partitions and filesystems

The rest of objective 104