LVM: Merging partitions used as physical volumes for volume group

First off sorry for the long post:

TL-DR: Is it possible/easy to merge partitions in an LVM volume group if they are on the same physical disk and contiguous?

I am probably being pedantic here and not using Linux LVM the way it is intended, but when I installed my OS (Fedora Workstation, currently F29) I didn’t really understand LVM as well as I should. I knew what I wanted to do but ended up with a storage set up I am not very happy with.

My Linux install currently uses two disks, an SSD for the /boot/ /root etc and a 2TB SSHD that I use for /var/ /tmp/ /swap/ and /home.

The original plan was to allocated fixed space for /var /tmp and /swap on the SSHD and have /home use the rest of the space. That was the plan but I think somewhere along the line I decided since I was using LVM that it would be a good idea to leave some un-allocated space on the SSHD to use later when I needed.

So I think what I ended up doing was creating a single partition on the SSHD just big enough for /var /tmp & /swap and then 250GB for /home and this one partition became my "fedora-sshd" volume group where I set up the various logical volumes.

Jump forward a year or so later and that 250GB /home was pretty much full, so I decided to use some of that un-allocated space. I thought I could just resize the partition, which I believe is possible but I was afraid of loosing data so in the end I just created a another 512GB partition, added it to the "fedora-sshd" volume group and extended the /home logical volume.

Jump forward another year and I am in the same situation (I’ve been creating a few more VMs which are taking up space).

The SSHD now has 2 partitions on it and about 1TB of un-allocated space (the original one and the one I used to extend the "fedora-sshd" volume group.

In hindsight, I should have just used the entire SSHD as the “fedora-sshd” volume group and created the /var /tmp /swap and /home logical volumes in it.

My question is, is there an easy way to merge the two existing partitions and the un-allocated space and use the entire SSHD as my "fedora-sshd" volume group or should I just do the same again and create a new partition and add it to the volume group?

I’m probably just being pedantic, after all the purpose of using LVM is to group storage from different storage devices but it just seems a little redundant if the storage is just on one physical disk anyway.

Perhaps another option, if I am going to have to create a new partition would be to create a new "fedora-sshd-vm" volume group for my VMs and move them there to free up space in "fedora-sshd" for /home and allow me to expand the VM volume group with an additional disk if I even need it … hmmm :thinking:

Any advise would be appreciated (even if it’s “just create the new partition and forget about it” :smiley: )

Cheers.

Your use of “SSHD” is kind of confusing for me.

“Solid state hard drive” makes sense even though it’s not usually referred to that way. But you contrast it against SSD.

What type of disk is the 2TB drive?

I want to make sure I completely understand before I make my suggestion.

1 Like

It’s a “Solid State Hybrid Disk” (SSHD) basically spinning rust with a built in flash cache (Usually 8-16GB). They were briefly popular before the price of large capacity SSDs started to fall.

Okay, thanks for clarifying.

The ideal way was the approach you rejected out of fear of data loss; expanding the partition size of the LVM physical volume, doing a PV resize, and expanding the underlying filesystem.

For what it’s worth, I’ve done that a lot. It’s very stable when you’re growing filesystems. Shrinking is a little less reliable, since not all filesystems handle that nicely.

The suggestion I was going to make was “take a backup, go nuclear, and start fresh.”

Not because you’ve done anything wrong, but because I’ve found a generally better approach for workstations and desktops.

Rather than splitting your SSD and your HDD (I’m just going to treat the SSHD as an HDD for the sake of simplicity) capacity because one is fast and one is big, combine their benefits!

Allocate about 50GB of space on the SSD as a cache device, use the 2TB device for backing, and then put your volume groups on the device exposed by your caching solution.

As it stands now, having your /var, /tmp, and swap space on the HDD brings most of your system operations down to the speed of spinning rust. Putting them on a cached device would improve system responsiveness over this configuration.

Unfortunately, I’m not sure how well the SSHD will handle that. Caching caches is not always fun.

1 Like

Yes that makes sense, I was thinking of doing this but was concerned about potential data loss as the tutorial warns that the existing partition needs to be deleted and then recreated at the exact same starting sector. It seems to suggest you can delete and re-create the partition in this way without loosing data but it wasn’t clear.

It also means I need to deactivate the logical volumes in the volume group while doing it so since that contains /swap and /home I assume I would need to boot in single user mode and login as root to do the work.

Although I am assume there’s not going to be much I can do about the 1st partition on the disk anyway as there’s already data in the second partition and they are contiguous on disk. E.g

+-----------------+----------------+-------------------------+
| Partition 1 | Partition 2 | 1TB Unallocated                |
+-----------------+----------------+-------------------------+

I am assuming the best I could do would be to extend partition 2 with the un-allocated space and end up with something like this

+-----------------+------------------------------------------+
| Partition 1 | Partition 2                                  |
+-----------------+------------------------------------------+

That’s pretty much the reason I am using the SSHD, it’s kind of the same as having a small caching SSD backed by a large HD except in hardware. The SSHD is a 2TB standard HD with a small NAND flash drive (8GB for my drive) built in. It has logic on the drive to cache at a sector level. It’s probably not as fast as using a modern SSD as cache and it doesn’t know anything about file systems in the way a software cache would but it’s certainly a lot faster than a regular HD,

Thanks for your suggestions, I am going to have a good think about it before I do anything. I have a 4TB HD so might just clone the SSHD to it first and then see if I can figure out how to switch /var /tmp /swap/ /home to that and just format and re-partition the SSHD before moving everything back.

It’s all part of the Linux learning process :smiley: (Famous last words before the “How do I restore data after re-partition?” thread :stuck_out_tongue_winking_eye:)

It also means I need to deactivate the logical volumes in the volume group while doing it so since that contains /swap and /home I assume I would need to boot in single user mode and login as root to do the work.

You can do all of this online. The ext* family of filesystems, btrfs, and xfs all support online resizing.

LVM would be rather useless if you had to offline your storage to work with it. :slight_smile:

That’s good to know, cheers.

The more I dig into this though the more tempted I am do do a complete re-install … just looked at my SSD and it’s pretty much being wasted.

Device       Start       End   Sectors  Size Type
/dev/sda1     2048   1050623   1048576  512M EFI System
/dev/sda2  1050624   5244927   4194304    2G Linux filesystem
/dev/sda3  5244928 542119935 536875008  256G Linux LVM

I think it’s time for a complete storage review :smiley:

1 Like