Robert Heller wrote:
At Wed, 9 Jun 2010 16:50:53 -0700 CentOS mailing list centos@centos.org wrote:
Hi,
I've used mdadm for years now to manage software raids.
The task of using fdisk to first create partitions on a spare drive sitting on a shelf (raid 0 were my 1st of 2 drives failed) is kind of bugging me now.
After using fdisk to create the same partition layout on the new drive as is on the existing drive and then using mdadm to finish every thing up is a little tedious.
Any one have an idea how to have a sort of hot plug were I just swap out the drive and it rebuilds?
sfdisk is your friend (from man sfdisk):
-d Dump the partitions of a device in a format useful as input to sfdisk. For example, % sfdisk -d /dev/hda > hda.out % sfdisk /dev/hda < hda.out will correct the bad last extended partition that the OS/2 fdisk creates.
So:
- plug in replacement disk.
- partition it:
# sfdisk -d /dev/sdX | sfdisk /dev/sdY
Where /dev/sdX is an existing disk and /dev/sdY is the replacement disk
- add the partition(s) to the array(s):
# mdadm /dev/mdI ... -a /dev/sdYI # mdadm /dev/mdJ ... -a /dev/sdYJ # mdadm /dev/mdK ... -a /dev/sdYK # mdadm /dev/mdL ... -a /dev/sdYL
No reason not to put all of the above in a script...
Agreed. And I have... :)
The script is designed to add a third drive to a raid1 set. I use this with a removable drive to get a backup of the system that can be taken off-site.
The sleeps in this script are probably a bit excessive, but they are designed to let the system fully process each command before the next one is given. I found that certain things would not work properly without a pause in there. Since I only run this once a month, it's not a big deal if it takes a couple of minutes to run.
Just posting this in case it proves useful to anyone.