The topic I want to touch on is quite popular and has been reviewed on many resources, but for a different version of the GRUB bootloader and for a different version of the OS.
Preamble
It was necessary to transfer the installed Centos 7 to the software raid level 1 in manual mode, since the system itself was set via kickstart. Looking for information on this issue, I found the material only on the old OS version and on the first version of the GRUB loader.
Having decided that the methods are similar, only with a change of commands, he got down to business and came across nuances with “dracut”.
For some reason, the initramfs created by “dracut” does not see the assembled raid and refuses to boot. Version "dracut" 033.
Plot
The solution was found and it consists in enabling and sending the “rd.auto = 1” option to the kernel (the option forces to automatically detect and run all raid devices that are available), which is disabled by default in dracut starting from version 024.
')
Below I will give a set of commands for transferring the installed OS to software raid level 1, for judging or helping the needy.
Initial data
Disk / dev / sda, on / dev / sda1 there is a system, 4GB in size.
The / dev / sdb disk is completely clean.
Teams
1. Fully copy partitions, from sda to sdb:
sfdisk -d /dev/sda | sfdisk /dev/sdb
2. Through fdisk, change id 83 to fd to sdb1:
fdisk /dev/sdb
3. We do raid level 1 with one disk:
mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
4. Format the resulting / dev / md0:
mkfs.ext4 /dev/md0
5. Mount our / dev / md0:
mount /dev/md0 /mnt/
6. Copy the current system to / dev / md0:
rsync -axu / /mnt/
7. We mount information about the current system into our new root and chroot into it:
mount --bind /proc /mnt/proc && mount --bind /dev /mnt/dev && mount --bind /sys /mnt/sys && mount --bind /run /mnt/run && chroot /mnt/
8. Get uuid / dev / md0 and add it to fstab, where we replace uuid sda1 with uuid md0:
ls -l /dev/disk/by-uuid |grep md >> /etc/fstab && vim /etc/fstab
9. Create a config for mdadm so that md0 does not change the name when rebooting:
mdadm --detail --scan > /etc/mdadm.conf
10. Making a new initramfs, with the necessary modules (it was here that dracut and disappoint):
mv /boot/initramfs-3.10.0-123.el7.x86_64.img /boot/initramfs-3.10.0-123.el7.x86_64.img.bak dracut /boot/initramfs-$(uname -r).img $(uname -r)
11. Passing the “rd.auto = 1” option to the kernel explicitly via “GRUB”; for this, add it to “GRUB_CMDLINE_LINUX”:
vim /etc/default/grub
12. Rewrite the “GRUB” config and install it on our sdb disk:
grub2-mkconfig -o /boot/grub2/grub.cfg && grub2-install /dev/sdb
13. Make sure that the uuid md0 and the "rd.auto = 1" option are accurately recorded:
cat /boot/grub2/grub.cfg
14. We make the reboot of the machine and through the bios boot menu we select the disk with the half raid
15. After successful loading, we remake sda ​​into the raid part. Change id 83 to fd via fdisk, add the disk to raid and reinstall “GRUB” to the disk:
fdisk /dev/sda mdadm --manage /dev/md0 --add /dev/sda1 grub2-install /dev/sda
After that, we’ll see how the raid is going through / proc / mdstat and you can try to boot from the first disk.
UPD: Due to the use of rd.auto = 1, problems with LVM are noticed, if it is located on the software raid section - the LVM section will not be available after a reboot. To prevent this from happening, you need to do the following:
In paragraph 11, you need to transfer rd.md.uuid = UUID that we put in mdadm.conf, instead of “rd.auto = 1”, thereby explicitly specifying which raid partition we should collect in order to load the root.
Link and solution about the bug:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=725759