In this article we will be discussing how to go about increasing the size of a Linux LVM. This will involve making the needed space available on the physical partition first. You will need to have available space, either by adding a new hard drive to your system, or if you are in a dual-boot situation such as myself you can shrink one of your current Windows partitions. When performing these tasks be sure you have made your needed backups of any of your important data before proceeding. As we are messing with partitions, and in the case of this example the root partition, a mistake could cause data loss.
This example will start within the Windows 10 partition where I used Disk Manager to shrink the size of one of my data drives by 150 GB’s. This is done by using the shrink option. You are then able to see how much you are able to adjust the size of the chosen partition.
Once the drive has been adjusted you can leave it unallocated as the remaining steps will be taken care of on the Linux side of things.
Once you have chosen the space you need you can reboot the system and boot back into your Linux distro and go ahead to the next phase of the project.
The next step you can run fdisk -l which will allow you to view the current setup of the disks, and the disk in which you are planning to expand. In this example we are looking at the /dev/mapper/fedora_fedora-root which shows a current allocation of 43.3 GBs.
Next we will need to create a partition from the available drive space we made at the start of this tutorial.
You can use the disk partition utility within Linux to create a Linux partition. You will also need to change the type of the partition to be LVM. This can be done by clicking on the gears icon where you can then make the required changes.
Once you have the partitions created and properly configured we can verify this with the command fdisk -l.
As you can now see from the output of the fdisk -l command you will see your original partition (shown as /dev/sdc5 with a size of 48.1 G), and the new partition (shown as /dev/sdc6 with a size of 146.5 G).
The next step involves increasing the logical volume. We will use the pvcreate command to create a physical volume for later use by the logical volume manager (LVM). In this case the physical volume is our /dev/sdc6 partition.
In this example it first failed as the drive was currently mounted. After unmounting the drive in the disk utility I ran the command again. Again, there was a warning as a partition was already in place on this drive and asked if I wanted to wipe it. I said yes to continue which resulted in the message that the Physical volume /dev/sdc6 was successfully created.
Our next step is to issue the command vgdisplay to verify the name of the volume group. This example has the volume group name set to fedora_fedora. We can then extend the volume group with the command vgextend fedora_fedora /dev/sdc6. You will get a response indicating that the Volume Group fedora_fedora has been successfully extended.
The pvscan command will scan all physical volumes so you can confirm both partitions. You will see the original /dev/sdc5 partition, and the new /dev/sdc6 partition.
We now extend the logical volume using the lvextend command. lvextend /dev/fedora_fedora/root /dev/sdc6. It shows it changed from 43.25 G to 189.73 G and that the logical volume root was successfully resized.
Finally we issue the resize2fs /dev/fedora_fedora/root command and we get a report that the filesystem on /dev/fedora_fedora/root is now 49737728 blocks long.
We can now run the df command to view all the filesystem on the Linux system. You will notice that the available disk space on your selected drive has increased by the amount you picked at the beginning of this tutorial.
For myself this came about as I was testing installing Fedora as a dual-boot with Windows 10. The installation process and configuration of Fedora went so well I did not want to restart, however needed more space as I have begun using Fedora as my primary OS instead of Windows 10.