Master LVM: Create, Extend, Shrink, and Remove Logical Volumes on Linux
This guide explains LVM fundamentals and walks through creating physical volumes, volume groups, and logical volumes, formatting and mounting them, then demonstrates how to extend, shrink, and finally remove physical volumes safely using Linux command‑line tools.
Introduction
LVM (Logical Volume Manager) is a Linux mechanism that adds a logical layer between physical storage and file systems, allowing flexible disk management. Key terms include physical media, physical volume (PV), volume group (VG), logical volume (LV), physical extent (PE) and logical extent (LE).
Experiment
Creating logical volumes
1. Create two partitions (sda5 5G, sda6 10G) and view them with fdisk -l.
2. Initialize sda6 as a physical volume: pvcreate /dev/sda6.
3. Create volume group vg6 with 16 MiB PE size: vgcreate -s 16M vg6 /dev/sda6.
4. Create a 6 GiB logical volume named ftpdata: lvcreate -L 6G -n ftpdata vg6.
5. Format it as ext4 and mount it, then copy some configuration files.
Extending the volume
1. Add the remaining sda5 to vg6: vgextend vg6 /dev/sda5.
2. Extend ftpdata by 4 GiB or to a total of 10 GiB using lvextend -L +4G /dev/vg6/ftpdata or lvextend -L 10G /dev/vg6/ftpdata, then resize the filesystem with resize2fs /dev/vg6/ftpdata.
Shrinking the volume
1. Unmount the filesystem, run e2fsck -f /dev/vg6/ftpdata, and test the reduction size with lvreduce -L 6001M /dev/vg6/ftpdata -t.
2. After confirming, resize the filesystem to 6000 M: resize2fs /dev/vg6/ftpdata 6000M.
3. Deactivate the LV, reduce it to 6000 M: lvchange -an /dev/vg6/ftpdata then lvreduce -L 6000M /dev/vg6/ftpdata, reactivate with lvchange -ay /dev/vg6/ftpdata, and remount.
Removing a physical volume
1. Ensure the PV has no data, move data with pvmove /dev/sda6 /dev/sda7.
2. Deactivate the VG and remove the PV: vgchange -an vg5 and vgreduce vg5 /dev/sda6.
All commands were executed on a Linux system, and the article concludes with a disclaimer that the content is sourced from the internet.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
