LVM is pretty great. I’ve been using it for years and you can do amazing things with it. It essentially adds an abstraction layer between physical media and filesystems. LVM has more features such as software raid, snapshots and more but hardware abstraction is what I use it for.
Replacing disks or extending filesystems becomes extremely trivial with LVM. Not only that, replacements can be done without ever shutting down the system or waiting for the process to finish.
A while back I was forced to replace my laptop. Unfortunately, the replacement laptop didn’t allow for a simple drive swap so I had to get a little creative.
Luckily I had access to one of those SATA to USB adapters. So I took the old drive and connected it via the adapter to one of the USB ports. Few minutes later I was booting from the old drive, albeit a bit slow due to the USB 2.0 bottleneck.
I started by partitioning the new internal NVMe SSD, added it to the LVM group and instructed LVM to move everything from the old USB-connected drive to the new internal NVMe drive. This operation of course took some time but I was able to continue my work like normal. The system gradually became faster and faster over time as more and more blocks were moved to the internal drive.
A few weeks pass and although for different reasons, once again I had to switch laptops. This time however, both laptops had internal non-removable drives. Or at least, not without removing a hundred screws and prying glued components apart.
After a bit of Googling I found something called NBD. Network Block Device is a pretty old protocol which allows a physical drive to be shared over a network as a plain block device. So I connected the two laptops together via gigabit and got to work.
A few minutes later the internal drive of the target laptop was accessible on my current laptop. I repeated the process of partitioning the drive, adding the drive to the LVM group and once again instructed LVM to move everything to the new drive. Meanwhile, I was able to continue working as normal.
Once the process finished, I shut down the laptop I was working on and rebooted the new laptop. It booted right away with all my data there, like nothing ever happened.
I found out later that this third laptop has a second internal drive. So I created a degraded RAID 1 array using software raid, partitioned the array, added it to the LVM pool and once more instructed LVM to move everything to the array.
I then re-partioned the now empty drive, added it to the array and voila. Hardware redundancy with a little bit of speed boost. A little bit of GRUB magic and I was able to boot from both drives.
The performance improvement was a bit of a bummer. I was expecting 350+300 MB/s reads but in the end only got about 500MB/s. I guess some internal bus is limiting transfer speeds. It will have to do.
There was a notable size difference between both SSDs, one being 256GB and the other 512GB. As all nodes in a RAID 1 array must be the same size I ended up with a 256GB RAID 1 array. The remainder I added as non-redundant storage to the end of my LVM pool. Perfect for swap space and other non-critical storage such as test containers and temporary VMs.
The flexibility that LVM provides is simply priceless. I highly recommend LVM on any new installation.