Migrate Centos 7 from Single HDD to mdadm RAID 10 array:

Done on Centos 7.3 very important as clearly based on older guides it was a lot easier and more simpler!  Hint do not use grub2-install!

If you have trouble booting after this check this CentOS mdadm RAID booting/fixing guide.

One huge caveat if you are an oldschool user or sysadmin who has avoided UEFI booting

The normal way will not work here if your Centos was using UEFI.  Newer systems use it by default.

The easiest way to check is to do an fdisk -l if your system disk and check for an EFI partition.

If using EFI you need a EFI partition usually about 200M.

Instead of the typical partition 1 being normal boot this will now be EFI.

  • Partion 1 = EFI Boot 200M
  • Partition 2 = Boot 800M
  • Partition 3 = SWAP
  • Partition 4 = /
     

To match you will now have of course 4 mdadm arrays instead of 3 because of EFI.

Centos boot issue

#1 you MUST have an EFI partiton and you MUST be booted as UEFI!
a.)
So to make it more complicated with UEFI here is how a standard or at least Centos 7 typically works.

/boot partion mounted as /boot
/efi partition mounted as /boot/efi
b.) EFI partition can be mdadm RAID but must be level 1 and --metadata=1.0 and vfat filesystem
grub2-install --target=x86_64-efi /dev/sda
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

If you don't tell grub2-mkconfig to update the EFI grub.cfg you will be greeted to a blank grub boot screen with no menu entries.  No clue why grub2-mkconfig does not seem to update the correct EFI grub.cfg on its own.

#after booting getting another issue
dracut-initqueue: Warning: dracut-initqueue timeout -starting timeout scripts
Started dracut initqueue hook
Reached target Remote File Systems (Pre).
Reached target Remote File Systems.
A start job is running for dev-disk-by\x2uuid-8f411f86\x2d....device (7min 58s / no limit)

 

3 arrays:

md0  = /boot ext4

*(note md0 this must be --level 1 and --metadata=0.90 or it will not boot/work)

md1 = swap

md2 = / ext4

 

all mounted in /mnt/

 

 

#install grub2-tools so we can install it

yum -y install grub2-tools grub2-efi-modules

lack of efi modules gives the following error (if you didn't install the above): grub2-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. Please specify --target or --directory.


mkswap /dev/md1
Setting up swapspace version 1, size = 31440892 KiB
no label, UUID=a30ab8dd-f462-4dab-940d-6658bcae4395

get the UUIDs of each array:

blkid /dev/md0
blkid /dev/md1
blkid /dev/md2

/dev/md0: UUID="5b51dbfb-f361-48c3-bfdf-5da171e4577c" TYPE="ext4"
/dev/md1: UUID="a30ab8dd-f462-4dab-940d-6658bcae4395" TYPE="swap"
/dev/md2: UUID="8f411f86-3816-409b-b291-ebe1a7a170ef" TYPE="ext4"

mount /dev/md2 /target

rsync -Pha --exclude="/boot/*" --exclude="/sys/*" --exclude=/proc/* --exclude=/mnt/* / /target

mount /dev/md0 /target/boot

#if you have an EFI partition /dev/md3 or whatever you've used it for

mount /dev/md3 /target/boot/efi

#rsync the rest

rsync -Pha /boot/ /target/boot/

#if you have an EFI partition

rsync -Pha /boot/efi /target/boot/efi

Change /mnt/md2 to your mounted root /

 

mount=/target
for bind in dev sys proc; do
mount -o bind /$bind /$mount/$bind
done

 chroot /mnt/md2

#run the swapon command on your swap partition othewrise it soudns weird but mdadm WILL not activate the array even if it's in mdadm.conf. 

swapon /dev/md1

mdadm --detail --scan > /etc/mdadm.conf
 Update initramfs

#you must specify the exact initramfs image and exact kernel name (matching it) or it will not work/be unbootable - much more finicky than Centos 6
dracut /boot/initramfs-3.10.0-514.21.2.el7.x86_64.img 3.10.0-514.21.2.el7.x86_64 --force

#if you get a message like this you specified the wrong kernel details in the second parameter
Kernel version 3.10.0-514.21.2.el7 has no module directory /lib/modules/3.10.0-514.21.2.el7
#in the above case I forgot the .x86_64 at the end

dracut --mdadmconf --fstab --add="mdraid" --filesystems "vfat xfs ext4 ext3 tmpfs devpts sysfs proc" --add-drivers="raid1 raid10" --force 
#this dracut step is critical because by default it will not have mdadm raid support so it will keep looking for devcies that don't get created
#also MAKE sure to use the latest or current initramfs (may not be obvious ifyou are booting from a recovery disc).
dracut --mdadmconf --fstab --add="mdraid" --filesystems "xfs ext4 ext3 tmpfs devpts sysfs proc" --add-drivers="raid1 raid10" /boot/initramfs-3.10.0-514.21.2.el7.x86_64.img --force

Update grub2-config

#to avoid problems remove any old grub.cfg

echo y| rm /boot/efi/EFI/centos/grub.cfg

echo y| rm /boot/grub2/grub.cfg

grub2-mkconfig

#something went wrong as it doesn't boot

The above happens if you are running EFI and didn't specify output to your EFI partition for grub.cfg

If you have EFI

grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

#not sure why but the above still results in a blank grub screen with no menu entries.  Maybe grub2 needs to be reinstalled as a package or something else first.  I suspect it doesn't contain the right modules to read the boot or efi partition.

 

Install grub2:

#NO NO NO - DO NOT USE GRUB2-INSTALL

This Fedora warning explains it all:

Stop (medium size).png

grub2-install shouldn't be used on EFI systems. The grub2-efi package installs a prebaked grubx64.efi on the EFI System partition, which looks for grub.cfg on the ESP in /EFI/fedora/ whereas the grub2-install command creates a custom grubx64.efi, deletes the original installed one, and looks for grub.cfg in /boot/grub2/.

Solution just do a "yum reinstall grub2-efi"

One other solution is if you really want grub2-install is to make /boot/grub2/grub.cfg a symlnk to /boot/efi/EFI/centos/grub.cfg

ln -s /boot/efi/EFI/centos/grub.cfg /boot/grub2/grub.cfg this doesn't work I am certain grub cannot make use of that symlink

#if you get an error of "grub2-install: error /boot/efi doesn't look like an EFI partition"

It means you haven't mounted your EFI partition OR you haven't set the partition as EFI (in gdisk this is type ef00).   You'll have to stop the mdadm array for EFI and then do a mkfs.vfat on it and try again (partition must be VFAT and no other fs such as ext4/xfs etc.. it won't work unless it's VFAT).


Tags:

migrate, centos, hdd, mdadm, raid, array, guides, simpler, grub, install, caveat, oldschool, user, sysadmin, avoided, uefi, booting, newer, default, easiest, fdisk, disk, efi, partition, partion, swap, arrays, partiton, booted, typically, mounted, metadata, vfat, filesystem, _, dev, sda, mkconfig, redhat, cfg, update, greeted, entries, dracut, initqueue, timeout, scripts, uuid, min, md, ext, mnt, yum, modules, didn, usr, lib, modinfo, sh, doesn, specify, directory, mkswap, swapspace, kib, label, ab, dd, dab, bcae, uuids, blkid, quot, dbfb, bfdf, ebe, ef, mount, rsync, pha, exclude, sys, proc, ve, bind, chroot, swapon, othewrise, soudns, activate, conf, scan, etc, initramfs, kernel, matching, unbootable, finicky, img, specified, parameter, module, mdadmconf, fstab, mdraid, filesystems, xfs, tmpfs, devpts, sysfs, drivers, devcies, ifyou, disc, config, echo, rm, output, reinstalled, contain, fedora, shouldn, installs, prebaked, grubx, esp, whereas, creates, custom, deletes, installed, reinstall, symlnk, ln, symlink, haven, gdisk, ll, mkfs, fs,

Latest Articles

  • How to install Windows or other OS and then bring to another computer by using a physical drive and Virtual Machine with QEMU
  • PXE-E23 Error BOOTx64.EFI GRUB booting is 0 bytes tftp pxe dhcp solution NBP filesize is 0 Bytes
  • vagrant install on Debian Mint Ubuntu Linux RHEL Quick Setup Guide Tutorial
  • RHEL 8 CentOS 8, Alma Linux 8, Rocky Linux 8 System Not Booting with RAID or on other servers/computers Solution for dracut and initramfs missing kernel modules
  • How to Upgrade to Debian 11 from Version 8,9,10
  • Ubuntu Linux Mint Debian Redhat Cannot View Files on Android iPhone USB File Transfer Not Working Solution
  • Virtualbox Best Networking Mode In Lab/Work Environment without using NAT Network or Bridged
  • debootstrap how to install Ubuntu, Mint, Debian install
  • Linux grub not using UUID for the root device instead it uses /dev/sda1 or other device name solution
  • How To Restore Partition Table on Running Linux Mint Ubuntu Debian Machine
  • Debian Ubuntu apt install stop daemon questions/accept the default action without prompting
  • iptables NAT how to enable PPTP in newer Debian/Ubuntu/Mint Kernels Linux
  • Grandstream Phone Vulnerability Security Issue Remote Backdoor Connection to 207.246.119.209:3478
  • Linux How to Check Which NIC is Onboard eth0 or eth1 Ubuntu Centos Debian Mint
  • VboxManage VirtualBox NAT Network Issues Managment Troubleshooting
  • Dell PowerEdge Server iDRAC Remote KVM/IP Default Username, Password Reset and Login Information Solution
  • Nvidia Tesla GPUs K40/K80/M40/P40/P100/V100 at home/desktop hacking, cooling, powering, cable solutions Tutorial AIO Solutions
  • Stop ls in Linux Debian Mint CentOS Ubuntu from applying quotes around filenames and directory names
  • Thunderbird Attachment Download Error Corrupt Wrong filesize of 29 or 27 bytes Solution
  • Generic IP Camera LAN Default IP Settings DVR