Customising the Logical Volume After Enlarging the SSD in CentOS (Cloud Server)
Please use the “Print” function at the bottom of the page to create a PDF.
In this article, we'll show you how to customise the Logical Volume after increasing the size of your SSD in CentOS 7, CentOS Stream 8, and CentOS Stream 9.
On cloud servers, the Logical Volume Manager (LVM) is used to manage storage space. The Logical Volume Manager puts a logical layer between the file system and the partitions of the datastores in use. This makes it possible to create a file system that spans multiple partitions and/or disks. In this way, the storage space of several partitions or disks can be combined. In addition, the Logical Volume Manager gives you the option to increase a logical volume on the fly.
After you have increased the size of your cloud server's SSD, you must manually adjust the size of the Logical Volume.
Please Note
We recommend that you take a snapshot before manually adjusting the logical volume. You can use a snapshot to restore the captured state of your cloud server or virtual server. However, please note that snapshots are automatically deleted after three days.
For more information on how to create a snapshot, click here:
Requirements
You have restarted the server after enlarging the SSD.
You have logged in to the server as an administrator.
Preparation
Install the growpart program. To do this, enter the following command and then follow the instructions.
[root@localhost ~]# yum install cloud-utils-growpart
To check the available space of the logical volume, enter the following command:
[root@localhost ~]# df -h
After entering the command, the following partitioning is displayed, for example:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 78G 1.3G 77G 2% /
devtmpfs 899M 0 899M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 18M 893M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 509M 213M 296M 42% /boot
tmpfs 182M 0 182M 0% /run/user/0Note the logical volume that is to be expanded. This is mounted under /. In the above example, the logical volume is /dev/mapper/centos-root.
To view the partitioning of the Logical Volume, type the command below. Then press Enter.
[root@localhost ~]# fdisk -l
After entering the command, the file system structure is displayed:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000ccef8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 167772159 83360768 8e Linux LVM
Disk /dev/mapper/centos-root: 83.2 GB, 83181436928 bytes, 162463744 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesIn this example, the partition sda2 is to be adjusted manually. Note the name of the partition for this purpose.
To determine the file system, enter the following command:
[root@localhost ~]# df -Th | grep "^/dev"
In the following example, the logical volume /dev/mapper/centos-root uses the xfs file system:
[root@localhost ~]# df -Th | grep "^/dev"
/dev/mapper/centos-root xfs 78G 1.7G 76G 3% /
/dev/sda1 xfs 509M 207M 303M 41% /boot
Increasing the Size of the Partition with growpart
Use the following growpart command to grow the partition:
[root@localhost ~]# growpart /dev/device_name
Example:
[root@localhost ~]# growpart /dev/sda 2
Take note of the fact that there is a space between the device name and the partition number.
Increasing the Logical Volume Manually
To display detailed information about the physical volumes, enter the following command:
[root@localhost ~]# pvdisplay
After entering the command, the following information is displayed, for example:
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <79.50 GiB / not usable 30.00 MiB
Allocatable yes (but full)
PE Size 32.00 MiB
Total PE 2543
Free PE 0
Allocated PE 2543
PV UUID 6FKWEG-OnkG-QxZt-m7TB-wiDb-K9P6-I403lPTo resize the physical volume, enter the following command:
[root@localhost ~]# pvresize /dev/sda2
After entering the command, the following information is displayed:
[root@localhost ~]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resizeTo check the status of the logical volumes, type the following command:
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ZghzAz-F7hG-Kxsn-OEdM-idwf-HPmJ-esaD8s
LV Write Access read/write
LV Creation host, time localhost, 2019-03-18 19:48:34 +0000
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 64
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 1ajYhy-gUdt-KUG4-9MaO-8ayT-g7Yi-Q3lGg1
LV Write Access read/write
LV Creation host, time localhost, 2019-03-18 19:48:34 +0000
LV Status available
# open 1
LV Size <77.47 GiB
Current LE 2479
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0Note the path of the logical volume you want to expand. In this example, the path is /dev/centos/root.
To increase the size of the logical volume with the lvresize program, type the lvresize command in the following format:
[root@localhost ~]# lvresize -l +100%FREE [PATH OF LOGICAL VOLUME]
Example:
[root@localhost ~]# lvresize -l+100%FREE /dev/centos/root
Size of logical volume centos/root changed from <77.47 GiB (2479 extents) to <97.47 GiB (3119 extents).
Logical volume centos/root successfully resizedResize the file system to use the new space. To use xfs_growfs to resize the file system to the new size, type the xfs_growfs command in the following format:
[root@localhost ~]# xfs_growfs [PATH OF LOGICAL VOLUME]
Example:
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=42, agsize=489472 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=20307968, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 20307968 to 25550848If the partition uses the ext4 file system, enter the following command to resize it to the new size:
[root@localhost ~]# resize2fs [PATH OF LOGICAL VOLUME]
Example:
[root@localhost ~]# resize2fs /dev/centos/root
To check if the file system has been adjusted, enter the following command:
[root@localhost ~]# df -h