- lsblk –figure out which disks you want to raid
- If you already have a raid running that you want to kill and remake, follow this guide
- Delete partitions on the disks using ?? or the disk utility.
- 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
- 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
- Now create the partitions. There are pros and cons to making the raid of partitions or the actual disks. I used partitions.
- link
- $ sudo parted /dev/sda
- (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.
- (parted) mklabel gpt – sets disk to GUID partition label.
- (parted) print – check to see if a GPT partition label was created.
- (parted) mkpart primary 0% 100% - Create a single primary partition aligning sectors and using all available space on drive.
- (parted) set 1 raid on – Marks partition of type "Linux raid".
- (parted) align-check optimal 1 – Checks for alignment of partition “1” we just created.
- (parted) print – Final check to determine if the primary partition was created properly with the appropriate partition label and marked for software raid.
- (parted) quit
- sudo gdisk -l /dev/sda (checks partition information)
- Repeat above for other disk (sdb for me)
- Create raid array: sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
- Make sure to use sda1, not sda, unless you are doing this on the drives and not the partitions.
- Commands for checking progress of syncing (will take a few hours):
- cat /proc/mdstat
- mdadm –detail /dev/md0
- You may not have to wait for it to finish to continue, but I do to be safe.
- Make filesystem and mount:
- Could create logical volumes before creating the files system and mounting, but don’t have to: link
- sudo mkfs.ext4 –F /dev/md0
- sudo mkdir /data
- 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)
- sudo chmod 775 /data (use whatever you need here)
- sudo mount /dev/md0 /data
- Try writing something to the raid. “touch test” or something like that.
- Create mdadm.conf file, which is used at boot to build the array:
- mdadm --detail --scan > /etc/mdadm.conf
- I did not use this one: mdadm --examine --scan --config=mdadm.conf >> /etc/mdadm.conf
- explanation of differences
- Note: > : if file exists, it will be replaced. >>: if file exists, it will be appended
- possibly useful link
- Edit fstab so it is persistent across reboots
- vi /etc/fstab
- add line: /dev/md0 /data ext4 defaults 0 0
- Need to rebuild initial ramdisk image (initramfs). Create backup first, then rebuild.
- link 1
- link 2
- cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
- ll /boot/initramfs-$(uname -r).img*
- dracut -f
- Reboot. If it works, YAY! If it doesn’t, try again!
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment