Marcus Str.
Husband, flight sim pilot, IT specialist

About | Tweets | Code | CV | Categories | Ortho4XP Tiles | Live Stream


End your hard drive chaos with LVM
 
Linux


LVM stands for Large Volume Management, and what it essentially does is that it can help you combine multiple drives into one single storage instance. This will then put an immediate end to inventing ever new mount points in your home install.

I slammed a Debian 12 on my main machine first. The plan was then to combine all my drives, which come to a total of 1.5TB in storage space, into one singular drive (which then in turn uses the entire space for VMs).

Back up your important data first!

Install Debian (or the distro of your choice) onto a drive of your choice, I chose the smallest I have so that I have a baseline to begin with. The smallest was 120 GB SSD for me. I walked through the install as normal, but did choose to configure the partition setup as LVM.

Then, you need to re-initialize all drives with a GPT partition table, and create one partition on the drive.

I HIGHLY recommend you use ext4 as the file system for that one partition as ext4 natively supports LVM and offers some features other file systems do not have, for example enlarge or shrink an LVM instance in real time without ever having to touch partition tools like fdisk or gparted.

Next, you simply need to attach your paritions to the LVM schema Debian (or your distro) has created in the install process.

You can find out what the name of that is by typing

df -h



Write down this name as you will need it for the operations that come next.

First, create a volume group of the partition you want to extend the existing LVM group with:

pvextend /dev/DRIVE_PARTITION (for example sdb1)



Next, extend your existing group by doing

vgextend NAME_OF_YOUR_LVM_GROUP /dev/DRIVE_PARTITION



Finally, perform a

lvextend -l +100%FREE /dev/VOLUME_GROUP/



Sometimes the volume group in /dev is registered in /dev/mapper - do a 'df -h' to see the exact path.

And, then, as your final act of tonight's entertainment, you need to add the free space to the unified ext4 system with

resize2fs /dev/VOLUME_GROUP



If you now go and perform another 'df -h', you will see that you have more free space than before - and thus have combined one hard drive with another in terms of space management.

Rinse and repeat for any other hard drive you want to add to that setup.


© 2024 Marcus Str.