Loading...
 
[Zobrazit/Skrýt nabídky vlevo]
[Zobrazit/Skrýt nabídky vpravo]

CreateMDRaid

If there is a need to create a file copy of a HW server that uses MD RAID, it is necessary to transfer the partition table and RAID setup by hand. This is best to be done using a Live CD.

Boot the Live CD on a new server. Throughout this tutorial, it is assumed that the server has two hard drives mapped to /dev/sda and /dev/sdb.

1) Prepare the partition table. For illustration, we will create root (20G), var (10G), and swap (4G)

fdisk /dev/sda
o # deletes partition table
n # create a partition (p, 1, enter, +20G)
n # (p, 2, enter, +4G)
n # (p, 3, enter, +10G)
t # change partition type (1, fd)
# repeat for partition 2 and 3
p # show the new table
w # write changes


2) Copy the partition table to the other drive:

sfdisk -d /dev/sda > /tmp/table
sfdisk /dev/sdb < /tmp/table
rm -f /tmp/table


3) Create the RAID:

mdadm --create /dev/md0 -n 2 -l 1 --metadata=1.0 /dev/sda1 /dev/sdb1 # for root/boot
mdadm --create /dev/md1 -n 2 -l 1 /dev/sda2 /dev/sdb2
mdadm --create /dev/md2 -n 2 -l 1 /dev/sda3 /dev/sdb3


4) Create file systems:

mkfs.ext4 /dev/md0
mkfs.ext4 /dev/md2
mkswap /dev/md1


5) Mount the new root to a temporary location:

mkdir /mnt/root
mount /dev/md0 /mnt/root


6) Copy all files from the old server (unpack archive, rsync, ...):

tar -xzf root_data.tar.gz -C /mnt/root


7) Mount pseudo-file systems:

mkdir /mnt/root/proc /mnt/root/sys /mnt/root/var
mount none -t devtmpfs /mnt/root/dev
mount none -t proc /mnt/root/proc
mount none -t sysfs /mnt/root/sys


8) Save the MD RAID configuration to a file:

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


9) Now we have to get the root file system UUID and the UUID of the root MD RAID (here md0)

blkid | grep "md0" | awk '{print $2}'  # root device UUID
mdadm --examine /dev/sda1 | grep "Array UUID" | awk '{print $4}'  #RAID set drives UUID


10) Update kernel command line parameters in /boot/grub/menu.lst:

chroot /mnt/root
vim /boot/grub/menu.lst
#copy root dev UUID to kernel cmd line after root=, delete the double quotes
#copy root RAID set UUID to kernel cmd line after rd_MD_UUID=


11) Fixthe new server's /etc/fstab:

vim /etc/fstab
#change UUID's obtained by blkid for root, var, etc.


12) Set up grub:

grub
find /boot/grub/stage1 # find block devies containing grub (example (hd0,0), (hd1,0))
root (hdX,Y) #for bodth devices
setup (hdX) #for both devices


13) Rebuild init RAM disk:

dracut -f /boot/initramfs-<kernel-verion>.img <kernel-version>


... and you shall be all set. Just reboot the server:

reboot



Created by dfabian. Last Modification: Pondělí 02 of listopad, 2015 16:33:00 CET by dfabian.