The Logical Volume manager solved this problem once and for all. LVM is a device mapper framework that allows for disk management in very easy steps.
LVM allows sysadmins to perform disk management tasks such as resizing, extending, and removing partitions flexibly and easily. Therefore sysadmins do not need to take the system offline to extend partitions and more.
In this tutorial, I will show you a method to use the LVM manager to extend the size of your root partition.
NOTE: This tutorial is not an introductory guide to LVM.
Pre-requisites
Before we get started with the tutorial, you will need to meet the following requirements.
- Root or user with sudo privileges
- Ensure you make a backup copy of all your files in case of trouble.
In the examples within this tutorial, I will be shrinking my home directory and add the extra space to the root directory. I’m also illustrating this tutorial on a CentOS 8 machine running on VMware.
Step 1 – Make Backups
The very first step before we proceed is to make a backup of your home directory. You don’t need to do this, but I cannot recommend it highly enough. Back up your files using file shares, copy them to a local drive, or compress them and move them to a new directory.
Step 2 – Unmount Home dir
The next step is to unmount the home directory. To view the location of the home partition, use the df command as:
This shows the location of the home partition as shown:
Use the command below to unmount.
Step 3 – Delete Home Volume
Once successfully unmounted, we need to remove the home volume using lvm. Use the command as:
This command will prompt you whether to proceed to remove the home volume. Press y to proceed.
Step 4 – Shrink Home Dir
The next step is to shrink the size of the home directory. That means we will recreate the home volume as a smaller-sized volume.
Start by getting the volume group name.
VG Name cl
That gives us the volume group name as cl.
Now, all we have to do is create a new volume for /home using lvcreate command as:
That will create the home volume with 5GB in size.
Step 5 – Format the volume
Now it’s time to format the home volume. Get the file type using the df command as:
Using mkfs utility format the volume as:
Step 6 – Mount Home dir
Now mount the newly created volume as:
Upon successful mount, restore your backups to the new home volume.
Step 7 – Extend Root
Now it’s time to extend the root partition with the free space available from shrinking the home directory. Start by getting the path of the root logical volume.
To extend the root partition with all the free space, the command as:
This command will extend the root partition with all the remaining free space from the home directory.
Conclusion
In this guide, we looked at how to extend the root partition by shrinking the home directory.
from Linux Hint https://ift.tt/3ji2hXw
0 Comments