Search This Blog

Monday, May 28, 2018

Making a RAID1 volume on Centos7 with mdadm that stays persistent upon reboot

The normal online guides didn’t work for me (example links 1 2). I could create one, and it would work fine. But the raid array, which I wasn’t even booting off of, would fail during boot, which caused a bunch of other failures, which would cause CentOS to boot into emergency mode. No way to even get the gui to boot (I tried). When I commented out the raid array line in fstab and rebooted, CentOS would boot fine, but there was no sign that the previously perfectly working raid array…no recognized superblocks, nothing, so I couldn’t assemble or start it again. Here’s the process that eventually worked.
  1. lsblk –figure out which disks you want to raid 
  2. If you already have a raid running that you want to kill and remake, follow this guide
  3. Delete partitions on the disks using ?? or the disk utility. 
  4. Run the command sudo dd if=/dev/zero of=/dev/sda bs=1M count=500000 , where sda is the disk you want to over write with zeros, and count is the size of the device in MB. The goal is to wipe out any metadata (filesystems, etc…) left on the disk from previous fails. You can kill it after a few minutes…just need to wipe first few sectors usually 
  5. Contents in the disk utility should say “unknown” now. If it says free space or unallocated space, go back and run the zeroing command longer 
  6. Now create the partitions. There are pros and cons to making the raid of partitions or the actual disks. I used partitions. 
    1. link
    2. sudo parted /dev/sda
      1. (parted) print – to check to see if a partition exists. If these are blank drives there should be no partition. If a partition exists, go back to main step 2. If a file system exists, go back to main step 3.
      2. (parted) mklabel gpt – sets disk to GUID partition label. 
      3.  (parted) print – check to see if a GPT partition label was created. 
      4. (parted) mkpart primary 0% 100% - Create a single primary partition aligning sectors and using all available space on drive. 
      5. (parted) set 1 raid on – Marks partition of type "Linux raid". 
      6. (parted) align-check optimal 1 – Checks for alignment of partition “1” we just created. 
      7. (parted) print – Final check to determine if the primary partition was created properly with the appropriate partition label and marked for software raid. 
      8. (parted) quit 
    3. sudo gdisk -l /dev/sda (checks partition information)
    4. Repeat above for other disk (sdb for me) 
  7. Create raid array: sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1 
    1. Make sure to use sda1, not sda, unless you are doing this on the drives and not the partitions. 
    2. Commands for checking progress of syncing (will take a few hours): 
      1. cat /proc/mdstat 
      2. mdadm –detail /dev/md0 
    3. You may not have to wait for it to finish to continue, but I do to be safe. 
  8. Make filesystem and mount: 
    1. Could create logical volumes before creating the files system and mounting, but don’t have to: link 
    2. sudo mkfs.ext4 –F /dev/md0 
    3. sudo mkdir /data 
    4. sudo chown (username) /data (use your username if you don’t want to have to sudo everytime you copy something to this, otherwise leave this step out) 
    5. sudo chmod 775 /data (use whatever you need here) 
    6. sudo mount /dev/md0 /data 
    7. Try writing something to the raid. “touch test” or something like that. 
  9. Create mdadm.conf file, which is used at boot to build the array: 
    1. mdadm --detail --scan > /etc/mdadm.conf 
    2. I did not use this one: mdadm --examine --scan --config=mdadm.conf >> /etc/mdadm.conf 
    3. explanation  of differences
    4. Note: > : if file exists, it will be replaced. >>: if file exists, it will be appended 
    5. possibly useful link 
  10. Edit fstab so it is persistent across reboots 
    1. vi /etc/fstab 
    2. add line: /dev/md0 /data ext4 defaults 0 0 
  11.  Need to rebuild initial ramdisk image (initramfs). Create backup first, then rebuild. 
    1. link 1 
    2. link 2
    3. cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
    4. ll /boot/initramfs-$(uname -r).img*
    5. dracut -f
  12. Reboot. If it works, YAY! If it doesn’t, try again!

No comments:

Post a Comment