I have outlined below the steps taken to move from a normal single disk system and convert to a raid1 using an additional drive:
Note: /boot cannot be on lvm nor any other raids other than raid1 partition.
Don't forget to make the essential backups prior.
Convert / to raid/lvm
-
fdisk /dev/sdb and make clone of sda (convert partition type to "Linux raid autodetect")
add /dev/sdb1 -- /boot - 13 blocks (100Mb) - type raid
add /dev/sdb2 -- rest - type raid
Create raid partitions:
partprobe
mdadm -C /dev/md0 --auto=yes -l 1 -n 2 missing /dev/sdb1
mdadm -C /dev/md1 --auto=yes -l 1 -n 2 missing /dev/sdb2
pvcreate /dev/md1
vgcreate vg0 /dev/md1
lvcreate -L 4G -n lv0 vg0
mke2fs -j /dev/vg0/lv0
mkdir /mnt/lv0
mount /dev/vg0/lv0 /mnt/lv0
find / -xdev | cpio -pvmd /mnt/lv0
cp -aux /dev /mnt/lv0
/dev/vg0/lv0 /   ;   ;   ;   ; ext3 defaults &nbs p; 1 1
mount --bind /dev /mnt/lv0/dev
chroot /mnt/lv0
mount -t proc /proc /proc
mount -t sysfs /sys /sys
vgscan
vgchange -ay
mkinitrd -v /boot/initrd-`uname -r`.lvm.img `uname -r`
umount /sys
umount /proc
exit
mv /mnt/lv0/boot/initrd-`uname -r`.lvm.img /boot
reboot
Convert /boot to raid1
-
Upon successful reboot
Create file-system and copy /boot partition files over:
mke2fs -j /dev/md0
mkdir /mnt/md0
mount /dev/md0 /dev/mnt0
cp -aux /boot/* /mnt/md0
umount /mnt/md0
umount /boot
Add /dev/sda1 to /dev/md0 raid
partprobe
mdadm /dev/md0 -a /dev/sda1
/dev/md0 /boot ext3 defaults 1 2
mount /boot
# grub
grub> root (hd1,0)
grub> setup (hd1)
grub> root (hd0,0)
grub> setup (hd0)
grub> find /boot/grub/stage1 {to confirm}
(hd0,0)
(hd1,0)
grub> quit
title CentOS-LVM-HD0 (2.6.18-92.1.6.el5)
&nbs p; root (hd0,0)
&nbs p; kernel /vmlinuz-2.6.18-92.1.6.el5 ro root=/dev/vg0/lv0 console=tty0 console=ttyS1,19200n8
&nbs p; initrd /initrd-2.6.18-92.1.6.el5.lvm. img
title CentOS-LVM-HD1 (2.6.18-92.1.6.el5)
&nbs p; root (hd1,0)
&nbs p; kernel /vmlinuz-2.6.18-92.1.6.el5 ro root=/dev/vg0/lv0 console=tty0 console=ttyS1,19200n8
&nbs p; initrd /initrd-2.6.18-92.1.6.el5.lvm. img
shutdown -r now
Create swap on raid1 and add sda2 to raid1:
-
Create logical volume swap.
swapoff -a
lvcreate -L 4G -n lv-swap vg0
mkswap -L SWAP-md1 /dev/vg0/lv-swap
LABEL=SWAP-md1 swap swap pri=0,defaults &nbs p; 0 0
swapon -a
partprobe
mdadm /dev/md1 -a /dev/sda2
- sandip's blog
- Login or register to post comments
Comments
On CentOS-6.0, I've had to set the raid metadata to the old 0.90 version for grub-install to work.
mdadm -C /dev/md0 --auto=yes --metadata=0.90 -l 1 -n 2 /dev/sda1 /dev/sdb1
Also, check "/etc/mdadm.conf" to make sure that the raid device is auto-detected at the next boot. It should include "+0.90" in the "AUTO" line and before "-all".
AUTO +imsm +1.x +0.90 -all
Then either use the label or UUID of device in "/etc/fstab" mounts file.
You can label via:
e2label /dev/md0 /boot
Find the UUID via:
blkid /dev/md0
This was very helpful. I did have one problem though. After rebooting I could not log back in on the new raid partition. Login just quickly returned with failure. ssh'd to the host and saw /bin/bash: permission denied. Googled that and found many references to file system permissions. I couldn't see any problems when I booted back to my non-raid setup and mounted the raid one. I did a clean mkfs on the raid side, and did:
cd /mnt/lv0
dump -0 -f - / |restore -r -f -
cd /
cp -aux /dev /mnt/lv0/
Rebooted and that worked. The cpio should have worked. Maybe I messed it up somewhere else. At any rate, thanks for the instructions.
Andy
I had the exact same problem with cpio on selinux enabled Fedora 11
Thanks for the dump/resore hint!
And thanks for this howto. It was so helpful!
Thank you for the step-by-step instructions, it worked for me. This area is not covered well in the documentation to both RAID and LVM.
cheers, Martin