Disk partitioning and filesystem creation. You cannot use a new hard drive until you have divided it into sections (partitions) and then applied a structure (filesystem) that the operating system understands. Without these steps, your computer cannot store files reliably, and for the LFCS exam, mastering this process is essential for managing storage on Linux systems.
Jump to a section
A simple way to picture Disk Partitioning and Filesystem Creation
The office manager at a busy accounting firm is responsible for organizing all the company's financial records. She has a large, empty filing cabinet with a single, massive drawer. This drawer is chaotic - invoices, tax returns, and payroll records are jumbled together. Finding anything takes forever, and the drawer is almost full, with no room to grow. The manager decides to reorganise. First, she installs dividers to create three separate sections: one for invoices, one for tax returns, and one for payroll. These dividers are like disk partitions - they carve the single physical drawer into separate, manageable areas. Next, she labels each section and establishes a system for how papers are filed within each section: invoices by date, tax returns by client name, payroll by employee ID. This system is the filesystem - the rules that govern how data is organised, named, and stored inside each partition. The dividers (partitions) provide the boundaries, and the filing rules (filesystem) define the structure within those boundaries. Without the dividers, everything is a mess. Without the rules, even dividers cannot help you find a specific document quickly. The office manager solves the problem of chaos and limited growth by partitioning and then imposing a filing system, exactly as a Linux administrator partitions a disk and then formats each partition with a filesystem.
When you buy a new physical hard drive (also called a disk or block device), it is essentially a large, flat, empty space. Your operating system cannot just start writing files to it willy-nilly. First, you need to create partitions. A partition is a logical section of the disk. Think of it as cutting a large pizza into slices - you are dividing the total available space into separate, independent pieces. Each partition can be used for a different purpose. For example, you might have one partition for the Linux operating system itself, another for user files, and a third for swap space (a special area used as virtual memory). This separation provides several benefits: it isolates problems (a full partition for user files does not crash the system partition), it allows different filesystems on different partitions, and it enables dual-booting multiple operating systems.
To create partitions, you use a tool like fdisk or parted. In the exam, you will use commands such as fdisk /dev/sda to start partitioning the first disk. Inside fdisk, you enter an interactive menu where you can create a new partition table (which is like the table of contents for the disk), then add, delete, and resize partitions. The partition table is stored in the Master Boot Record (MBR) or GUID Partition Table (GPT). MBR is the older standard, limited to four primary partitions and a maximum disk size of 2TB. GPT is the modern standard, supporting many more partitions (up to 128 on Linux) and disks larger than 2TB. The LFCS exam assumes you know the differences and that GPT is preferred for modern systems.
Once you have created partitions, they are still unusable for data storage. You must format each partition with a filesystem. A filesystem is the method and data structure that the operating system uses to control how data is stored and retrieved on a partition. It is like deciding the rules for organising files in a library: where the card catalogue goes, how books are shelved, and what metadata (author, title, date) is recorded. Common Linux filesystems include: - ext4: The default for many Linux distributions, reliable and feature-rich. - XFS: Excellent for large files and high performance. - Btrfs: Modern, with advanced features like snapshots and compression, but more complex. - swap: Not a filesystem for storing files, but a special format used for virtual memory.
To format a partition, you use the mkfs command. For example, mkfs.ext4 /dev/sda1 creates an ext4 filesystem on the first partition of the first disk. This command writes the filesystem structure (superblock, inode tables, block groups) to the partition, preparing it to hold files. After formatting, the partition still needs to be mounted to be accessible. Mounting attaches the partition to a directory in the existing Linux filesystem tree. You mount it using mount /dev/sda1 /mnt, which makes the contents of /dev/sda1 appear under the /mnt directory. To make the mount persistent across reboots, you add an entry to the /etc/fstab file, which tells the system which partitions to mount automatically at boot time.
Why does this all matter? Without partitioning and filesystem creation, a disk is a blank slate. The process is like building a house: first, you divide the land into rooms (partitions), then you install the electrical wiring and plumbing (filesystem), and finally, you turn on the lights (mount). Linux gives you total control over this process, and the LFCS exam tests your ability to execute these tasks correctly from the command line.
Identify the Disk
Use lsblk or fdisk -l to find the disk you want to partition. For example, a new disk may appear as /dev/sdb. This step prevents accidentally partitioning the wrong disk, which could destroy data.
Create Partition Table
Run fdisk /dev/sdb, then use 'g' for GPT or 'o' for MBR. This wipes any existing partition table and sets the disk layout. GPT is preferable for modern systems and disks over 2TB.
Add Partitions
Inside fdisk, press 'n' to create a new partition. Specify size (e.g., +20G for 20GB), type (primary or extended), and location. Repeat for each partition. Press 'w' to write the table to disk and exit.
Format Partitions
Use mkfs.ext4 /dev/sdb1 for a data partition, mkswap /dev/sdb2 for swap. Formatting writes the filesystem structure (inodes, superblock) to the partition. A swap partition cannot be formatted with mkfs - it needs mkswap.
Mount and Enable
Create a mount point (e.g., mkdir /data). Mount the partition: mount /dev/sdb1 /data. For swap: swapon /dev/sdb2. Then edit /etc/fstab to add entries using UUIDs so mounts persist after reboot. Use 'mount -a' to test the fstab config.
An IT professional at a small company is setting up a new Linux web server. The server has a single 500GB SSD. The administrator needs to partition this disk to separate the operating system, application data, and logs, ensuring that a runaway log file cannot fill the entire disk and crash the server.
The step-by-step process they follow is:
First, they boot the server from a Live USB and run lsblk to identify the new disk, which appears as /dev/sda.
They execute sudo fdisk /dev/sda. Inside fdisk, they press 'g' to create a new GPT partition table, then 'n' to create a new partition. They create:
- Partition 1: 20GB, for the root filesystem (/)
- Partition 2: 100GB, for application data (/var/www)
- Partition 3: 10GB, for log files (/var/log)
- Partition 4: remaining space (approx 370GB) for user home directories (/home)
- They press 'w' to write the partition table and exit fdisk.
- Next, they format each partition with the appropriate filesystem:
- sudo mkfs.ext4 /dev/sda1 (root)
- sudo mkfs.ext4 /dev/sda2 (app data)
- sudo mkfs.ext4 /dev/sda3 (logs)
- sudo mkfs.ext4 /dev/sda4 (home)
- They create mount points (directories) for each partition: sudo mkdir /mnt/root /mnt/www /mnt/log /mnt/home.
- They mount each partition temporarily: sudo mount /dev/sda1 /mnt/root, etc.
- They copy the operating system files to /mnt/root, then use sudo blkid to get the UUID (Universally Unique Identifier) of each partition. They edit /mnt/root/etc/fstab to add permanent mount entries using the UUIDs, ensuring that the partitions mount correctly after every boot.
This setup means that if the web application generates excessive logs, only the /var/log partition fills up, and the server remains operational. The administrator also created a swap partition (optional) for virtual memory, which is formatted with mkswap and enabled with swapon. In a real business context, this kind of structured partitioning improves reliability, security (by isolating different types of data), and simplified backup strategies (you can back up only the /var/www partition).
The LFCS exam (version 1.0) objectives state that you must be able to create, format, and manage disk partitions and filesystems. The exam is performance-based, meaning you are given a live command-line environment and must complete tasks. Expect to be asked to perform specific actions using these tools:
- fdisk and parted for creating partitions.
- mkfs (with filesystem type variants like mkfs.ext4, mkfs.xfs) for formatting.
- mount and umount for attaching/detaching filesystems.
- blkid and lsblk for identifying disks and their UUIDs.
- swapon and swapoff for swapping.
- df -h and du -sh for viewing disk usage.
Common exam traps include:
Forgetting to run partprobe or rebooting after creating partitions to force the kernel to re-read the partition table. The exam might trick you into trying to format a partition before the system recognises its existence.
Confusing MBR and GPT limits: MBR supports 4 primary partitions, GPT supports up to 128. The exam may ask you to create more than 4 partitions, expecting you to use GPT or create an extended partition for MBR.
Not using the correct syntax for mkfs: mkfs.ext4 works, but mkfs -t ext4 is also valid. The exam expects you to know both.
Forgetting to add entries to /etc/fstab for persistent mounts. You will be tested on the correct format: UUID, mount point, filesystem type, options, dump, pass.
Using the wrong device name: /dev/sda is the whole disk, /dev/sda1 is the first partition. Formatting the whole disk will overwrite the partition table.
Concepts they love to test:
UUID vs. device names: Using UUIDs in fstab is recommended because device names (like /dev/sda) can change on reboot.
The difference between primary, extended, and logical partitions in MBR.
The purpose of swap: it is not a filesystem, it is formatted with mkswap and enabled with swapon.
Filesystem-specific commands: tune2fs for ext filesystem tuning, xfs_admin for XFS.
The exam will likely give you a scenario: 'You have a 1TB disk /dev/sdb. Create two partitions of 500GB each. Format the first with ext4 and the second with swap. Mount the ext4 partition to /data and enable the swap partition.' Your job is to execute the commands correctly, in order, without errors.
Partitioning divides a physical disk into logical sections using either MBR (legacy, max 4 primary partitions) or GPT (modern, up to 128 partitions).
Formatting a partition writes a filesystem structure (like ext4 or XFS) onto it, making it ready to store files.
The command mkfs.ext4 /dev/sda1 creates an ext4 filesystem; mkswap /dev/sda2 creates a swap area, not a filesystem.
Mounting attaches a formatted partition to a directory in the Linux filesystem tree; permanent mounts must be defined in /etc/fstab.
Always use UUIDs (found with blkid) in /etc/fstab instead of device names to avoid boot failures when disk order changes.
The exam is performance-based: you must run commands in a live environment, not just answer multiple-choice questions.
These come up on the exam all the time. Here's how to tell them apart.
MBR (Master Boot Record)
Supports disks up to 2TB only.
Allows a maximum of 4 primary partitions (plus extended/logical).
Legacy standard, used for older systems and BIOS boot.
GPT (GUID Partition Table)
Supports disks larger than 2TB, up to 9.4ZB.
Allows up to 128 primary partitions (no extended needed).
Modern standard, required for UEFI boot. Includes backup partition table for reliability.
ext4 Filesystem
Default for many Linux distributions, widely supported.
Good for general-purpose workloads with many small files.
Supports up to 1 exabyte in size.
XFS Filesystem
Optimised for large files and high performance.
Scales well with large storage arrays and concurrent access.
Cannot be shrunk (reduced in size) online; ext4 can be shrunk.
Primary Partition
A partition that can be bootable and is directly stored in the MBR's partition table.
Limited to 4 on an MBR disk (or up to 128 on GPT).
Cannot be nested inside another partition.
Logical Partition
A partition created inside an extended partition (only on MBR disks).
Used when you need more than 4 partitions on an MBR disk.
Not bootable by default; stored in a linked list inside the extended partition.
Device Name (e.g., /dev/sda1)
Can change if disk order changes or hardware is rearranged.
Simple and human-readable.
Unreliable for consistent mount across reboots.
UUID (Universally Unique Identifier)
Always unique and does not change, even if disk order changes.
Long and hard to remember (e.g., 1234-5678-...).
Preferred for use in /etc/fstab for reliable booting.
Mistake
Partitioning and formatting are the same thing.
Correct
Partitioning divides the disk into logical sections; formatting creates a filesystem on a partition so it can hold files. They are separate steps.
New users often see the word 'format' and think it covers both dividing the disk and preparing it, but partitioning must happen first.
Mistake
You can format an entire disk (e.g., /dev/sda) and still use it as a single partition.
Correct
Formatting a whole disk overwrites the partition table, making the disk unusable until a new partition table is created. You must create a partition (e.g., /dev/sda1) and format that instead.
People see the disk device as a single entity and assume they can use it directly, not realising the partition table is a separate structure at the start of the disk.
Mistake
All Linux filesystems are interchangeable and behave identically.
Correct
Different filesystems have different capabilities: ext4 is reliable and general-purpose, XFS handles large files well, Btrfs supports snapshots. Choosing the wrong one can impact performance or features.
Beginners think 'Linux' means one filesystem, but in reality, you choose based on workload.
Mistake
Mounting is only for temporary use; reboots clear mounts automatically.
Correct
Mounting without /etc/fstab is temporary, but adding the entry to /etc/fstab makes mounts persistent across reboots. Rebooting without the fstab entry will leave the partition unmounted and inaccessible.
Users often mount manually for testing and forget to make it permanent, then panic when the data 'disappears' after a reboot.
Mistake
Swap partitions are the same as data partitions.
Correct
Swap is a special area used as virtual memory, not for storing regular files. It is formatted with mkswap (not mkfs) and enabled with swapon.
New users see 'partition' and assume it stores files like any other, but swap has a completely different purpose and handling.
Mistake
Using /dev/sda in fstab is reliable because the device name never changes.
Correct
Device names like /dev/sda can change depending on which SATA port the disk is connected to or the order of detection. Using UUIDs or labels is more reliable.
Beginners see the device name once and think it is permanent, not realising that adding a new disk can shift the letters (sda becomes sdb, etc.).
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
MBR (Master Boot Record) is an older standard supporting disks up to 2TB and only 4 primary partitions. GPT (GUID Partition Table) is modern, supporting larger disks and up to 128 partitions. GPT is the default for new Linux installations.
You can, but it is not recommended. Writing a filesystem directly to /dev/sdb will overwrite the partition table, and the system may not recognise the disk correctly. Always create a partition (e.g., /dev/sdb1) first.
The /etc/fstab file defines how disk partitions and other storage devices should be mounted automatically at boot time. Without it, your mounts are temporary and disappear after a reboot.
Run the blkid command (e.g., blkid /dev/sdb1). It displays the UUID, which is a unique identifier used to reliably mount partitions even if device names change.
Swap is used as virtual memory, extending the system's RAM. It is not a filesystem for storing files. You create it with mkswap and enable it with swapon.
This means the partition is already mounted somewhere. Use 'mount' or 'df -h' to see where. You cannot mount the same partition in two locations simultaneously.
You've finished Disk Partitioning and Filesystem Creation. Continue through the LFCS study guide to build a complete picture of the exam.
Done with this chapter?