Making a remote Dell PE1600SC at The Planet use software RAID
We just got another server at The Planet. They had a deal on another of the same 1600SC’s we got before: dual Xeon, but this time with dual 10k 136GB SCSI disks.
They offer CentOS 5 now. (When we bought our last one, they only
offered RHEL 3, which I had to remotely upgrade to CentOS 4.) When
they turn the server over to you, you’ve got /, /boot, swap, and
then /dev/sdb is one big partition. My task: change it to LVM on
software RAID 1.
I don’t think their web site mentions it, and there was some question
about whether they still offer it, but this newest server still has a
Dell DRAC III card in it, which I needed to toy with grub (when I
screwed up). You could probably do without remote console access,
except (1) it will be hard to see errors, and (2) I don’t recall if
grub has a functionality similar to lilo -R (“for the next boot
only, use boot entry N”) these days.
Here are my rough steps to complete this task. This is based partly on what I did, partly what I should have done, and it’s all from memory (granted, memories that are scant hours old). Note that you probably don’t want to do this on a “production” machine (duh), as this will require reboots and potentially horking things. I did it on a fresh install that I wasn’t afraid to have reinstalled; you’ve been warned.
- Partition
/dev/sdb. For me, that’s 128MB/dev/sda1as/boot, and the rest in/dev/sdb2. Both types0xfdfor RAID auto-detect. I setsdb1, which will be software RAID 1 for/boot, to be an “active” (AFAIK means “can boot off of here”) partition, in casesda1fails. - Create the software RAID devices. For
/boot, this like likemdadm --create -l 1 -n 2 /dev/md0 missing /dev/sdb1.missingis the word I always forget: it says “the disk that would normally go in this slot is… well, missing.” Repeat for/dev/md1with/dev/sdb2. -
pvinit,vgcreate, and thenlvcreateall the logical volumes you want. -
mkfsor equivalent on all your new devices. For the record, I found out RH’s anaconda does something likemke2fs -j -i <inode size> <device>. I left out the-i. Other options formke2fsare apparently read from/etc/mke2fs.conf. Aftermke2fsanaconda seems to dotune2fs -i0 -c0 -ouser_xattr,acl -Odir_index <device>. (This is from memory, I hope it’s right.) Don’t forget toe2labeleverything too. RHEL 5’smkswapapparently takes-Lto set a label, which you can use in/etc/fstab. - Mount up your new, empty filesystem(s) somewhere. I made and used
/mnt/sdb. -
Edit
grub.conf. Note on my system,/etc/grub.confwas not symlinked to the actual file,/boot/grub/grub.conf. If you see this I don’t see why you shouldn’trm /etc/grub.conf && ln -s ../boot/grub/grub.conf /etc/grub.conflike I did.In
grub.confyou want to make a copy of your currently booted stanza. In this copy, change theroot (hd0,0)to beroot (hd1,0), and also change theroot=LABEL=/in thekernelline to point at something likeroot=/dev/vgmain/lvroot(or wherever your root FS is).Also, for people like me on a DRAC III, you’ll want to comment out any
bootsplashorhiddenmenulines, you don’t need any serial console (I commented out bothserialandterminallines for GRUB and also removedconsole=...parameters to the kernel). You may want to bump up thetimeout. Additionally, DRAC III users will need to addi8042.dumbkbd=1to thekernel“command line.” I don’t think this is necessary… but I did add
(hd1) /dev/sdbto/boot/grub/device.mapand I also re-ran/sbin/grub-install.- Copy everything from the running filesystems to the new
filesystem(s). I used
cd /; find . -xdev -print | cpio -pvdm /mnt/sdb/to do this, and then the same with/boot. Jumping ahead some steps, after I finally got the new arrays booted, I don’t think this copied the SELinux labels right, which is no good. I encourage you to find a command that does copy the SELinux labels. Maybestarcan help? Orcp -ax? If you use my method, go ahead and touch.autorelabelin the root of your new filesystem, which should cause SELinux relabelling at boot. -
chrootto your new FS.mount /proc && mount /sys. - Edit
/etc/fstabon the new FS to reflect your new layout. I note that a fresh CentOS 5 install using LVM on RAID doesn’t useLABEL=...syntax for selecting devices, so I’d put actual device names for everything on software RAID or LVM in column 1 offstab. Note that I never gotmkinitrdto run correctly (i.e. include the LVM stuff) as long as I was usingLABEL=/for my/partition. - This is kind of weird: I think you need the device nodes hanging
around to ensure that
mkinitrdworks right in the next step, so runstart_udev. The weird part: this is going to kill the runningudevdand replace it with one whose/points to your new root. I was able to finish my work and reboot my system withoutudevdrunning on my real root; hopefully your mileage won’t vary. - If you’re using LVM like me, you need to run
vgmknodesnow, to make things like/dev/vgmain/lvroot(example name). - Now it’s time to run
mkinitrd.rmthe existinginitrdin/bootand runmkinitrdwith the-vswitch. Make sure it pulls inlvm(and look forlvm.conftoo). - Theoretically you’re now ready to go, and it’s time to reboot.
(Last chance to
touch /.autorelabel.)killall udevd; umount sys && umount proc && exitto get out of the chroot.umountthe rest of the stuff for fun, maybevgchange -a nand thenmdadm --stopall your new RAID devices (since I’m paranoid and not sure if RHEL would do this for me, since they weren’t there at boot), and reboot. - Hopefully you can now select your new GRUB entry at boot, and boot
from your new disks. (If you touched
.autolabelyou’re in for an extra reboot.) Once it boots, log in and make suremountlooks right, with your new LVM/RAID devices. Also check/proc/swapsto make sure the right swap device is being used. - Once you’re sure you’re OK, and you don’t want anything off the
old disk,
sfdisk --dump /dev/sdb | sed 's/sdb/sda/g' | sfdisk /dev/sdato copy the partition table fromsdbtosda. -
mdadm --manage --addthesdapartitions to the RAID devices. - Wait for resync (i.e. bounce on
cat /proc/mdstat). - Now go back to
grub.conf, take out your extra entry (the one using(hd1,0)). Change the old entry (in mygrub.confI now only had one entry) to use the real root device path, so (ex.)root=/dev/vgmain/lvroot) instead ofroot=LABEL=/. - Make sure
/etc/fstablooks right still. Again, I recommend against usingLABEL=syntax for anything on software RAID or LVM. - I re-ran
mkinitrdwith-v, more than anything just to make sure it worked right. (Again: if your/is on LVM, make sure you see things likelvm.confbeing put on the initrd. I didn’t the first time I did this, and it turned out to be because I was usingLABEL=...syntax in/etc/fstabfor/.) - Optional: I wrote a GRUB boot sector to
sdbas if it were the first disk in the system. Rungrub,device (hd0) /dev/sdb,root (hd0,1),setup(hd0). You can check that GRUB is now onsdbwith something likedd if=/dev/sdb bs=512 count=1 | strings | grep GRUBand you should seeGRUBas output. - Reboot (and pray, perhaps).
Once you’ve rebooted this last time you’ll probably want to look at
mount to make sure everything is still where it should be, check
your swap is on, and check /proc/mdstat to make sure the arrays are
OK. In my case, and slightly to my surprise, everything was OK.
Sorry to the folks at The Planet if my turning off serial console stuff in GRUB/the kernel screws them up. (Feel free to drop me a line and I’ll turn it back on and update these instructions.)