CentOS 8 how to convert to a bootable mdadm RAID software array

The cool thing here is that we only need 1 drive to make a RAID 10 or RAID 1 array, we just tell the Linux mdadm utility that the other drive is "missing" and we can then add our original drive to the array after booting into our new RAID array.

Step#1 Install tools we need

yum -y install mdadm rsync

Step #2 Create your partitions on the drive that will be our RAID array

Here I assume it is /dev/sdb

fdisk /dev/sdb

#I find that mdadm works fine with the default partition type Linux although the fd flag will make them easier to find (fd means Software RAID)

/dev/sdb1 (md0) = Partition #1=/boot size=1G
/dev/sdb2 (md1) = Partition #2=swap size=30G (or whatever is suitable for your RAM and disk space)
/dev/sdb3 (md2) = Partition #3=/ size = the remainder of the disk (unless you have other plans/requirements).

Step #3 - Make our RAID arrays

To make sure your RAID array is bootable we need to ALWAYS make our md0 or /boot this way.

#md0 /boot
#we use level = 1 and metadata=0.90 to ensure /boot is readable by grub otherwise boot will fail
mdadm --create /dev/md0 --level 1 --raid-devices 2 /dev/sdb1 missing --metadata=0.90

#md1 swap
mdadm --create /dev/md1 --level 10 --raid-devices 2 /dev/sdb2 missing

#md2 /
mdadm --create /dev/md2 --level 10 --raid-devices 2 /dev/sdb3 missing

Notice that we specified the second drive as "missing". We will re-add it after we are all done and have rebooted into our RAID array.  Still, with the degraded array and only a single drive you can convert a live system into RAID without reinstalling anything.

Step #4 - Make filesystems on RAID arrays

mkfs.ext4 /dev/md0

mkswap /dev/md1

mkfs.ext4 /dev/md2

Step #5 - Mount and stage our current system into new mdadm RAID arrays

We will use /mnt/md2 as out staging point but it could be anything technically.

#make our staging point
mkdir /mnt/md2

# mount our root into our staging point
mount /dev/md2 /mnt/md2

#we need to make our boot inside our staging point before we copy things over
mkdir /mnt/md2/boot

# mount our boot into our staging point
mount /dev/md0 /mnt/md2/boot

Step #6 - Copy our current environment to our new RAID

#we exclude /mnt/so we don't double copy what is in /mnt including our staging environment
# we also exclude the contents of proc, sys because it slows things down and proc and sys will be populated once our new array environment actually gets booted from
rsync -Phaz --exclude=/mnt/* --exclude=/sys/* --exclude=/proc/* / /mnt/md2

Step #7 - chroot into and configure our new environment

Here is how we chroot properly:
#remember I assume your staging point ins in /mnt/md2 change that part if yours is different
for mount in dev sys proc; do
 mount -o bind /$mount /mnt/md2/$mount

#now let's chroot

chroot /mnt/md2

Step #8 - Disable SELinux

#1 Let's disable selinux it causes lots of problems and if you don't update the selinux attributes you will not be able to login after you boot!
#you would get this error "Failed to create session: Start job for unit user@0.service failed with 'failed'"

sed -i s#SELINUX=enforcing#SELINUX=disabled#  /etc/selinux/config

#double check that /etc/selinux/config has SELINUX=disabled just to be sure

Step #9 - Modify grub default config

#2 Let's fix our default grub config, it will often have references to lvm and other hard coded partitions that we no longer have.  We also have to add "rd.auto" or grub will not assemble and boot from our array

vi /etc/default/grub

Find this line:

GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"

change to

GRUB_CMDLINE_LINUX="crashkernel=auto rd.auto rhgb quiet"

rd.auto will automatically assemble our raid array otherwise if it's not assembled we can't mount and boot from it.

update grub

grub2-mkconfig > /etc/grub2.cfg


Make sure your grub entries are correct:

Centos grub would not boot because it was relative to /boot but that is wrong since we changed to an actual partition for /boot

cd /boot/loader/entries



[root@localhost entries]# vi 02bcb1988e6940a1bed64c61df98716a-4.18.0-147.5.1.el8_1.x86_64.conf
title CentOS Linux (4.18.0-147.5.1.el8_1.x86_64) 8 (Core)
version 4.18.0-147.5.1.el8_1.x86_64
linux /boot/vmlinuz-4.18.0-147.5.1.el8_1.x86_64
initrd /boot/initramfs-4.18.0-147.5.1.el8_1.x86_64.img $tuned_initrd

options $kernelopts $tuned_params
id centos-20200205020746-4.18.0-147.5.1.el8_1.x86_64
grub_users $grub_users
grub_arg --unrestricted
grub_class kernel

Fix the lines in bold and remove the /boot because that will cause your system not to boot.  If you have the /boot above it means that your current system has no separate boot partition.

Fixing them would like this:

title CentOS Linux (4.18.0-147.5.1.el8_1.x86_64) 8 (Core)
version 4.18.0-147.5.1.el8_1.x86_64
linux /vmlinuz-4.18.0-147.5.1.el8_1.x86_64
initrd /initramfs-4.18.0-147.5.1.el8_1.x86_64.img $tuned_initrd

options $kernelopts $tuned_params
id centos-20200205020746-4.18.0-147.5.1.el8_1.x86_64
grub_users $grub_users
grub_arg --unrestricted
grub_class kernel

Step #10 - Update /etc/fstab

Modify /etc/fstab and give the UUID for /, boot and swap of your md devices.

#Let's get their block IDs/UUID

blkid /dev/md0
/dev/md0: UUID="f4dc88f5-90ea-4916-97d7-8d627935118" TYPE="ext4"
blkid /dev/md1
/dev/md1: UUID="3adf88f5-90ea-4916-97d7-8d6279871f18" TYPE="swap"
blkid /dev/md2
/dev/md2: UUID="45aa90ea-4916-97d7-8d6279871f18" TYPE="ext4"

vi /etc/fstab
It should look something like this with ONLY the RAID arrays we have and the old stuff commented out

UUID=45aa90ea-4916-97d7-8d6279871f18    /                       ext4     defaults        0 0
UUID=f4dc88f5-90ea-4916-97d7-8d627935118 /boot                   ext4    defaults        1 2
UUID=3adf88f5-90ea-4916-97d7-8d6279871f18     swap                    swap    defaults        0 0

Step #11 - Use dracut to update our initramfs otherwise we don't be able to boot still!

#the first part below after -f is the full path name to the initramfs that you will be booting.  The second part is just the raw kernel version
dracut -f /boot/initramfs-4.18.0-147.5.1.el8_1.x86_64.img 4.18.0-147.5.1.el8_1.x86_64

dracut -f alone will work IF you are on the same OS and kernel that is installed

Step#12 - Install grub to all bootable drives

This depends on how many drives you have but let's assume 2 then they are /dev/sda and /dev/sdb

grub2-install /dev/sda

grub2-install /dev/sdb

Step#13 - Cross fingers and reboot

It would be a good idea to go back through the steps and make sure everything is right, including your grub default conf, UUIDs in /etc/fstab etc..

I also recommend NOT doing this on a production machine and at least not without backups.  If you want to practice it is best to run through the steps on a Virtual Machine first to identify any mistakes you've made.



centos, convert, bootable, mdadm, raid, software, arraystep, install, yum, partitions, dev, sdb, fdisk, default, partition, linux, fd, md, swap, suitable, ram, disk, remainder, requirements, arrays, array, metadata, ensure, readable, grub, devices, filesystems, mkfs, ext, mkswap, mount, mnt, staging, mkdir, exclude, contents, proc, sys, slows, populated, booted, rsync, phaz, chroot, configure, ins, bind, disable, selinux, update, attributes, login, quot, user, sed, enforcing, disabled, etc, config, references, lvm, coded, rd, auto, assemble, ll, mkconfig, cfg, doesn, vi, default_kernelopts, uuid, fa, aaa, eb, aa, ro, crashkernel, resume, mapper, cl, lv, rhgb, automatically, updated, fstab, modify, ids, blkid, dc, ea, adf, commented, defaults, dracut, initramfs, booting, kernel, _, img, sda, reboot,

Latest Articles

  • How to allow SSH root user access in Linux/Debian/Mint/RHEL/Ubuntu/CentOS
  • Ansible Tutorial - Playbook How To Install From Scratch and Deploy LAMP + Wordpress on Remote Server
  • Ceph Install Errors on Proxmox / How To Fix Solution
  • Proxmox Update Error https://enterprise.proxmox.com/debian/pve bullseye InRelease 401 Unauthorized [IP: 443]
  • QEMU/KVM How to Hot-add A Virtual Disk .raw/.qcow2 via QEMU Monitor Commands
  • Proxmox How To Enable Ceph Distributed Storage Cluster with OSD and Pools
  • pulseaudio issue on QEMU/KVM guest VM when microphone is replugged/unplugged pulseaudio: pa_threaded_mainloop_lock failed pulseaudio: Reason: Invalid argument
  • Ubuntu Linux Mint - Volume Control Stopped Working
  • Proxmox Services Won't Start Failed to start The Proxmox VE cluster filesystem. Proxmox VE firewall. PVE Status Daemon. Proxmox VE scheduler. PVE Cluster HA Resource Manager Daemon. PVE Local HA Resource Manager Daemon.
  • Proxmox Guide FAQ / Errors / Howto
  • Virtualbox Vbox Issue Cannot Enable Nested Virtualization Button is Grayed/Greyed Out and Unclickable HowTo Solution
  • Virtualbox VBOX Howto Port Forward To Guests
  • Linux Ubuntu Debian Centos Mint - How To Check if Intel VT-x or AMD-V Hardware Virtualization is Enabled?
  • Linux Howto Zip Multiple Files and Directories
  • Windows Cannot Format USB drive Device Media is Write Protected Error Solution
  • Linux Mint 20 cannot install snapd missing solution
  • Virtualbox VBOX How To Install Guest-Utils/GuestUtils so drag and drop and clipboard works Ubuntu Mint Debian Linux
  • How to install Kubernetes with microk8s and deploy apps on Debian/Mint/Ubuntu Linux
  • vi how to delete everything to the end of the line or the rest of the line from the cursor
  • Cisco Howto Configure Console Port/Terminal/Comm Server with Async Cable Setup