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

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!

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).


  • How to Update Linux /usr/share/misc/pci.ids
  • pcimodules and lspci not working alternative solution
  • How to disable Google Fonts in Wordpress
  • Unable to load dynamic library /usr/lib64/php/modules/php_openssl
  • mysqld in Linux hacked
  • W: GPG error: http://archive.debian.org squeeze Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA NO_PUBKEY 64481591B98321F9
  • cannot mount kvm ntfs image
  • h264 DVR security camera footage cannot be played
  • dhcpd.conf how to secure so only known and allowed clients will be given dhcpd IP address leases
  • Thunderbird E-mail List Blank White but e-mails still clickable and viewable
  • css responsive images
  • responsive table without changing much code solution
  • yum how to install old obsolete packages
  • PHP Howto Store Value of Included File Output Into Variable
  • PHP Migration from 5.3 to 5.4+ and dealing with deprecated functions
  • ffmpeg vidstab to stabilize video
  • userdel user userdel: cannot lock /etc/passwd; try again later.
  • mdadm how to mount inactive array
  • How to find and mount mdadm arrays automatically
  • M2Crypto.SSL.Checker.WrongHost: Peer certificate subjectAltName does not match host, expected fedora-archive.ip-connect.vn.ua, got DNS:mirror.ip-connect.vn.ua