0

I've got a machine with two physical identical hard drives which are currently set up with LVM as one logical volume. The original idea was to make use of as much "contiguous" space as possible in order to store a big amount of very large data. Time passed, and the current use of the machine changed, so now I'd rather have the two disks in RAID1, both for some extra safety (yes, I do make backups anyway) and 'cause I really don't need that much space anymore. The main concern is whether the second disk does actually have data on it, but I couldn't find any way to actually know how much data is stored on the physical volume.

I'm trying to figure out what the best way to do this would be, and what features does LVM offer me for this. Would I have to reinstall from scratch, or is there any way I could "split" the LVM and create a RAID1 array while keeping the data on - at least - the first disk (supposing the second one has no data on it)?

Thank you very much.

1

LVM supports some simple RAID configurations, including mirroring (RAID1).

Your best option will be to shrink the LV to a size such that it'll fit onto a single disk (using resize2fs -- assuming ext3/4 -- and lvresize), migrate the VG to a single PV (pvmove), then convert the LV to a mirror (lvconvert --mirror).

As an alternative, instead of converting the LV to a mirror, you could remove the second disk from the VG (lvremove), reformat it as a mdadm RAID1 array with one element, copy your data there, then remove the remaining LVM VG and add it to the array as a mirror.

It should go without saying, but I'll say it anyway: make sure you have a current backup before trying either of these approaches. There are a lot of ways you could easily screw things up and lose data. If possible, set up a scratch array and test on that (e.g, using a pair of USB thumb drives!) before making any changes to your live system.

  • Thanks! I'll keep this in mind since it looks like a good approach. – markkuit Jul 31 '17 at 19:20
0

Depending on how how actual your distribution/kernel and tools are, there are some options.

First you should be able to identify how much space is used ondisk with the command as follows.

lvs -o +devices

or

pvs -o+pv_used

Then you might have to shrink the filesystem before shrinking the block device as the usable space will be less than before.

Consult the man page of lvconvert. It should be possible to convert from a striped/linear volume to RAID1. You also will find various examples and good documentation to find out if you can convert.

If lvconvert does not work for you, you could use pvmove and vgreduce to free up one disk. You also have to shrink the filesystem before.
Then you can start a RAID1 with just one drive.

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 missing

Then make your filesystem on /dev/md0, mount it and copy the data. Then unmount your LVM and add the second disk to your RAID1. Partition or clean the LVM before.

mdadm --add /dev/md0 /dev/sdb1

Keep in mind that a backup is a really good idea before making these steps as a tiny mistake may nuke your data.

  • Thanks! I'm still having issues trying to figure out how much space is used on the physical volumes. This is what I see, it sees the disks as "full" as in completely partioned, but doesn't look like it looks in-depth at actual usage, or am I missing something? pastebin.com/raw/izuDWxFx – markkuit Jul 31 '17 at 19:21
  • @MarcoGiosa This is normal. Unless you explicitly created the LVs with thin provisioning (which is usually a bad idea!), all of the space was allocated during lvcreate. – duskwuff Jul 31 '17 at 19:51
  • I see. So would there be a way for me to know whether there is data actually stored on the second physical disk? I tried having a look at iotop but of course I'd guess that isn't ideal at all. – markkuit Aug 1 '17 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.