Master Linux Disk Partitioning and Mounting: A Practical Step‑by‑Step Guide
This guide walks Linux operators through the fundamentals of disk partitioning, explains MBR and GPT partition tables, demonstrates the use of fdisk, parted and gdisk, shows how to create and format filesystems, configure mounting options and fstab, manage LVM volumes, and provides real‑world case studies with commands, examples, and best‑practice recommendations.
Background and Scenarios
Disk partitioning and mounting are fundamental yet error‑prone tasks in Linux operations. Typical scenarios include initializing a new server, mounting data disks, expanding full disks, and replacing failed disks.
Basic Concepts of Disk Partitioning
Disk and Partition Relationship
Linux treats everything as a file, including block devices. Common device files are: /dev/sda – first SCSI/SATA disk /dev/sdb – second SCSI/SATA disk /dev/nvme0n1 – first NVMe disk /dev/vda – first virtual disk (KVM)
Partitions are logical regions on a disk, numbered from 1 (e.g., /dev/sda1, /dev/sda2).
Partition Table Types
MBR (Master Boot Record)
Stored in the first 512‑byte sector
Maximum disk size 2 TB
Supports up to 4 primary partitions (or 3 primary + 1 extended)
Legacy compatibility
GPT (GUID Partition Table)
Part of the UEFI specification
Supports disks up to 18 EB (practically 128 partitions in Linux)
Each partition has a unique GUID
Backup table and CRC checks improve reliability
Requires UEFI boot or BIOS+GPT compatibility mode
Selection guidance:
Disk < 2 TB – MBR or GPT
Disk > 2 TB – GPT is mandatory
New partitions – prefer GPT
Legacy systems – consider MBR
Partition Type Codes (MBR)
83 – Linux (regular)
82 – Linux swap
8e – Linux LVM
fd – Linux RAID
Partition Type GUIDs (GPT)
28732AC1‑… – Linux filesystem
0657FD6D‑… – Linux swap
E6D6D379‑… – Linux LVM
A2D3D0F5‑… – Linux RAID
Partitioning Tools
fdisk (MBR‑focused)
# View partition table
fdisk -l /dev/sda
# Interactive mode
fdisk /dev/sdb
# Inside fdisk:
# p – print table
# n – new partition
# d – delete partition
# t – change type
# w – write and exit
# q – quit without saving
# m – helpExample: create a 10 GB primary partition
# fdisk /dev/sdb
Command (m for help): n
Partition type: p (primary)
Partition number (1‑4, default 1): 1
First sector (2048‑…): 2048
Last sector, +size{K,M,G,T,P} (default): +10G
Command (m for help): wparted (MBR & GPT)
# Print partition table
parted /dev/sdb print
# Create GPT label
parted /dev/sdb mklabel gpt
# Create a full‑size XFS partition
parted /dev/sdb mkpart primary xfs 0% 100%gdisk (GPT‑only)
# View GPT table
gdisk -l /dev/sdb
# Interactive mode
gdisk /dev/sdb
# Inside gdisk:
# p – print table
# n – new partition
# d – delete partition
# t – change type
# w – write changes
# q – quit
# Example: 50 GB Linux filesystem partition
Command (m for help): n
Partition number (1‑128, default 1): 1
First sector (34‑…): 2048
Last sector, +size{K,M,G,T,P} (default): +50G
Hex code or GUID (Enter = 8300): 8300
Command (m for help): wTool Selection Recommendations
MBR (< 2 TB) – fdisk (simple)
GPT (> 2 TB) – parted or gdisk (modern, good compatibility)
Scripting – parted (non‑interactive mode)
Repairing damaged tables – fdisk or parted (cannot fully repair GPT)
LVM preparation – fdisk or parted (create LVM‑type partition)
Filesystem Creation and Formatting
Common Filesystems
ext4 – stable, general‑purpose, ideal for system disks
xfs – high performance, good for large files, databases, logs
btrfs – snapshots, compression, checksums (use with caution in production)
vfat – Windows compatibility (UEFI boot, cross‑platform storage)
ntfs – Windows NTFS (access via ntfs‑3g)
swap – swap partition for virtual memory
Creating an ext4 Filesystem
# Basic format
mkfs.ext4 /dev/sdb1
# With label
mkfs.ext4 -L "data" /dev/sdb1
# Specify block size (default 4096)
mkfs.ext4 -b 4096 /dev/sdb1
# Specify inode count
mkfs.ext4 -N 1000000 /dev/sdb1
# Fast format (no bad‑block check)
mkfs.ext4 -E lazy_itable_init=1 /dev/sdb1
# Full format with bad‑block check
mkfs.ext4 -c /dev/sdb1Creating an XFS Filesystem
# Basic format
mkfs.xfs /dev/sdb1
# With label
mkfs.xfs -L "data" /dev/sdb1
# Specify block size (default 4096)
mkfs.xfs -b size=4096 /dev/sdb1
# Specify inode size and max percentage
mkfs.xfs -i size=512 -i maxpct=5 /dev/sdb1
# Fast format
mkfs.xfs -f /dev/sdb1Choosing between ext4 and XFS:
General‑purpose, system disks – ext4
Large files, logs, databases – XFS
Need snapshots and checksums – btrfs (test before production)
Creating a Swap Partition
# Format as swap
mkswap /dev/sdb2
# Enable swap
swapon /dev/sdb2
# Disable swap
swapoff /dev/sdb2
# View swap status
swapon -s
free -hViewing Filesystem Information
# UUID and label
blkid /dev/sdb1
# ext4 superblock info
dumpe2fs -h /dev/sdb1
# XFS info
xfs_info /dev/sdb1
# Disk usage
df -h
# Inode usage
df -iFilesystem Repair
ext4:
# Unmount first
umount /dev/sdb1
# Force repair (interactive)
fsck.ext4 -f /dev/sdb1
# Automatic repair
fsck.ext4 -p /dev/sdb1
# Force (dangerous)
fsck.ext4 -fy /dev/sdb1XFS (check only, repair separate):
# Unmount first
umount /dev/sdb1
# Check
xfs_check /dev/sdb1
# Repair if needed
xfs_repair /dev/sdb1Mount Operations
Mount Basics
Mounting attaches a partition ( /dev/sdb1) to a directory (mount point) so that the directory provides access to the data on that partition.
Device – the partition to mount (e.g., /dev/sdb1)
Mount point – directory where the device appears
Filesystem type – ext4, xfs, etc.
Basic Mount Commands
# Simple mount
mount /dev/sdb1 /mnt/data
# Specify filesystem type
mount -t ext4 /dev/sdb1 /mnt/data
# Read‑only mount
mount -r /dev/sdb1 /mnt/data
# Remount with new options
mount -o remount,rw /mnt/dataViewing Mount Status
# List all mounts
mount
# Filter for a specific point
mount | grep /mnt/data
# Human‑readable usage
df -h
# Tree view of devices
lsblkUnmounting
# Normal unmount
umount /mnt/data
# Force unmount (busy)
umount -f /mnt/data
# Lazy unmount (defer until not busy)
umount -l /mnt/dataEnsure no processes are using the filesystem before unmounting (e.g., lsof +D /mnt/data or fuser -v /mnt/data).
Mount Options
defaults– rw,suid,dev,exec,auto,nouser,async (default) ro – read‑only (secure environments) nosuid – disable set‑uid binaries (security) nodev – do not interpret device files (security) noexec – do not allow execution (security) noatime – do not update access time (performance) nodiratime – same for directories (performance) async – asynchronous I/O (performance) sync – synchronous I/O (data safety) errors=remount-ro – remount read‑only on errors
Examples:
# Secure mount (public directory)
mount -o nosuid,noexec,nodev,ro /dev/sdb1 /mnt/shared
# High‑performance mount
mount -o noatime,nodiratime,async /dev/sdb1 /mnt/dataAutomatic Mount Configuration (fstab)
fstab Basics
The /etc/fstab file defines filesystems to be mounted automatically at boot. Each line has six fields:
Device – device name, UUID or LABEL
Mount point – directory path
Type – filesystem type (ext4, xfs, tmpfs, etc.)
Options – comma‑separated mount options
Dump – 0 = no dump, 1 = dump
Pass – fsck order (0 = skip, 1 = root, 2 = others)
# Example fstab entries (UUIDs are placeholders)
UUID=550e8400-e29b-41d4-a716-446655440000 /boot ext4 defaults 1 2
UUID=b2a7d3f0-1234-5678-9abc-def012345678 / xfs defaults 0 1
UUID=c8b9a1e2-3456-7890-abcd-ef0123456789 /data ext4 defaults,noatime 0 2
/dev/sdb1 /mnt/data ext4 defaults,noatime 0 2
tmpfs /dev/shm tmpfs defaults,noexec,nosuid,nodev 0 0Getting UUID and LABEL
# List all devices
blkid
# Specific device
blkid /dev/sdb1
# Sample output
/dev/sdb1: UUID="550e8400-e29b-41d4-a716-446655440000" TYPE="ext4" PARTUUID="12345678-01"Adding an Automatic Mount
# Edit fstab
vi /etc/fstab
# Append a line (example using UUID)
UUID=550e8400-e29b-41d4-a716-446655440000 /data ext4 defaults,noatime 0 2Testing fstab Configuration
# Apply changes without reboot
mount -a
# Verify
df -h | grep /dataUsing LABEL Instead of UUID
# Set a label on the partition
e2label /dev/sdb1 "data"
# For XFS
xfs_admin -L "data" /dev/sdb1
# Use LABEL in fstab
LABEL=data /data ext4 defaults,noatime 0 2tmpfs (in‑memory filesystem)
# Add to fstab
tmpfs /dev/shm tmpfs defaults,noexec,nosuid,nodev 0 0
# Example with size limit
tmpfs /tmp/app tmpfs defaults,size=2G,noexec,nosuid,nodev 0 0LVM Logical Volume Management
Fundamental Concepts
Physical Volume (PV) – a physical disk or partition
Volume Group (VG) – pool of one or more PVs
Logical Volume (LV) – block device carved out of a VG
Advantages: dynamic resizing, snapshots, cross‑disk expansion, hot‑add new disks.
Creating LVM
# 1. Mark a partition as LVM (type 8e)
fdisk /dev/sdb # inside fdisk: t → 8e
# or with parted
parted /dev/sdb set 1 lvm on
# 2. Create PV
pvcreate /dev/sdb1
# 3. Create VG
vgcreate vg_data /dev/sdb1
# 4. Create LV (example 100 GB)
lvcreate -n lv_data -L 100G vg_data
# 5. Create filesystem and mount
mkfs.ext4 /dev/vg_data/lv_data
mount /dev/vg_data/lv_data /dataDynamic LVM Adjustments
Expand LV:
# Extend VG if new PV added
vgextend vg_data /dev/sdc1
# Extend LV
lvextend -L +50G /dev/vg_data/lv_data
# Resize filesystem (ext4)
resize2fs /dev/vg_data/lv_data
# Resize filesystem (XFS)
xfs_growfs /mnt/dataShrink LV (requires unmount and filesystem check):
# Unmount
umount /dev/vg_data/lv_data
# Check filesystem
e2fsck -f /dev/vg_data/lv_data
# Shrink filesystem
resize2fs /dev/vg_data/lv_data 50G
# Shrink LV
lvreduce -L 50G /dev/vg_data/lv_data
# Remount
mount /dev/vg_data/lv_data /dataNote: XFS cannot be shrunk.
LVM Snapshots
# Create a 10 GB snapshot of lv_data
lvcreate -s -n lv_data_snap -L 10G /dev/vg_data/lv_data
# Mount snapshot
mkdir -p /mnt/snapshot
mount /dev/vg_data/lv_data_snap /mnt/snapshot
# After backup, unmount and remove snapshot
umount /mnt/snapshot
lvremove /dev/vg_data/lv_data_snapProduction‑Level Case Studies
Case 1 – Initialising a New Data Disk
Scenario: New server has a 500 GB disk /dev/sdb that must be mounted at /data.
Inspect the disk:
lsblk
fdisk -l /dev/sdbCreate a GPT partition and a full‑size XFS partition:
parted /dev/sdb mklabel gpt
parted /dev/sdb mkpart primary xfs 0% 100%Format the partition:
mkfs.xfs /dev/sdb1Obtain the UUID:
blkid /dev/sdb1Add an entry to /etc/fstab using the UUID and test:
mkdir -p /data
echo "UUID=$(blkid -s UUID -o value /dev/sdb1) /data xfs defaults,noatime 0 2" >> /etc/fstab
mount -a
df -h | grep /dataSet directory permissions:
chmod 755 /dataCase 2 – Expanding the Root Partition (LVM)
Scenario: Root filesystem is full on a system that uses LVM.
Check current usage and LVM layout:
df -h /
vgs
lvsIf the volume group has free space, extend the logical volume and filesystem:
lvextend -L +50G /dev/mapper/centos-root
resize2fs /dev/mapper/centos-root # ext4
# or for XFS
xfs_growfs /If the VG lacks space, add a new physical disk, create an LVM partition, and extend the VG before extending the LV:
# Partition new disk as LVM (type 8e)
fdisk /dev/sdc
# Create PV
pvcreate /dev/sdc1
# Extend VG
vgextend centos /dev/sdc1
# Extend LV and filesystem as aboveNon‑LVM root partitions require deleting and recreating the partition (keeping the start sector) and then running resize2fs. This carries risk and should be backed up.
Case 3 – Fixing a Mount Failure at Boot
Typical causes: wrong UUID, missing mount point, or corrupted filesystem.
Inspect boot logs:
journalctl -xb | grep -i mount
cat /proc/mountsVerify /etc/fstab entries and compare UUIDs with blkid.
Common fixes:
Correct the UUID in fstab.
Create the missing mount point directory.
Repair the filesystem with fsck.ext4 or xfs_repair.
Temporary bypass: edit the GRUB entry at boot, add rd.break or init=/bin/bash, remount root read‑write ( mount -o remount,rw /), then fix fstab.
Case 4 – Migrating Data to a New Disk
Scenario: Move /data from an old disk to a new one.
Partition and format the new disk:
fdisk /dev/sdc
mkfs.xfs /dev/sdc1Mount the new disk temporarily and sync data:
mkdir -p /mnt/newdata
mount /dev/sdc1 /mnt/newdata
rsync -avz /data/ /mnt/newdata/
# Verify integrity
diff -r /data /mnt/newdataUpdate /etc/fstab to use the new disk’s UUID, back up the old file, and test:
blkid /dev/sdc1
cp /etc/fstab /etc/fstab.bak
# Edit fstab, replace old UUID with new UUID
mount -aAfter successful verification, reboot the system.
Summary and Best Practices
Prefer GPT for new partitions; it supports large disks and many partitions.
Use UUIDs in fstab to avoid issues when device names change.
Back up /etc/fstab and important data before modifying partitions.
Test changes with mount -a before rebooting.
Leverage LVM for data disks to simplify future expansion and snapshot backups.
Separate critical directories (e.g., /var/log, /data) onto dedicated partitions.
Set appropriate permissions after mounting.
Regularly monitor disk usage with df, lsblk, and blkid.
Quick Reference – Partition Tools
# fdisk (MBR)
fdisk -l /dev/sda # view
fdisk /dev/sdb # interactive
# Commands: p, n, d, t, w, q, m
# parted (MBR/GPT)
parted /dev/sdb print # view
parted /dev/sdb mklabel gpt # create GPT
parted /dev/sdb mkpart primary xfs 0% 100%
# gdisk (GPT)
gdisk -l /dev/sdb # view
gdisk /dev/sdb # interactive
# Commands: p, n, d, t, w, qQuick Reference – Filesystem Commands
# ext4
mkfs.ext4 /dev/sdb1
fsck.ext4 -f /dev/sdb1
resize2fs /dev/sdb1
# xfs
mkfs.xfs /dev/sdb1
xfs_check /dev/sdb1
xfs_growfs /mountpoint
xfs_repair /dev/sdb1
# swap
mkswap /dev/sdb2
swapon /dev/sdb2
swapoff /dev/sdb2Quick Reference – Mount Commands
# Manual mount
mount /dev/sdb1 /mnt/data
mount -t ext4 /dev/sdb1 /mnt/data
mount -o ro,noexec /dev/sdb1 /mnt/data
mount -o remount,rw /mnt/data
# Unmount
umount /mnt/data
umount -f /mnt/data
umount -l /mnt/data
# View mounts
mount
df -h
lsblk
blkidQuick Reference – fstab Options
# Common options
defaults # rw,suid,dev,exec,auto,nouser,async
ro # read‑only
rw # read‑write (default)
nosuid # disable set‑uid binaries
nodev # ignore device files
noexec # do not allow execution
noatime # do not update access time
nodiratime # same for directories
async # asynchronous I/O (performance)
sync # synchronous I/O (safety)
errors=remount-ro # remount read‑only on errorsQuick Reference – LVM
# PV
pvcreate /dev/sdb1
pvs
pvdisplay
# VG
vgcreate vg_data /dev/sdb1
vgextend vg_data /dev/sdc1
vgs
vgdisplay
# LV
lvcreate -n lv_data -L 10G vg_data
lvextend -L +20G /dev/vg_data/lv_data
lvreduce -L 5G /dev/vg_data/lv_data # requires unmount & fsck
lvs
lvdisplay
# Resize filesystem
resize2fs /dev/vg_data/lv_data # ext4
xfs_growfs /mountpoint # XFSCommon Issues and Solutions
Mount fails – verify UUID, mount point existence, and filesystem integrity.
Out of disk space – clean files, extend partitions (LVM) or add storage.
Filesystem corruption – run fsck for ext4 or xfs_repair for XFS.
Boot failure due to fstab – boot into emergency mode, edit /etc/fstab, then mount -a.
Damaged partition table – use tools like testdisk to recover.
Best‑Practice Checklist
Use GPT for new disks.
Reference partitions by UUID in fstab.
Back up /etc/fstab and critical data before any change.
Validate fstab with mount -a before reboot.
Prefer LVM for data volumes to enable easy expansion and snapshots.
Separate critical directories (e.g., /var/log, /data) onto dedicated partitions.
Set appropriate permissions on mount points after mounting.
Periodically check disk usage with df, lsblk, and monitor logs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Community
A leading IT operations community where professionals share and grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
