Sample Header Ad - 728x90

How do I clone a single drive onto a new RAID 1 array?

3 votes
1 answer
4328 views
I'm maintaining a DELL Precision T7600, which lost a hard-drive. Just the /home directory was on it and has been recovered. I've been tasked with making a RAID 1 of the OS drive so that our downtime is minimized. I read about hard-drive cloning on the Arch-Linux wiki, and am currently following these two guides , leaning on the first for the grub2 configuration, but I could not wrap my head around it. Perhaps it is a simple dd if=/dev/sdc of=/dev/md126 command. Is dding to an array from a device file possible or recommended? * I tried dding to the /dev/md0 device, but it was a bit smaller than the original, so I got an error from dd about not being able to copy to /dev/md0. I tried to boot off of this array, but ran into error: file '/grub/i386-pc/normal.mod' not found. and was put into a grub rescue>, which I don't know what to do with. So I tried to mount the array in order to do a grub-install on it, but mount told me: unknown filesystem type 'linux_raid_member' * I ran this command to clone my OS drive to the two blank drives:
-sh
    sudo pv /dev/sdc | tee >(dd of=/dev/sda) >(dd of=/dev/sdb) | dd of=/dev/null
This cloned my OS drive successfully, without grub errors like the 1st attempt. Grub loaded, but would not boot the OS, and I was thrown into dracut emergency mode. * I got out of this by issuing the following commands from my LiveUSB
-sh
    sfdisk -d /dev/sdc | sfdisk /dev/sda
and ditto for sdb. * Fedora loaded this time, but I was thrown into emergency mode, which is caused in my case by inexistant /etc/fstab entries. So I pruned the fstab to only mount the / partition. * Now I ran:
-sh
    sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda /dev/sdb
from my Live USB stick to create the array, but after the drives were still not bootable. So I had to re dd the sdc2 and sdc3 partitions, to their respective sdb partitions. And I'm back at square one. * This time I decided to create 3 separate RAID partitions. And created a file called /etc/grub.d/09_raid1_setup:
menuentry 'Fedora RAID 1' --class fedora --class gnu-linux --class gnu --class os {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        insmod mdraid1x
        set root='(md/2)'
        search --no-floppy --set=root /dev/md2 
        linux /vmlinuz-3.18.9-100.fc20.x86_64 root=/dev/md3 ro
        initrd /initramfs-3.18.9-100.fc20.x86_64.img
    }
* Then I recreated the new /boot/grub2/grub.cfg with grub2-mkconfig -o /boot/grub2/grub.cfg and ran dracut -f /boot/initramfs-currentimage to update the initramfs. * I made the mistake of not changing the partition table of sdb to match that of sda, which looks like:
Part. #     Size        Partition Type            Partition Name
    ----------------------------------------------------------------
             1007.0 KiB  free space
    1        1024.0 KiB  BIOS boot partition
    2        500.0 MiB   Linux RAID
    3        97.7 GiB    Linux RAID
    4        2.6 TiB     Linux RAID
             455.5 KiB   free space
until after I had created the initramfs image and updated grub.cfg. * The output of lsblk now looks like:
NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
    sda       8:0    0   2.7T  0 disk  
    ├─sda1    8:1    0     1M  0 part  
    ├─sda2    8:2    0   500M  0 part  
    ├─sda3    8:3    0  97.7G  0 part  /
    └─sda4    8:4    0   2.6T  0 part  
    sdb       8:16   0   2.7T  0 disk  
    ├─sdb1    8:17   0     1M  0 part  
    ├─sdb2    8:18   0   500M  0 part  
    │ └─md2   9:2    0 499.7M  0 raid1 /boot
    ├─sdb3    8:19   0  97.7G  0 part  
    │ └─md3   9:3    0  97.6G  0 raid1 
    └─sdb4    8:20   0   2.6T  0 part  
      └─md4   9:4    0   2.6T  0 raid1 
    sdc       8:32   0   2.7T  0 disk  /home
* And /etc/fstab is:
/dev/md3 /                       ext4    defaults        1 1
    /dev/md2 /boot                   ext4    defaults        1 2
    UUID=f9fba42e-80f4-41b1-b309-88b22f642907 /home                 ext4    defaults        1 2
After research , reading , and general googling , I can't find answers.
Asked by rivanov (271 rep)
Nov 10, 2015, 12:15 AM
Last activity: Jan 8, 2025, 10:21 AM