RAID + UEFI

Matteo Guglielmi Matteo.Guglielmi at dalco.ch
Fri Jan 22 14:33:44 CET 2021


varoius snippets to get RAID + UEFI




# disk_config/EFIKEES

disk_config disk1 disklabel:gpt fstabkey:uuid
primary /boot/efi 512M     vfat rw createopts="-n EFIS"
primary -          20G-    -    -
primary -          10G-50G -    -
primary -          10G     -    -

disk_config disk2 disklabel:gpt
primary -         512M     -    -
primary -          20G-    -    -
primary -          10G-50G -    -
primary -          10G     -    -

disk_config raid fstabkey:uuid
raid1 /    disk1.2,disk2.2 ext4 defaults mdcreateopts="-e 1.2" createopts="-L root"
raid1 /tmp disk1.3,disk2.3 ext4 defaults mdcreateopts="-e 1.2" createopts="-L tmp"
raid1 swap disk1.4,disk2.4 swap sw       mdcreateopts="-e 1.2" createopts="-L swap"




# scripts/EFI/30-add-os-entry

if ifclass EFIKEES ; then
  DISKS=($disklist)

  bdevice=/dev/${DISKS[0]}
else
  bdevice=$BOOT_DEVICE
fi

if ifclass CENTOS ; then
  ifclass COS7 && label='CentOS' || label='CentOS Linux'

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

  efibootmgr -c -d $bdevice -p 1 -L "$label" -l '\EFI\centos\grubx64.efi'
fi




# hooks/mountdisks.EFI

DISKS=($disklist)

if ifclass EFIKEES ; then
  # BOOT_DEVICE is /dev/md0
  sgdisk -c 1:EFI1 -c 2:RAID -c 3:RAID -c 4:RAID /dev/${DISKS[0]}

  sgdisk -c 1:EFI2 -c 2:RAID -c 3:RAID -c 4:RAID /dev/${DISKS[1]}
fi





# then, when the pc boot for the first time after FAI, you
# can cerate a one time script/service which runs something
# like this (see here below).
#
# the script should be installed by FAI and executed on the
# pc during its first boot.
#
# NOTE: some functions in this script are not reported here,
#       but it's quite easy to undestand what they do.


efi1='/dev/disk/by-partlabel/EFI1'

efi2='/dev/disk/by-partlabel/EFI2'

[ -b $efi1 -a -b $efi2 ] || exit 20

efi1d=$(lsblk -npo pkname $efi1)

efi1p=$(lsblk -npo kname $efi1)

efi2d=$(lsblk -npo pkname $efi2)

efi2p=$(lsblk -npo kname $efi2)

[ -n "$efi1d" -a -n "$efi1p" -a -n "$efi2d" -a -n "$efi2p" ] || exit 21

mountpoint -q /boot/efi && [ -d /boot/efi/EFI ] || exit 22

[ ! -f /etc/mdadm/mdadm.conf ] || mdadmconf='/etc/mdadm/mdadm.conf'

[ ! -f /etc/mdadm.conf ] || mdadmconf='/etc/mdadm.conf'

[ -n "$mdadmconf" ] || exit 23

tar -cf /tmp/EFI.tar -C /boot/efi EFI

umount /boot/efi

efi1psize=$(blockdev --getsize64 $efi1p)

efi2psize=$(blockdev --getsize64 $efi2p)

if ifclass RHEL ; then
  efi1dsecsize=$(< /sys/block/${efi1d##*/}/queue/hw_sector_size)

  efi2dsecsize=$(< /sys/block/${efi2d##*/}/queue/hw_sector_size)

  dd if=/dev/zero of=$efi1p bs=$efi1dsecsize \
    count=$[efi1psize/efi1dsecsize] conv=noerror,sync

  dd if=/dev/zero of=$efi2p bs=$efi2dsecsize \
    count=$[efi2psize/efi2dsecsize] conv=noerror,sync
else
  pv -q --stop-at-size -s $efi1psize /dev/zero > $efi1p

  pv -q --stop-at-size -s $efi2psize /dev/zero > $efi2p
fi

sgdisk -t 1:FD00 -c 1:RAID $efi1d

sgdisk -t 1:FD00 -c 1:RAID $efi2d

i=9

mdadm --create /dev/md/$i --level 1 --raid-disks 2 --metadata 1.0 $efi1p $efi2p

mkfs.fat -F32 /dev/md/$i

uuid=$(blkid | grep -Pohi "/dev/md/*$i.+uuid=\"*\K[^\"]+")

[ -n "$uuid" ] || exit 24

grep -q '/boot/efi' /etc/fstab || exit 25

sed -i "/\/boot\/efi/c UUID=$uuid /boot/efi vfat noauto,umask=0077 0 2" /etc/fstab

mount /boot/efi || exit 26

tar -xf /tmp/EFI.tar -C /boot/efi

sed -i '/^ARRAY/d' $mdadmconf

mdadm --detail --scan >> $mdadmconf

uuid=$(grep -Pohi "/dev/md/*$i.+uuid=\"*\K[^\"\s]+" $mdadmconf)

[ -n "$uuid" ] || exit 27

sed -i "s#/dev/md/*$i#<ignore>#g" $mdadmconf

grep -q '<ignore>' $mdadmconf || exit 28

[ ! -b /dev/md/$i ] || espdev=/dev/md/$i

[ ! -b /dev/md$i ] || espdev=/dev/md$i

[ -n "$espdev" ] || exit 29

cat > /etc/systemd/system/sync-esp.service <<-EOF
[Unit]
Description=sync esp
DefaultDependencies=no
After=local-fs.target

[Service]
Type=oneshot
ExecStart=$(which bash) -c 'if [ ! -b $espdev ] ; then $(which mdadm) -A $espdev --uuid=$uuid --update=resync ; fi'
ExecStart=$(which sleep) 3
ExecStart=$(which mount) /boot/efi
RemainAfterExit=yes

[Install]
WantedBy=sysinit.target
EOF

systemctl daemon-reload

systemctl enable sync-esp.service

osids=($(efibootmgr | perl -nle \
  'if (/^boot([0-9a-f]+).+(centos|opensuse|sle[sd]|fedora|red\s*hat|ubuntu|debian)/i) { print "$1" }'))

[ ${#osids[@]} -gt 0 ] || exit 30

for osid in ${osids[@]} ; do
  efibootmgr -Bb $osid # remove all os entries
done

if ifclass CENTOS ; then
  ifclass COS7 && label='CentOS' || label='CentOS Linux'

  bootloader='\EFI\centos\grubx64.efi'

  grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
elif ifclass REDHAT ; then
  label='Red Hat Enterprise Linux'

  bootloader='\EFI\redhat\grubx64.efi'

  grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
elif ifclass FEDORA ; then
  label='Fedora'

  bootloader='\EFI\fedora\grubx64.efi'

  grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
elif ifclass OSUSE ; then
  label='opensuse'

  bootloader='\EFI\opensuse\grubx64.efi'

  grub2-mkconfig -o /boot/grub2/grub.cfg
elif ifclass SLES ; then
  label='sles'

  bootloader='\EFI\sles\grubx64.efi'

  grub2-mkconfig -o /boot/grub2/grub.cfg
elif ifclass SLED ; then
  label='sled'

  bootloader='\EFI\sled\grubx64.efi'

  grub2-mkconfig -o /boot/grub2/grub.cfg
elif ifclass DEBIAN ; then
  label='debian'

  bootloader='\EFI\debian\grubx64.efi'

  update-grub -o /boot/grub/grub.cfg
elif ifclass UBUNTU ; then
  label='ubuntu'

  bootloader='\EFI\ubuntu\grubx64.efi'

  update-grub -o /boot/grub/grub.cfg
else
  exit 31
fi

assertNoError || exit 32

efibootmgr -c -d $efi2d -p 1 -L "${label}2" -l "$bootloader"

efibootmgr -c -d $efi1d -p 1 -L "${label}1" -l "$bootloader"

assertNoError || exit 33

if which dracut &> /dev/null ; then
  dracut -f
else
  update-initramfs -u
fi

reboot



# you will now have 2 efi entries to boot the same OS
#
# when one drive fails, just select the working one.

________________________________
From: linux-fai <linux-fai-bounces at uni-koeln.de> on behalf of Thomas Lange <lange at cs.uni-koeln.de>
Sent: Friday, January 22, 2021 10:33:25 AM
To: fully automatic installation for Linux
Subject: Re: RAID + UEFI

>>>>> On Thu, 21 Jan 2021 18:13:25 +0100, Alexander Thomas <alexander.thomas at esaturnus.com> said:


    > I would prefer the second method because it is not a hack. I have
    > successfully tried it with only 1 disk in the RAID during install, but
    > with 2 disks there is a problem. The disk_config for this 2-disk case
    > currently looks like:

    > disk_config disk1 disklabel:gpt bootable:1

    > primary /boot/efi  512M     vfat  rw
    > primary -  512M     -  -
    > primary -  1G-4G    -  -
    > primary -  30G-36G  -  -
    > primary -  4G-      -  -

    > disk_config disk2 sameas:disk1 bootable:1

    > Obvious problem: the `sameas` also clones the /boot/efi mount point,
    > and install fails with “mount point /boot/efi used twice”.
    > Is there an easy way around this, like some mountdisks hook script, or
    > is the ESP-inside-RAID a better option after all?
The only workaround I know is not to use samas, but to copy the config
from disk1 to disk2 and then remove the mount point from disk2.

--
regards Thomas


More information about the linux-fai mailing list