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 Upgrade Debian 8,9,10 to Debian 12 Bookworm
  • Linux dhcp dhclient Mint Redhat Ubuntu Debian How To Use Local Domain DNS Server Instead of ISPs
  • Docker dockerd swarm high CPU usage cause solution
  • Docker Minimum Requirements/How Efficient is Docker? How Much Memory Does Dockerd Use?
  • qemu-nbd: Failed to set NBD socket solution qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
  • apache2 httpd apache server will not start [pid 22449:tid 139972160445760] AH00052: child pid 23248 exit signal Aborted (6) solution Mint Debian Ubuntu Redhat
  • How to use the FTDI USB serial cable to RJ45 adapter to connect to the console on Cisco/Juniper Switch Router Firewall in Linux Ubuntu Debian Redhat
  • How To Setup Python3 in Ubuntu Docker Image for AI Deep Learning
  • How to Configure NVIDIA GPUs with Docker on Ubuntu: A Comprehensive Guide for AI Deep Learning CUDA Solution
  • Linux Ubuntu Mint how to check nameservers when /etc/resolv.conf disabled solution
  • Docker cannot work on other overlayfs filesystems such as ecryptfs won't start overlayfs: filesystem on '/home/docker/overlay2/check-overlayfs-support130645871/upper' not supported as upperdir
  • Linux How To Access Original Contents of Directory Mounted Debian Mint CentOS Redhat Solution
  • ecryptfs how to manually encrypt your existing home directory or other directory
  • How to Reset CIPC Cisco IP Communicator for CME CUCM CallManager
  • Internet Explorer Cannot Download File "Your security settings do not allow for this file to be downloaded." Security Settings Solution
  • Linux How To Upgrade To The Latest Kernel Debian Mint Ubuntu
  • Firefox how to restore and backup saved passwords and history which files/location
  • Linux How To echo as root solution to use tee permission denied solution Ubuntu Debian Mint Redhat CentOS
  • Linux how to keep command line bash process running if you are disconnected or need to logout of SSH remotely
  • Linux swapping too much? How to check the swappiness and stop swapping