Couple of days ago I installed Arch Linux with i3wm. During installation I enabled LVM without understanding its effects. But after I realized, by default Arch has allocated only 20 gigs of space for \root (which was almost full after installing my required packages) and rest of the space of the whole hard disk for \home. Both of these partitions were logically separate which is basically LVM is all about. So, scoured the internet to increase the space of my root directory. As it turns out, there are no single article that thoroughly covers this specific problem. I have read RedHat's guide on LVM, LVM's own documentation, some other articles. After hours of searching and reading I was able to come up with a solution.
To perform this process safely, you need to boot into a live environment where /home and / aren’t mounted. The best way to do this is by booting from an Arch ISO or a live USB.
Once you’re in the live environment, you will need to activate the Logical Volume Manager (LVM) so you can make changes to your volumes. Run the following command to activate the volume group:
vgchange -ay
To verify that the logical volumes are available, use:
lvdisplay
This command will display details about your LVM volumes, ensuring everything is set up and accessible. Note the paths of partitions.
/home FilesystemBefore you shrink the /home partition, you need to check its filesystem integrity. This can help prevent data corruption during the shrinking process.
e2fsck -f /dev/ArchinstallVg/home
This will check and fix any filesystem issues on /home before proceeding.
/home FilesystemNext, you want to shrink the filesystem on the /home partition. For this example, we’ll shrink it by 20 gigs, leaving /home with approximately 130 gigs of space (you will have determine your space amount). Use the following command to resize the filesystem:
resize2fs /dev/ArchinstallVg/home 130G
Always shrink the filesystem before shrinking the logical volume. If you shrink the logical volume first, it can cause filesystem corruption.
/home Logical VolumeOnce the filesystem is resized, it’s time to shrink the logical volume itself. This will reduce the space allocated to /home, making room for the root (/) partition. To shrink the logical volume by 20 gigs, run:
lvreduce -L -20G /dev/ArchinstallVg/home
Confirm the action when prompted. Double-check the values to ensure you’re not shrinking it too much.
/ FilesystemBefore you extend the root (/) partition, you need to check its filesystem integrity. This can help prevent data corruption during the shrinking process.
e2fsck -f /dev/ArchinstallVg/root
This will check and fix any filesystem issues on /root before proceeding.
Now that you’ve freed up 20 gigs of space, you can allocate that space to the root (/) partition. To do this, extend the root logical volume:
lvextend -L +20G /dev/ArchinstallVg/root
This command adds the 20 gigs of free space to the root partition.
Now that you've extended the root logical volume, it’s time to grow the filesystem. For ext4, you can resize the filesystem with the following command:
resize2fs /dev/ArchinstallVg/root
This step ensures that the root partition recognizes and uses the newly added space.
Once you've resized the logical volumes and grown the filesystem, it's time to reboot the system back into your usual environment.
reboot
Once the system has rebooted, you can verify the changes by checking the disk usage:
lsblk
df -h
These commands will show the updated sizes for your partitions and the amount of space available.
By following this guide, you’ve successfully freed up space from /home and allocated it to your root partition. This process ensures that your root (/) gets its space allocated without breaking your filesystem.