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
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.
Worth carrying in
- fdisk /dev/sda
- Partition editor.
gdiskfor 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 ext4andmke2fs -t ext4are the same thing. - mke2fs
- The program behind
mkfs.ext2,mkfs.ext3andmkfs.ext4— they are all it, under different names. - mkswap /dev/sda2
- Prepare swap.
swaponactivates it,swapoffreleases 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
- Four primary partitions is an MBR limit, worked around with an extended partition. GPT has no such rule.
- Btrfs takes several devices at mkfs time and mirrors across them itself. Every other
mkfs.*here takes one device and expects RAID to be somebody else's job. - XFS can be grown, never shrunk. That asymmetry is asked directly.
mkfsdestroys what was on the partition. A question about "preparing an existing partition without data loss" is not asking for mkfs.
- 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
- A new disk /dev/sdb has no partition table at all. Which command writes an empty GPT partition table onto it without dropping you into an interactive editor? machine-checked
- You need the partition /dev/sdc1 on a USB stick to carry a FAT32 filesystem so that Windows machines can read and write it. Which command creates it? machine-checked
- You have just run `mkswap /dev/sdb2`. Which command makes the kernel start using that swap area immediately, without a reboot? machine-checked
- Type the complete command that creates an ext4 filesystem on the partition /dev/sdb1, using default options. machine-checked
- The partition /dev/sdb2 has been set aside for paging. Type the command that prepares it as a swap area (it does not activate it). machine-checked
- A 4 TB disk /dev/sdb carries an MBR partition table with data you must keep, and you need it converted to GPT in place so that the whole disk becomes usable. Which interactive tool is built to do that conversion? machine-checked
- You partition a 4 TB disk with an MBR partition table and find that, however you arrange the partitions, about half the disk cannot be addressed. Which property of the MBR scheme causes that ceiling? machine-checked
- Two empty disks, /dev/sdc and /dev/sdd, are to hold a single Btrfs filesystem that keeps a mirrored copy of both data and metadata across the pair, using Btrfs's own multi-device support. Which command creates it? machine-checked
- You want a quick inventory of every disk the system can see, with its size and partition table, printed to the terminal without entering any interactive editor. Type the complete fdisk command line, including its option, that does this. machine-checked
- Which THREE of the following tools create or modify a partition table on a disk? (Choose three.) machine-checked
- A server has had swap areas added to it over several years. You need to see which of them the running kernel is actually paging to, and at what priority. Which command reports that? machine-checked
- `mkfs.ext3 /dev/sdb1` builds an ext3 filesystem on that partition. Select the TWO commands that build exactly the same filesystem there. machine-checked
Practise Partitions and filesystems
The rest of objective 104
- Partitions and filesystems — you are here
- Keeping filesystems intact
- Mounting and unmounting filesystems
- File permissions, ownership and disk quotas
- Hard links and symbolic links
- Finding files and where they belong