2

I'm about to convert my 2x3TB LVM setup to use software RAID1 with 2 additional drives. I'm just wondering if the following will be safe and if there is a way to recover at various steps.

So I have /dev/sdb1 and /dev/sdc1 making up my vg_media volume group.

I'm adding disks /dev/sdd and /dev/sde, but first setting up a degraded RAID on them.

So here is my plan:

# use parted to create GPT partitions on /dev/sdd and /dev/sde

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdd1 missing
mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sde1 missing

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

pvcreate /dev/md0
pvcreate /dev/md1

vgextend vg_media /dev/md0
vgextend vg_media /dev/md1

pvmove /dev/sdb1 /dev/md0
pvmove /dev/sdc1 /dev/md1

vgreduce vg_media /dev/sdb1
vgreduce vg_media /dev/sdc1

It is my understanding that pvmove really just copies everything then updates some metadata so the new physical location is used.

I'm just wondering if I could undo the pvmove at this point and go back to the data on /dev/sdb1 and /dev/sdc1, if something were to go wrong with my degraded RAID.

When I've verified that things seem to be working at this point, I will just do this to finish the RAID

pvremove /dev/sdb1
pvremove /dev/sdc1

sfdisk -d /dev/sdd | sfdisk /dev/sdb
sfdisk -d /dev/sde | sfdisk /dev/sdc

mdadm --manage /dev/md0 --add /dev/sdb1
mdadm --manage /dev/md1 --add /dev/sdc1
  • 1
    Depending on the LVM version, but that should be supported normally nowadays, you also could make use of the LVM internal RAID functionality. It should be possible to convert a linear LVM to RAID and you can just add disks without juggling with disks. More details on the LVM RAID can be found here – Thomas Jul 17 '16 at 18:10
1

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

It's a good starting point for a mdadm.conf but tends to be too verbose. UUID alone is sufficient.

MAILADDR your@address
ARRAY /dev/md0 UUID=d8b8b4e5:e47b2e45:2093cd36:f654020d

It is my understanding that pvmove really just copies everything then updates some metadata so the new physical location is used.

It's like a small RAID-1 mirror. For each segment to be moved, it starts syncing in the new location and once fully in sync, removes the old location. That way any writes that happen on segments currently in the middle of relocation are handled properly as well.

I'm just wondering if I could undo the pvmove at this point and go back to the data on /dev/sdb1 and /dev/sdc1, if something were to go wrong with my degraded RAID.

That depends on what you mean by "go wrong with" ... the pvmove mirror is strictly temporary, you have no redundancy to go back. If the new PV fails entirely you will suffer some data loss.

If you run pvmove in read only mode you might be able to just vgcfgrestore an old vgcfgbackup (create a backup before you start moving things around), however that also only works if the pvmove itself never did anything that overlapped with anything else, overwriting old data in the process.

Running a long smart self-test on all your disks (and looking at other relevant smart data) before starting this movement should tell you beforehand whether to expect big trouble or no.

Alternative methods: (not necessarily any better)

If you can do it offline / from a rescue system, you could just dd(rescue) both disks over to the RAID. However in this case you have to deal with size issues (RAID device must not be smaller than the PV size) and duplicate UUID issues.

You could put the RAID layer onto the original PV without copying anything and then just add the new disks to the RAID. This could be done with 0.90 or 1.0 metadata which lives at the end of the partition (might have to shrink the PV somewhat first), or by editing LV metadata to free the first few physical extents to make room for mdadm metadata at the start of the partition. However this requires you to fully understand both LVM and MD metadata layouts.

  • I have backups so worst case, I don't lose data, but I was just sort of thinking through this and trying to understand a bit better. I'm currently running badblocks on the new drives and testing SMART before and after to be sure. My biggest worry was somehow I screwed up creating the RAID (bad settings or config or something) and I just wanted to go back and start again. Probably overly paranoid since I'm testing the disks beforehand, but I'll use vgcfbackup just so I have that option. – Matt Jul 17 '16 at 20:27
  • Thanks for the note on mdadm.conf too. All the guides I've read recommend that so it's good to know that I really only need part of it. – Matt Jul 17 '16 at 20:28

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.