Disk Partitioning and Filesystem Management on Linux

Disk partitioning in Linux is the process of dividing a physical storage device into separate sections. These sections, called partitions, work like independent disks. Each partition can hold a specific part of the Linux system, user data, or other filesystems. Partitioning is an important step during installation, system administration, and server setup.

When you install Linux, the system needs to know where to store files, system logs, applications, and user data. These are usually separated into different partitions. For example, Linux commonly uses one partition for the root system, one for the /home directory, and one for swap memory. On servers, partitions are often separated by role—for example, one partition for web data and another for logs.

Linux also gives you the flexibility to use different filesystem types for each partition. Once partitions are created and formatted with a filesystem like ext4 or XFS, you can mount them into the Linux directory structure. After mounting, you can access the content of that partition from a folder, such as /mnt/data or /home.

To keep partitions automatically mounted every time the system boots, Linux uses a configuration file called fstab. This file tells the system which partitions to mount, where to mount them, and how to handle them.

If you are not yet familiar with the Linux directory structure, it is a good idea to first read the article Understanding the Linux File System (FHS). That guide explains how folders like /, /home, and /var work inside the Linux hierarchy.

How to Partition a Disk in Linux

Partitioning a disk in Linux can be done using command-line tools like fdisk, parted, or gdisk. These tools work with different partition table formats. fdisk is typically used for MBR (Master Boot Record), while parted and gdisk work well with GPT (GUID Partition Table), which is recommended for modern systems.

To start, you need to identify the name of the disk you want to partition. You can use the lsblk or fdisk -l command to list all available storage devices.

lsblk
View The Partitions Using Lsblk Command
View The Partitions Using Lsblk Command

This command will show all disks and their current partitions. For example, a new disk might appear as /dev/sda with no partitions under it.

To create a new partition on /dev/sda, you can use:

sudo fdisk /dev/sda
Create A New Partition
Create A New Partition

This will launch an interactive tool where you can create a new partition by typing n for new, choosing a partition number, selecting the default size, and saving changes by typing w.

Unnamed File
Unnamed File

After creating a partition, such as /dev/sda1, you must format it with a filesystem before using it.


Filesystem Types: ext4 and XFS

Linux supports several types of filesystems, but two of the most commonly used are ext4, BTRFS and XFS.

ext4 (Fourth Extended Filesystem) is the default for many distributions, including Linux Mint and Ubuntu. It is reliable, fast, and well-supported across desktop and server systems. It supports journaling, which helps recover from power failures or crashes, and it can handle files up to 16 terabytes.

XFS is a high-performance journaling filesystem used mostly in enterprise or server environments. It is particularly good for handling large files and high-speed data writing. XFS is the default in Red Hat Enterprise Linux and CentOS.

To format a partition with ext4, use the mkfs command:

sudo mkfs.ext4 /dev/sda
Formatting Filesystem With Ext4
Formatting Filesystem With Ext4

To format with XFS:

sudo mkfs.xfs /dev/sda

After formatting, the partition is ready to be mounted and used.

Mounting Filesystems in Linux

Mounting a filesystem means attaching a partition or storage device to a folder in the Linux system so that its contents can be accessed. Unlike Windows, where drives appear as separate letters (like C: or D:), Linux mounts all storage devices into the directory tree.

To mount a newly created partition manually, follow these steps. First, create a folder where you want to mount the partition:

sudo mkdir /mnt/data

Then, mount the partition to that folder:

sudo mount /dev/sdb1 /mnt/data
Mounting Partitions
Mounting Partitions

Now, you can use /mnt/data to access the contents of /dev/sdb1. If you copy files to that folder, they will be stored on the partition.

You can check mounted filesystems using the df -h command, which shows usage and mount points.

Unmounting is also possible when the filesystem is not in use:

sudo umount /mnt/data

Keep in mind that mounting done this way is temporary. Once you restart the system, the mount will be lost. To make it permanent, you need to edit the fstab file.

Configuring fstab for Persistent Mounts

The /etc/fstab file contains the list of filesystems to mount automatically at boot. Each line defines a device or partition, its mount point, the filesystem type, and options for mounting.

Before editing this file, it is recommended to get the UUID of the partition. The UUID is a unique identifier that does not change, even if device names like /dev/sdb1 change due to hardware reordering.

You can get the UUID by running:

sudo blkid

This command will show output like:

Use Blkid To Figure Out UUID
Use Blkid To Figure Out UUID

Now, open the fstab file in a text editor:

sudo nano /etc/fstab

Then add a new line at the bottom like this:

UUID=c21d14e8-093e-426c-b9e5-0f4622992a50 /mnt/data ext4 defaults 
Modify The Fstab File
Modify The Fstab File

This line tells Linux to mount the partition with that UUID to /mnt/data using the ext4 filesystem with default options. The numbers at the end are for dump and fsck settings. In most cases, you can use 0 2.

Save the file and close the editor. You can now test the configuration without rebooting:

sudo mount -a

If there are no errors, the partition is mounted as described. From now on, Linux will mount it every time the system starts.

Summary

Disk partitioning and filesystem management are important skills in Linux. Partitioning allows you to divide a physical disk into usable sections. These partitions can be formatted with different filesystems like ext4 or XFS depending on your needs. After formatting, the partitions must be mounted to make them available for use. While you can mount a filesystem manually, editing the fstab file ensures that it is mounted automatically every time the system boots.

Understanding this process helps you manage storage more effectively, especially if you are working with multiple drives or setting up a Linux server. It also gives you full control over how data is stored and accessed, which is essential in both desktop and production environments.

If you are still new to file structure in Linux, be sure to review Understanding the Linux File System (FHS) to see how mount points fit into the system. You may also find our earlier article on Linux File Permissions and Ownership useful, especially if you plan to control who can access your new mounted directories.