How to Partition Linux Disks for Three Common Scenarios
This guide walks through three practical Linux disk‑partitioning scenarios—mounting a new partition to a directory, extending a subdirectory via a symbolic link, and enlarging the root filesystem—complete with commands, formatting steps, and verification.
Linux Disk Partitioning: Three Common Scenarios
Scenario 1 – Mount a New Partition to a Directory
First, inspect the target disk:
lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 32G 0 disk
├─sdb1 8:17 0 200M 0 part /boot/eifCreate a new primary partition (sdb2) of about 15 GB using fdisk:
fdisk /dev/sdb
n # new partition
p # primary
2 # partition number
<Enter> # default start sector
+15G # size
w # write changesFormat the new partition (ext4 in this example) and mount it:
mkfs.ext4 /dev/sdb2
mkdir /mnt/sdb2
mount /dev/sdb2 /mnt/sdb2Verify the mount:
df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb2 ext4 15G 41M 14G 1% /mnt/sdb2Scenario 2 – Expand a Subdirectory Using a Symbolic Link
When a subdirectory needs more space, create a new partition, format it, mount it at a temporary location, and then link the original subdirectory to the new mount point with a symbolic link, effectively extending storage without moving files.
Scenario 3 – Expand the Root Filesystem
For a system using an MBR disk (e.g., /dev/sda) with the root partition (/dev/sda7) formatted as XFS, the following steps enlarge the root filesystem:
1. Ensure the root partition is the last one on the disk and note its size with fdisk -l:
fdisk -l /dev/sda
... (output showing /dev/sda7 as the last partition) ...2. Refresh the kernel partition table:
sudo partprobe /dev/sda3. Verify the filesystem type:
blkid /dev/sda7
/dev/sda7: UUID="f7c7645e-5d67-43f8-ba7e-5c9f019d980a" TYPE="xfs"4. Grow the XFS filesystem to use the newly allocated space:
sudo xfs_growfs /dev/sda75. Confirm the expanded size:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda7 152G 66M 152G 1% /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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
