Issue: Server was upgraded, the virtual disk (sda) was expanded correctly but the free space is not allocated to the LVM.
Below you have instructions for the ngcs cloud server, which was upgraded.
Step-by-step guide for CentOS
1. First of all add epel-release for the CentOS system.
CentOS 7:
| # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm |
CentOS 8:
| # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm |
2. Install the growpart
| # yum install cloud-utils-growpart –y |
3. Print the current partition layout with the fdisk -l
| # fdisk -l Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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 Disklabel type: dos Disk identifier: 0x27795bc1 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1050623 1048576 512M 83 Linux /dev/sda2 1050624 167772159 166721536 20G 8e Linux LVM |
4. In our example, the /dev/sda1 is the boot partition and /dev/sda2 is the Linux LVM partition we wish to expand. Please notice that the command is asking you for the device (sda) and the partition number 2. There is a space between sda and 2 and it is not a typo.
| # growpart -N -v -u auto /dev/sda 2 |
5. This was only a dry run, to see the changes it is going to make. If you are happy with proposed changes (see the block number changing). Run the command without –N option to resize the sda2 partition.
| # growpart -v -u auto /dev/sda 2 |
6. Verify the changes with fdisk -l again. Establish which partition you wish to expand, for example it could be:
- /dev/mapper/centos-root
- /dev/mapper/vg00-var
7. Try to resize the partition for the LVM, If this command throws some errors, you need to reboot the server.
| # pvresize /dev/sda2 |
8. Use the free space to extend the partition
| # lvextend -l +100%FREE /dev/mapper/centos-root |
9. Extend the xfs filesystem:
| # xfs_growfs /dev/mapper/centos-root |
