LVM and RAID

If you have a question about a file system (for example xfs, reiserfs, ...)

Moderator: feffer

Post Reply
Guest

LVM and RAID

Post by Guest » Tue Mar 23, 2004 3:48 am

This works with copying disk data within partitions if I understand correctly... What if you're using LVM2? Can it properly copy the contents from a Logical Volume? What about a RAID set?

guest/2

LVM and RAID

Post by guest/2 » Thu May 19, 2005 8:31 am

and what about LVM1 ?

lud

Post by lud » Tue Aug 30, 2005 4:16 pm

LVM1/2 is now available on the LRS ! http://lrs.linbox.org/wiki/WikiStartEn

The iso can be downloaded here: ftp://lrs.linbox.org/pub/lrs/iso/

crash3m
Posts: 9
Joined: Wed Jun 07, 2006 8:44 pm

heres my scripts to handle SW raid + LVM in linux (SuSE 10)

Post by crash3m » Wed Jun 07, 2006 9:40 pm

These are the scripts I use to backup and restore a system using raid1+LVM, this script assumes a LOT of things (like nothing will ever blow up, as there is currently no error checking, future versions will have this) see comments next to commands for more information.


(createimage.sh)
#!/bin/bash

#I drop everything into /mnt/custom, then cp into the isoroot directory, as when you re-run the script the isoroot directory is overwritten


mount /dev/hdb1 /mnt/custom #I put everything on a seperate drive, so I dont have to regenerate images every time I want to build an iso
sysrescuecd-custom extract #standard step
sysrescuecd-custom cloop 300 20000 #standard step
vgchange -ay #activate LVM
vgcfgbackup --file /mnt/custom/lvmcfg.backup #backup LVM information
cp -a /mnt/custom/lvmcfg.backup /mnt/custom/customcd/isoroot/ #copy LVM information into place
partimage -d -b -z1 -M save /dev/system/root /mnt/custom/root.img #image root FS
partimage -d -b -M -z0 save /dev/system/var /mnt/custom/var.img #image var FS
partimage -d -b -M -z0 save /dev/system/tmp /mnt/custom/tmp.img #image tmp FS
partimage -d -b -z0 save /dev/md0 /mnt/custom/boot.img #image boot "partition"
cp -a /mnt/custom/*.img.000 /mnt/custom/customcd/isoroot/ #move images into place
cp /mnt/custom/autorun /mnt/custom/customcd/isoroot #move autorun into place
cp -a /mnt/custom/backup-sda.sf /mnt/custom/customcd/isoroot/ #move sfdisk backups into place
cp -a /mnt/custom/backup-sdb.sf /mnt/custom/customcd/isoroot/
cp -a /mnt/custom/sdambr.img /mnt/custom/customcd/isoroot/ #move mbr backups into place
cp -a /mnt/custom/sdbmbr.img /mnt/custom/customcd/isoroot/
chmod 755 /mnt/custom/customcd/isoroot/autorun #set 755 on autorun, so it will run
sysresccd-custom setkmap us #set default keymap so no one is prompted
sysresccd-custom isogen myclone #build iso
cd / #get out of /mnt/custom so umount wont fail
umount /mnt/custom #umount /mnt/custom
sync #sync data to disks so no info is lost
exit 0 #exit 0 regardless, I will add error-checking in the future

(autorun)
#!/bin/bash

dd if=/mnt/cdrom/sdambr.img of=/dev/sda #move MBR's back into place
dd if=/mnt/cdrom/sdbmbr.img of=/dev/sdb
sfdisk /dev/sda < /mnt/cdrom/backup-sda.sf #move sfdisk info back into place, this has 'extended partition information' that may or may not be needed...
sfdisk /dev/sdb < /mnt/cdrom/backup-sdb.sf
/etc/init.d/udev force-reload #reload udev so that the partitions will be created in /dev
mknod /dev/md/1 b 9 1 #create md 1 device so I can work with raid
ln -s /dev/md/1 /dev/md1 #symlink md1, out of habit
mdadm -C -R /dev/md0 -c 4096 -l1 -n2 /dev/sda1 /dev/sdb1 #create md0/md1 in raid 1, with 2 devices, without question
mdadm -C -R /dev/md1 -c 4096 -l1 -n2 /dev/sda2 /dev/sdb2
pvcreate --uuid ASDFASDFASDFASDFASDF /dev/md1 #no, this isnt the real UUID... you'll use the UUID of your physical volume, you can find this from pvscan IIRC... this sets up the PV so that vgcfgrestore can do its thing
vgcfgrestore --file /mnt/cdrom/lvmcfg.backup system #restore LVM information
vgchange -ay #activate LVM
partimage -e -b restore /dev/md0 /mnt/cdrom/boot.img.000 #restore images
partimage -e -b restore /dev/system/root /mnt/cdrom/boot.img.000
partimage -e -b restore /dev/system/var /mnt/cdrom/var.img.000
partimage -e -b restore /dev/system/tmp /mnt/cdrom/tmp.img.000
mkswap /dev/system/swap #make swap, swap
vgchange -an #disable LVM
sync #sync data do disk
echo "dont forget to let your RAID sync!"
exit 0 #exit 0, regardless


There may be typo's, logical errors, and general idiocy in these scripts...I can NOT be held liable.

USE THESE AT YOUR OWN RISK! DATA CAN, MAY, AND LIKELY WILL BE LOST IF YOU DONT KNOW WHAT YOUR DOING!!!!!

This is distributed under the free beer license. Do as you will with it, copy it, take credit for it, but if you like it buy me a beer.

crash3m
Posts: 9
Joined: Wed Jun 07, 2006 8:44 pm

update (issues with grub)

Post by crash3m » Fri Jul 07, 2006 4:01 pm

After having others test this script, its become apparent that grub has issues, but just needs to be reinstalled to the MBR...easily enough done. I just add this to the bottom of my autorun script

/sbin/grub --batch <<EOT 1>/dev/null 2>/dev/null
root (hd0,0)
setup (hd0)
root (hd0,0)
setup (hd1)
quit
EOT

note that root doesnt change, this is in case one drive dies in the RAID...

crash3m
Posts: 9
Joined: Wed Jun 07, 2006 8:44 pm

Post by crash3m » Fri Jul 07, 2006 4:10 pm

I found a new tool that promises to support LVM and RAID out of the box (though its FS support is limited)

http://www.trickytools.com/php/clonesys.php

librelrs
Posts: 11
Joined: Fri Sep 15, 2006 9:38 am
Contact:

Post by librelrs » Fri Sep 15, 2006 10:13 am

crash3m wrote:I found a new tool that promises to support LVM and RAID out of the box (though its FS support is limited)

http://www.trickytools.com/php/clonesys.php
But don't forget the LRS is GPLed, and just works with LVM1/2 :) No need to script anything !
You can even build a bootable restoration DVD from your LVM image.
http://lrs.linbox.org

Cheers,
Ludo.

deisner
Posts: 1
Joined: Fri Sep 15, 2006 9:58 pm
Contact:

Post by deisner » Fri Sep 15, 2006 10:02 pm

librelrs wrote:But don't forget the LRS is GPLed, and just works with LVM1/2 :) No need to script anything !
I'm looking for a solution that will let me boot my laptop from a CD, save my LVM partition to a USB drive, and later on recover the partion from the USB drive.

If I understand correctly, LRS requires me to setup a second machine as a server, and to communicate over the network with it. Is that right?

Thanks.

-David

markarnold
Posts: 2
Joined: Tue Jan 09, 2007 11:35 pm

Post by markarnold » Wed Jan 10, 2007 5:28 pm

I just booted from the SystemRescueCD that the partimage page refers to and used mdadm to manually mount my software raid1 /dev/md0 onto the two physical partitions.
Then I started partimage and it turns out that it does allow me to take a backup of /dev/md0.

So it seems like it is not entirely unsupported - it just requires some manual intervention (mdadm) - and on the flipside the same when restoring.

MARK

complexnumber
Posts: 1
Joined: Tue Feb 27, 2007 10:36 pm

Post by complexnumber » Tue Feb 27, 2007 10:38 pm

markarnold wrote:I just booted from the SystemRescueCD that the partimage page refers to and used mdadm to manually mount my software raid1 /dev/md0 onto the two physical partitions.
Then I started partimage and it turns out that it does allow me to take a backup of /dev/md0.

So it seems like it is not entirely unsupported - it just requires some manual intervention (mdadm) - and on the flipside the same when restoring.

MARK
Can anyone give a more elaborate example on that? I'm not familiar with mdadm or arrays in general, I was able to backup the partition but now I can't get partimage to restore it.

thanks

KBorders01
Posts: 1
Joined: Thu Aug 27, 2009 1:00 pm
Contact:

What about Partimage with RAID but no LVM?

Post by KBorders01 » Thu Aug 27, 2009 1:35 pm

I was also able to save disk images with partimage from a disk using software raid. I restored the MBR, as well as /dev/sd[ab]1 and /dev/sd[ab]3, then linked them to /dev/md0 (boot) and /dev/md1 (/) with mdadm, respectively. I am getting the following errors upon booting up:

mdadm: no devices found for /dev/md1
Unable to access resume device (UUID=1dc07df1-2ea4-4642-8907-16d92d6ed89e)
mount: error mounting /dev/root on sysroot as ext3: Invalid argument

That particular UUID is under my /etc/fstab file as one of the swap partitions. It looks like I forgot a step somewhere along the way, but I'm not sure how to fix it. Anyone have any ideas?

Post Reply