LPIC-1 Exam Objective 104.1: Create Partitions and Filesystems #
Introduction #
Creating partitions and filesystems is a fundamental skill for any Linux administrator. This tutorial will guide you through the process of configuring disk partitions and creating filesystems on Ubuntu/Debian and Enterprise Linux (RHEL/CentOS) systems. We will cover the management of MBR and GPT partition tables, the use of various mkfs
commands to create filesystems like ext2/ext3/ext4, XFS, VFAT, exFAT, and provide a basic overview of Btrfs.
Key Knowledge Areas #
- Manage MBR and GPT partition tables.
- Use various
mkfs
commands to create different filesystems such as ext2/ext3/ext4, XFS, VFAT, and exFAT. - Basic feature knowledge of Btrfs, including multi-device filesystems, compression, and subvolumes.
Tools and Utilities #
fdisk
gdisk
parted
mkfs
mkswap
Managing MBR and GPT Partition Tables #
MBR vs GPT #
MBR (Master Boot Record)
- Supports disks up to 2TB.
- Maximum of 4 primary partitions.
- Compatibility with older systems.
GPT (GUID Partition Table)
- Supports disks larger than 2TB.
- Allows more than 4 partitions.
- Better data integrity with CRC32 checksums.
Using fdisk
for MBR
#
Ubuntu/Debian:
sudo fdisk /dev/sdX
Enterprise Linux (RHEL/CentOS):
sudo fdisk /dev/sdX
Commands within fdisk
:
n
: Create a new partition.d
: Delete a partition.p
: Print the partition table.w
: Write changes to disk.
Using gdisk
for GPT
#
Ubuntu/Debian:
sudo gdisk /dev/sdX
Enterprise Linux (RHEL/CentOS):
sudo gdisk /dev/sdX
Commands within gdisk
:
n
: Create a new partition.d
: Delete a partition.p
: Print the partition table.w
: Write changes to disk.
Using parted
for Both MBR and GPT
#
Ubuntu/Debian and Enterprise Linux:
sudo parted /dev/sdX
Common parted
commands:
mklabel gpt
: Create a GPT partition table.mklabel msdos
: Create an MBR partition table.mkpart primary ext4 1MiB 100%
: Create a primary ext4 partition.
Creating Filesystems #
ext2/ext3/ext4 #
Ubuntu/Debian:
sudo mkfs.ext4 /dev/sdX1
Enterprise Linux (RHEL/CentOS):
sudo mkfs.ext4 /dev/sdX1
XFS #
Ubuntu/Debian:
sudo mkfs.xfs /dev/sdX1
Enterprise Linux (RHEL/CentOS):
sudo mkfs.xfs /dev/sdX1
VFAT #
Ubuntu/Debian:
sudo mkfs.vfat /dev/sdX1
Enterprise Linux (RHEL/CentOS):
sudo mkfs.vfat /dev/sdX1
exFAT #
Ubuntu/Debian:
sudo mkfs.exfat /dev/sdX1
Enterprise Linux (RHEL/CentOS):
sudo mkfs.exfat /dev/sdX1
Basic Feature Knowledge of Btrfs #
Btrfs (B-tree filesystem) is a modern filesystem with advanced features.
Creating a Btrfs Filesystem:
Ubuntu/Debian:
sudo mkfs.btrfs /dev/sdX1
Enterprise Linux (RHEL/CentOS):
sudo mkfs.btrfs /dev/sdX1
Creating a Btrfs Multi-device Filesystem:
sudo mkfs.btrfs -d raid1 /dev/sdX1 /dev/sdX2
Enabling Compression:
sudo mount -o compress=zlib /dev/sdX1 /mnt
Creating Subvolumes:
sudo btrfs subvolume create /mnt/my_subvolume
Handling Swap Partitions #
Creating a Swap Partition:
Using
fdisk
orparted
to create a partition of type82
(Linux swap).Initialize the swap partition:
Ubuntu/Debian and Enterprise Linux:
sudo mkswap /dev/sdX2
Enable the swap partition:
Ubuntu/Debian and Enterprise Linux:
sudo swapon /dev/sdX2
To make it permanent, add the following line to
/etc/fstab
:/dev/sdX2 none swap sw 0 0
Conclusion #
Creating partitions and filesystems is an essential task for managing disk storage in Linux. This tutorial covered the key tools and commands needed to manage MBR and GPT partition tables and create various filesystems on both Ubuntu/Debian and Enterprise Linux systems. With these skills, you can efficiently manage disk storage and ensure your Linux systems are well-organized and optimized for performance.