Summary of Linux Storage Expansion

Core Concepts

1. Disk: Underlying Storage Hardware

A disk is a general term for physical storage devices, forming the basis of all storage management, corresponding to actual hardware (such as mechanical hard drives HDD, solid-state drives SSD) or virtual disks in a virtualization environment (such as VMware’s VMDK, KVM’s QCOW2, cloud server’s cloud disk).

  • Device file path: All disks in Linux are identified by device files under the /dev directory.
    • Physical disks: /dev/sda (first SCSI/SATA disk), /dev/sdb (second), /dev/nvme0n1 (first NVMe disk, faster).
    • Virtual disks: /dev/vda (first virtual disk of KVM/cloud server), /dev/xvda (first disk of Xen virtualization).
  • Capacity unit: Measured in GB/TB, it is the total storage limit that the disk can provide.
  • Partition table type: Disks must be divided into areas through a “partition table”. The two common types are:
    • MBR (Master Boot Record): Traditional partition table, supports a maximum disk capacity of 2TB, and up to 4 primary partitions (or 3 primary partitions + 1 extended partition, which can contain multiple logical partitions).
    • GPT (GUID Partition Table): Modern partition table, supports a maximum disk capacity of 18EB (far exceeding current hardware limits), with no limit on the number of primary partitions (supports up to 128 partitions), compatible with UEFI boot, and is the current mainstream choice.
dos => MBR
gpt => GPT
# fdisk -l

Disk /dev/vda: 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: 0x000b0ebb

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83875364    41936658+  83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xb8a885ad

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   83  Linux

2. Partition: Logical Slices of the Disk

A partition is a logical division of a disk, splitting a physical disk into multiple independent “logical areas”, each of which can be formatted, mounted, and used independently.

  • Device file path: Identified by adding a number to the disk device name, such as /dev/sda1 (the first partition of sda disk), /dev/vda2 (the second partition of vda disk).
  • Functions: 1. Data isolation: Different partitions are managed independently; 2. Performance optimization: Frequently read/write directories (such as /var/log) are partitioned separately to avoid system disk impact due to log overflow; 3. Multi-system support: A single disk can be divided into multiple partitions to install different operating systems (such as Linux + Windows).

3. Physical Volume (PV): The “Building Block” of LVM

A physical volume is the lowest unit of the LVM logical layer, essentially a “partition or disk managed by LVM”—marking a regular partition (or entire disk) as LVM-usable “raw material” for subsequent volume group construction.

pvcreate /dev/sda3  # Convert /dev/sda3 partition to PV
pvcreate /dev/sdb    # Convert entire /dev/sdb disk to PV (no partitioning needed)
pvs  # View all PVs succinctly)
pvdisplay # View detailed PV information, such as capacity, belonging volume group
pvscan   # Scan the list of physical volumes on all disks in the system
pvremove /dev/sda3 # Remove physical volume information from LVM partition, making it no longer recognized as a physical volume

4. Volume Group (VG): The “Storage Pool” of LVM

A volume group is a collection of multiple physical volumes (PV), consolidating scattered PVs into a “unified storage pool”, masking the physical differences of underlying PVs (such as different disks, different capacities), and subsequently dividing logical volumes from the volume group.

vgs   # View all VGs succinctly
vgdisplay  # View detailed VG information, such as total capacity, remaining capacity, included PVs
vgcreate centos /dev/sda3 /dev/sdb  # Consolidate /dev/sda3 and /dev/sdb into VG named centos
vgextend centos /dev/sdc  # After adding a new PV, add it to the existing VG using vgextend
vgreduce centos /dev/sdb  # Remove free PV from VG (ensure PV has no data)
vgremove vg1000 # Delete LVM volume group "vg1000"
vgrename vg1 vg2  # Rename volume group vg1 to vg2
vgchange -ay vg1000     # Set volume group "vg1000" to active state
vgchange -an vg1000    # Set volume group state to inactive

5. Logical Volume (LV): The “Final Usable Unit” of LVM

A logical volume is a “virtual partition” divided from a volume group (VG), serving the same purpose as traditional partitions (can be formatted, mounted, and store data), but with the capability of “dynamic expansion/reduction” that traditional partitions do not possess.

Device file path: The default path is /dev/volume_group_name/logical_volume_name, for example, /dev/centos/root (root LV in centos VG), some systems create a symlink to /dev/mapper/centos-root.

lvdisplay   # Display logical volume properties
# Allocate 20GB LV from centos VG, named root
lvcreate -L 20G -n root centos   #  -L: Specify the size of the logical volume, units are "kKmMgGtT" bytes;
lvextend -L +10G /dev/centos/root   #  Extend logical volume space
lvreduce -L -50M /dev/centos/root   # Reduce logical volume space by 50M
lvremove /dev/centos/root  # Delete specified LVM logical volume  -f for forced deletion
lvresize -L +200M /dev/centos/root    # Adjust logical volume space size, increasing it by 200M

# -l: Specify the size of the logical volume (number of LE).
lvextend -l+100%FREE /dev/mapper/centos-root  # All remaining space

6. File System: “User-Accessible Storage Format”

A file system is the “formatting operation” performed on partitions/LVs, defining the “organization method” of data on storage devices (such as how files are stored, how directory structures are managed, how permissions are controlled), enabling the Linux system to recognize and read/write data.

Type Characteristics Applicable Scenarios
Ext4 Strong compatibility (supported by all Linux distributions), supports dynamic expansion/reduction, journal file system (high data reliability) System disk, regular data disk (such as /, /home)
XFS High performance (fast read/write speed for large files), supports dynamic expansion (does not support reduction), journal file system Cloud server system disk, large file storage (such as databases, videos)
Btrfs Supports snapshots, compression, multi-device integration (similar to LVM), journal file system Scenarios requiring advanced features (such as backup, virtualization storage)
swap Dedicated format for swap partitions, serving as Linux’s “virtual memory”, temporarily used when physical memory is insufficient Swap partition (cannot be mounted, used only by the system kernel)
  • Formatting: Using mkfs command (e.g., mkfs.ext4 /dev/centos/root, mkfs.xfs /dev/vda1).
  • Mounting: Associating the formatted partition/LV to the Linux directory tree using the mount command (e.g., mount /dev/centos/root /), for permanent mounting, configure the /etc/fstab file.

Concept Hierarchy

Hardware Layer: Physical Disk/Virtual Disk (e.g., /dev/sda, /dev/vda)
    ↓ (Partition table division)
Partition Layer: Traditional Partitions (e.g., /dev/sda1, /dev/vda2)
    ↓ (PV initialization)
LVM Base Layer: Physical Volumes (PV, e.g., /dev/sda3, /dev/sdb)
    ↓ (VG integration)
LVM Pool Layer: Volume Groups (VG, e.g., centos, data_vg)
    ↓ (LV division)
LVM Application Layer: Logical Volumes (LV, e.g., /dev/centos/root)
    ↓ (File system formatting)
File System Layer: Ext4/XFS/Btrfs (e.g., /dev/centos/root formatted as XFS)
    ↓ (Mounted to directory)
User Layer: Linux Directory Tree (e.g., /, /home, /data) → Users access data through directories
  • Traditional storage process: Disk → Partition → Formatting → Mounting (fixed size, cannot be dynamically adjusted).
  • LVM storage process: Disk → Partition/PV → VG → LV → Formatting → Mounting (dynamically adjust LV size, flexible expansion).

Core Differences Between LVM and Traditional Partitions

Feature Traditional Partition LVM (Logical Volume)
Capacity Adjustment Fixed size, expansion requires deleting and recreating partitions (high risk, data loss prone) Dynamic expansion/reduction (operations at the LV level, no need to delete partitions)
Cross-Disk Integration Cannot integrate across disks (a partition can only be on one disk) Supports cross-disk integration (VG can include PVs from multiple disks)
Space Utilization Partition capacity must be pre-allocated, unused space wasted (e.g., partition allocated 50GB, only using 10GB, leaving 40GB idle) On-demand allocation (remaining space in VG can be allocated to LV at any time)

Disk Expansion

1. Traditional Partition Expansion

# Can only expand on the same disk (virtual disk)
1. Unmount the disk
umount /test
2. Delete the old partition and create a new one
 fdisk /dev/sdb
d Delete the existing partition (if there are multiple partitions, select the partition number)
n Create a new partition
 p Primary partition
 1 New partition number
 2048 This should match the starting position of the previous partition.
3. Check the new partition
 e2fsck -f /dev/sdb1
4. Correct the new partition
 # Check already mounted partitions and file system types (ext4/xfs)
 df -T
 resize2fs /dev/sdb1
 # ext4 file system: usually use resize2fs command for expansion
 # xfs file system: should use xfs_growfs command for expansion
5. Reload mount information
 mount /dev/sdb1 /test  # Temporary mount
 vim /etc/fstab
 # Add the last line
 /dev/sdb1 /test  ext4       defaults      0 0
 mount -a  # Auto mount

2. LVM Expansion

Two scenarios: 1. Expanding on the original disk 2. Adding a new disk for expansion
----------------------------------------------
1. Check disks and physical volumes
# Check the newly added hard disk device name and physical volume properties
fdisk -l
pvdisplay
2. Create partition (in the case of expanding on the original disk)
fdisk /dev/sdb
.....
partprobe  # Update partition table information
3. Create physical volume
pvcreate /dev/sdb3
4. Extend volume group
vgextend centos /dev/vda3
5. Extend logical volume
lvextend -l +100%FREE /dev/mapper/centos-root
6. Adjust file system size
xfs_growfs /dev/mapper/centos-root
# ext4 file system: usually use resize2fs command for expansion.
# xfs file system: should use xfs_growfs command for expansion.
7. Verify
df -h

Leave a Comment