How to Expand Linux Disk Space Using fdisk and LVM: Step‑by‑Step Guide
This tutorial walks you through adding a new partition with fdisk, changing its type to LVM, extending the physical and volume groups, enlarging the logical volume, and finally resizing the XFS (or ext4) filesystem to fully utilize the added disk space on a Linux system.
Linux Disk Expansion
After adding a new disk in the console, restart the system and follow the steps below.
Add Partition
Use fdisk /dev/sda to create a new primary partition (e.g., /dev/sda4) of the desired size.
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 4 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.View New Partition Types
# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a9a6f
Device Boot Start End Blocks Id System
/dev/sda1 2048 6143 2048 83 Linux
/dev/sda2 * 6144 2103295 1048576 83 Linux
/dev/sda3 2103296 41943039 19919872 8e Linux LVM
/dev/sda4 41943040 83886079 20971520 83 LinuxChange Partition Type
Set the partition type to match LVM (type 8e) using fdisk /dev/sda and the t command.
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Partition number (1-4, default 4):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.Verify Modified Partition Type
# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a9a6f
Device Boot Start End Blocks Id System
/dev/sda1 2048 6143 2048 83 Linux
/dev/sda2 * 6144 2103295 1048576 83 Linux
/dev/sda3 2103296 41943039 19919872 8e Linux LVM
/dev/sda4 41943040 83886079 20971520 8e Linux LVMDisk Expansion
After reboot, extend the logical volume.
Check Volume Group
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <18.00g
swap centos -wi-ao---- 1.00g
# vgdisplay
--- Volume group ---
VG Name centos
Format lvm2
Metadata Areas 1
VG Access read/write
VG Status resizable
Cur LV 2
Cur PV 1
VG Size <19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0Create Physical Volume
Create a physical volume on the new partition.
# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.If the device is not found, run partprobe first to make the kernel aware of the new partition table.
# partprobe
# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.Extend Volume Group
# vgextend centos /dev/sda4
Volume group "centos" successfully extended
# vgdisplay
--- Volume group ---
VG Name centos
Metadata Areas 2
VG Status resizable
Cur LV 2
Cur PV 2
VG Size 38.99 GiB
Free PE / Size 5119 / <20.00 GiBExtend Logical Volume
# lvextend -l +100%FREE /dev/centos/root /dev/sda4
Size of logical volume centos/root changed from <18.00 GiB (4607 extents) to <36.50 GiB (9343 extents).
Logical volume centos/root successfully resized.Resize Filesystem
For XFS filesystems, run:
# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1179392 blks
... (output truncated) ...
data blocks changed from 4717568 to 9567232If the filesystem is ext4, use resize2fs instead.
Expansion complete.
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.
