Linux

Manually recreate RAID1 with file backup of CENTOS

Boot new machine with CENTOS LiveCD.

Creating swap, boot and root partition

fdisk /dev/sda
# create swap
n
p
1
enter
+16G
# create boot
n
p
2
enter
+512M
# create root partition
n
p
3
enter
+225G
# change partition to raid
t
1
fd
t
2
fd
t
3
fd
# activate boot on 2nd partition
a
2
w
fdisk /dev/sdb
#repeat above steps.

Verify partitions

fdisk -l /dev/sda
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000566e
Device Boot Start End Blocks Id System
/dev/sda1 2048 33556479 16777216 fd Linux raid autodetect
/dev/sda2 * 33556480 34605055 524288 fd Linux raid autodetect
/dev/sda3 34605056 506464255 235929600 fd Linux raid autodetect
fdisk -l /dev/sdb
Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000567b2
Device Boot Start End Blocks Id System
/dev/sdb1 2048 33556479 16777216 fd Linux raid autodetect
/dev/sdb2 * 33556480 34605055 524288 fd Linux raid autodetect
/dev/sdb3 34605056 506464255 235929600 fd Linux raid autodetect

Create RAID partitions

mdadm -C /dev/md0 --metadata=1.1 --level=1 --raid-devices=2 --name=ramdisk /dev/sda1 /dev/sdb1
mdadm -C /dev/md1 --metadata=1.0 --level=1 --raid-devices=2 --name=bootdisk /dev/sda2 /dev/sdb2
mdadm -C /dev/md2 --metadata=1.1 --level=1 --raid-devices=2 --name=root /dev/sda3 /dev/sdb3

Format RAID partitions

mkfs.ext3 /dev/md0 && mkfs.ext3 /dev/md1 && mkfs.ext4 /dev/md2
# format swap partition
mkswap /dev/md0

Mount partitions

mkdir /mnt/s
mount /dev/md2 /mnt/s
mkdir /mnt/s/boot
mount /dev/md1 /mnt/s/boot

Copy TAR backup from backup server to local disk

rsync --progress -av yourBackupServer:/yourBackupFile.tgz /mnt/s/

Extract TAR backup local disk

cd /mnt/s && tar -zxvf de6.tgz

Mount system partitions

mkdir /mnt/s/dev 
mkdir /mnt/s/proc 
mkdir /mnt/s/sys 
mount --bind /dev /mnt/s/dev/
mount --bind /proc /mnt/s/proc/
mount --bind /sys /mnt/s/sys/

Chroot

chroot /mnt/s /bin/bash

Update mdraid configuration

mdadm --examine --scan >> /etc/mdadm.conf

Verify mdraid configuration

cat /etc/mdadm.conf
# mdadm.conf written out by anaconda
MAILADDR root
AUTO +imsm +1.x -all
ARRAY /dev/md/ramdisk metadata=1.1 UUID=0711c371:dbb17d31:94eb870d:bda39400 name=rescue:ramdisk
ARRAY /dev/md/bootdisk metadata=1.0 UUID=0d7bbde6:9b8e6e58:061ba120:58999b0d name=rescue:bootdisk
ARRAY /dev/md/root metadata=1.1 UUID=2df86329:6cdd1e92:e42cc596:1290dea5 name=rescue:root

Update fstab with UUIDS of the newly created RAID partitions

ls /dev/disk/by-uuid/ -lha
total 0
drwxr-xr-x 2 root root 120 Sep 16 19:32 .
drwxr-xr-x 5 root root 100 Sep 16 19:29 ..
lrwxrwxrwx 1 root root 9 Sep 16 19:32 2838827a-499f-477d-8329-a6c42c780156 -> ../../md0
lrwxrwxrwx 1 root root 11 Sep 16 19:29 40c4ea95-0ecc-4c51-9f3e-e49d8f62f160 -> ../../loop0
lrwxrwxrwx 1 root root 9 Sep 16 19:32 5c94dc94-823b-4cc0-a848-827816eb56a3 -> ../../md1
lrwxrwxrwx 1 root root 9 Sep 16 19:32 f1d027bf-d2fc-499b-9db0-19f9b0780e28 -> ../../md2
vi /etc/fstab
UUID=2838827a-499f-477d-8329-a6c42c780156 none swap sw 0 0
UUID=5c94dc94-823b-4cc0-a848-827816eb56a3 /boot ext3 defaults 0 0
UUID=f1d027bf-d2fc-499b-9db0-19f9b0780e28 / ext4 defaults 0 0
<strong>Verify configuration</strong>
cat /etc/fstab
proc /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
UUID=2838827a-499f-477d-8329-a6c42c780156 none swap sw 0 0
UUID=5c94dc94-823b-4cc0-a848-827816eb56a3 /boot ext3 defaults 0 0
UUID=f1d027bf-d2fc-499b-9db0-19f9b0780e28 / ext4 defaults 0 0

Fix Grub on MBR record of both RAID1 disks

grub
root (hd0,1)
setup (hd0)
root (hd1,1)
setup (hd1)
quit
vi /boot/grub/grub.conf
#remove possibly logical volumes:   rd_LVM_LV=vg_livecd/lv_swap rd_LVM_LV=vg_livecd/lv_root
# add root partitions UUID
root=UUID=f1d027bf-d2fc-499b-9db0-19f9b0780e28
# add us keyboard KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 # add mdraid root partition + swap UUID: rd_MD_UUID=2df86329:6cdd1e92:e42cc596:1290dea5 rd_MD_UUID=0711c371:dbb17d31:94eb870d:bda39400
Verify configuration
cat /boot/grub/grub.conf
timeout 5
default 0
title CentOS (2.6.32-279.19.1.el6.x86_64) root (hd0,1) kernel /boot/vmlinuz-2.6.32-279.19.1.el6.x86_64 ro root=UUID=f1d027bf-d2fc-499b-9db0-19f9b0780e28 rd_MD_UUID=2df86329:6cdd1e92:e42cc596:1290dea5 rd_MD_UUID=0711c371:dbb17d31:94eb870d:bda39400 KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 rd_NO_LUKS rd_NO_DM nomodeset
initrd /boot/initramfs-2.6.32-279.19.1.el6.x86_64.img
mv /boot/initramfs-2.6.32-279.19.1.el6.x86_64.img /boot/initramfs-2.6.32-279.19.1.el6.x86_64.imgbackup
mkinitrd -f -v /boot/initramfs-2.6.32-279.19.1.el6.x86_64.img 2.6.32-279.19.1.el6.x86_64

Below is optional, but for my work mandatory

Fix network

vi /etc/hosts
yourIpAddress myserver.domain.com

vi /etc/sysconfig/network

HOSTNAME=your_custom_host.com
vi /etc/resolv.conf
nameserver IpOfYourNameServer
nameserver IpOfYourNameServer2
vi /etc/sysconfig/network-scripts/route-eth0
GATEWAY0=IpOfYourDefaultGateWay
vi /etc/sysconfig/network-scripts/ifcfg-eth0
#remove old hw address: HWADDR=XX:XX:XX:XX
IPADDR=YourIpAddress
NETMASK=YourSubnetMask
#remove entry in udev if your backup is restored to different machine 
vi /etc/udev/rules.d/70-persistent-net.rules
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:xx:xx:xx: af", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Restore to different hardware

If you are restoring the backup from a machine that used different hardware than the target server has, you have to recompile the kernel. If you have another machine that uses the same hardware of the target machine you could copy the kernel from that machine the following way:

<span style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px;">rsync -avz differentmachine:/lib/modules/2.6.32-358.14.1.el6.x86_64 /lib/modules/
</span>rsync -avz differentmachine:/boot/vmlinuz-2.6.32-358.14.1.el6.x86_64 /boot/
mkinitrd -f -v /boot/initramfs-2.6.32-358.14.1.el6.x86_64.img 2.6.32-358.14.1.el6.x86_64

If you still get errors when booting then compare the modprobe.d folder. Sometimes you have to blacklist specific modules to bypass bugs.

Troubleshooting

If rebooting does not work at all, just boot again with LiveCD. CENTOS LiveCD resets the MD numbering in reversed order and starting at md127. So md0 is md127, md1 md126 and md2 is md125. Mount your OS quickly this way:

mkdir /mnt/s
mount /dev/md125 /mnt/s
mkdir /mnt/s/boot
mount /dev/md126 /mnt/s/boot
mkdir /mnt/s/dev 
mkdir /mnt/s/proc 
mkdir /mnt/s/sys 
mount --bind /dev /mnt/s/dev/
mount --bind /proc /mnt/s/proc/
mount --bind /sys /mnt/s/sys/
chroot /mnt/s /bin/bash

More related posts