Get the App
SLTechnology News&Howtos  ›  Servers  › 

Disk expansion based on LVM after disk size adjustment under Linux

Shulou Source: shulou.com Published: 2022-06-02 15:13:46 09月10日 Update

Adjust the disk size under Linux and expand the partition capacity online. The premise is that LVM does not add new LV (alas, obsessive-compulsive disorder occurs again). It is mainly used to:

After the partition of mounting SAN increases the capacity of LUN, the capacity of system partition increases correspondingly after the disk capacity of virtual machine increases.

Assume that the disk to be adjusted is / dev/sda, install centos with lvm, and adopt the default partition of the system.

PV:/dev/sda3VG:/dev/centos-testLV:/dev/centos-test/root and / dev/centos-test/swap

If the LUN is mounted remotely, please mount the umount partition first.

STEP1 scan disk changes # partprobeSTEP2 uses parted to adjust partition capacity

Run parted to enter partition management mode

# parted

Use print all to view the adjusted hard disk size (for example, the adjusted maximum capacity is 21.5GB)

(parted) print all...Disk / dev/sda: 21.5 GB.

Because the physical disk has changed, follow the prompts to perform the 'fix' operation.

Resizepart resizing

(parted) resizepartPartition number? 3 # Select the partition number (Number) here, that is, Flags is the Number of the lvm tag, and here is 3End? [15GB] 21.5GB # enter the new end position here, such as 21.5GB. (parted) quitSTEP3 resize the LVM physical volume # pvresize / dev/sda3

/ dev/sda3 is the physical volume corresponding to the volume group that needs to be expanded

STEP4 resizes LVM logical volumes # lvresize-l + 100%FREE / dev/centos-test/root

Description:

-l: it is adjusted according to the PE block, especially when partitioning by capacity, all idle PE can be used as much as possible.

100%FREE: use all the remaining free space

/ dev/centos-test/root: is a logical volume created and can be viewed using lvdisplay.

STEP5 resize the file system # resize2fs / dev/centos-test/root

The following command is recommended for the xfs file system

# xfs_growfs / dev/centos-test/root add that the command for LVM to resize logical volumes for ext2/ext3/ext4 file systems is resize2fs (both increase and decrease are supported)

Lvextend-L 120g / dev/mapper/centos-home / / increased to 120g

Lvextend-L + 20g / dev/mapper/centos-home / / add 20g

Lvreduce-L 50G / dev/mapper/centos-home / / reduced to 50G

Lvreduce-L-8G / dev/mapper/centos-home / / minus 8G

Resize2fs / dev/mapper/centos-home / / perform adjustments

The tuning command for the xfs file system is xfs_growfs (only growing is supported)

Lvextend-L 120g / dev/mapper/centos-home / / increased to 120g

Lvextend-L + 20g / dev/mapper/centos-home / / add 20g

Xfs_growfs / dev/mapper/centos-home / / perform adjustments

Note: if you want to reduce the xfs partition, you can only mount the logical partition by reformatting it through the mkfs.xfs command after the reduction, so that the original data on the logical partition will be lost.

Tags: Adjust system size capacity disk logic command file physics support maximum in that case location premise obsessive-compulsive disorder situation data time is in label Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Docker Shulou Tech Info macOS