In this article we will show how to incorporate extra space into an existing Linux Partition.
This is used when a Linux based Virtual Machine and the root drive has run out of space in an existing partition inside a single VM hard disc. To actually increase space of the Linux root drive we will perform a simple tweak inside the Linux OS to add extra space to the partition that needs it.
1. Shut down the VM from Hypervisor
2. Right click the VM and select Edit Settings and change Hard Disk size to desired size (90 in this example)
3. Start the VM from the hypervisor
4. Login to the VM console as root
5. Execute the below command to check the disk space :
- The fdisk command provides disk partitioning functions and using it with the -l switch lists information about your disk partitions.
6. Execute the below command to initialize the expanded space and mount it.
The following will be prompted:
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
7. Enter ‘n’ in the next line for creating new partition.
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
8. Assign the partition number you wish based on your existing partition numbering.
9. In the next line choose code ‘8e’ for select the LINUX OS
10. Next enter ‘w’ to proceed further.
Created a new partition 3 of type 'Linux' and of size 74 GiB.
Command (m for help): w
The partition table has been altered.
11. Restart the VM and log back in as root
12. Type fdisk -l and you'll notice another partition is present.
13. Now we need to create physical & logical volumes. Execute the following command to create physical a volume.
[root@tmplt-centos8 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
14. Execute below command to get the name of current Volume Group
15. Execute the following command to extend the Volume Group with /dev/sda3
vgextend <VG NAME> /dev/sda3
vgextend cl /dev/sda3
16. Execute the following command to get Logical Volume path.
17. Execute below command to extend the Logical Volume with /dev/sda3
lvextend <LV_PATH> /dev/sda3
lvextend /dev/cl/root /dev/sda3
18. Execute the following command to update the Logical Volume
19. Check for the disk space has changes by running the following command df -h