From 14069e46a60e06a6b1ac1b437b4c6536f21f3d02 Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 20 Jan 2019 09:37:02 -0800 Subject: [PATCH] Add refind-efi and syslinux setup for UEFI systems --- lang/english.trans | 2 +- src/archlabs-installer | 113 +++++++++++++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/lang/english.trans b/lang/english.trans index 08eb4ac..f6d73bb 100644 --- a/lang/english.trans +++ b/lang/english.trans @@ -12,7 +12,7 @@ _Pass2="\nRe-enter the password for" _NoFileErr="\nFile does not exist.\n" _WelTitle="Welcome to the" -_WelBody="\nThis will help you get $DIST setup on your system.\nBeing an Arch based distribution, having prior GNU/Linux experience will be an asset however we try our best to keep things simple.\nIf you are unsure about an option, a default will be listed or the first selected option will be the default (excluding language and timezone).\n\n\nMenu Navigation:\n\n - Select items with the arrow keys or the option number.\n - Use [Space] to toggle options and [Enter] to confirm.\n - Switch between buttons using [Tab] or the arrow keys.\n - Use [Page Up] and [Page Down] to jump whole pages\n - Press the highlighted key of an option to select it.\n" +_WelBody="\nThis will help you get $DIST setup on your system.\nHaving GNU/Linux experience is an asset, however we try our best to keep things simple.\n\nIf you are unsure about an option, a default will be listed or\nthe first selected option will be the default (excluding language and timezone).\n\n\nMenu Navigation:\n\n - Select items with the arrow keys or the option number.\n - Use [Space] to toggle options and [Enter] to confirm.\n - Switch between buttons using [Tab] or the arrow keys.\n - Use [Page Up] and [Page Down] to jump whole pages\n - Press the highlighted key of an option to select it.\n" _NotRoot="\nThis installer must be run as root or using sudo.\n" _Not64Bit="\nThis installer only supports x86_64 architectures.\n" diff --git a/src/archlabs-installer b/src/archlabs-installer index 6e4a2c8..227b820 100755 --- a/src/archlabs-installer +++ b/src/archlabs-installer @@ -8,7 +8,7 @@ # Some ideas and code reworked from other resources # AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due -VER="2.0.1" # version +VER="2.0.0" # version DIST="ArchLabs" # distributor MNT="/mnt" # mountpoint @@ -108,6 +108,7 @@ SHL=$((LINES - 20)) # command used to install each bootloader declare -A BCMDS=( +[refind-efi]="refind-install" [grub]="grub-install --recheck --force" [syslinux]="syslinux-install_update -i -a -m" [systemd-boot]="bootctl --path=/boot install" @@ -1702,17 +1703,19 @@ setup_boot() if [[ $SYS == 'BIOS' ]]; then BOOTLDR="$(menubox "$_PrepMount" "$_MntBootBody" \ "grub" "The Grand Unified Bootloader, standard among many Linux distributions" \ - "syslinux" "A collection of boot loaders capable of booting from drives, CDs, and over the network")" + "syslinux" "A collection of boot loaders for booting drives, CDs, or over the network")" else BOOTLDR="$(menubox "$_PrepMount" "$_MntBootBody" \ "systemd-boot" "A simple UEFI boot manager which executes configured EFI images" \ - "grub" "The Grand Unified Bootloader, standard among many Linux distributions")" + "grub" "The Grand Unified Bootloader, standard among many Linux distributions" \ + "refind-efi" "A UEFI boot manager that aims to be platform neutral and simplify multi-boot" \ + "syslinux" "A collection of boot loaders for booting drives, CDs, or over the network (no chainloading support)")" fi [[ $BOOTLDR ]] || return 1 - if [[ $BOOT_PART != "" ]]; then + if [[ $BOOT_PART ]]; then mount_partition "$BOOT_PART" "/boot" && SEP_BOOT=true || return 1 setup_boot_device fi @@ -1721,9 +1724,6 @@ setup_boot() setup_grub() { - # grub has by far the worst setup of the three however - # the configuration is shorter due to grub-mkconfig - EDIT_FILES[bootloader]="/etc/default/grub" if [[ $SYS == 'BIOS' ]]; then @@ -1751,12 +1751,49 @@ setup_grub() setup_syslinux() { - EDIT_FILES[bootloader]="/boot/syslinux/syslinux.cfg" + if [[ $SYS == 'BIOS' ]]; then + EDIT_FILES[bootloader]="/boot/syslinux/syslinux.cfg" + else + EDIT_FILES[bootloader]="/boot/EFI/syslinux/syslinux.cfg" + BCMDS[syslinux]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars || true && + efibootmgr -c -d $BOOT_DEVICE -p $BOOT_PART_NUM -l /EFI/syslinux/syslinux.efi -L $DIST -v" + fi } setup_systemd-boot() { EDIT_FILES[bootloader]="/boot/loader/entries/$DIST.conf" + BCMDS[systemd-boot]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars || true && bootctl --path=/boot install" +} + +setup_refind-efi() +{ + EDIT_FILES[bootloader]="/boot/refind_linux.conf" + BCMDS[refind-efi]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars || true && refind-install" +} + +prerun_refind-efi() +{ + cat > $MNT/boot/refind_linux.conf << EOF +"$DIST Linux" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && + printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] && + printf "initrd=/%s " "$UCODE")initrd=/initramfs-%v.img" +"$DIST Linux Fallback" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && + printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] && + printf "initrd=/%s " "$UCODE")initrd=/initramfs-%v-fallback.img" +EOF + mkdir -p $MNT/etc/pacman.d/hooks + cat > $MNT/etc/pacman.d/hooks/refind.hook << EOF +[Trigger] +Operation = Upgrade +Type = Package +Target = refind-efi + +[Action] +Description = Updating rEFInd on ESP +When = PostTransaction +Exec = /usr/bin/refind-install +EOF } prerun_grub() @@ -1765,11 +1802,16 @@ prerun_grub() s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/g" $MNT/etc/default/grub if [[ $LUKS_DEV ]]; then sed -i "s~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; - s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g" $MNT/etc/default/grub + s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g" $MNT/etc/default/grub 2>$ERR + errshow 1 "sed -i 's~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; + s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g' $MNT/etc/default/grub" fi if [[ $SYS == 'BIOS' && $LVM && $SEP_BOOT == false ]]; then - sed -i "s/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g" $MNT/etc/default/grub + sed -i "s/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g" $MNT/etc/default/grub 2>$ERR + errshow 1 "sed -i 's/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g' $MNT/etc/default/grub" fi + + # setup for os-prober module mkdir -p /run/lvm mkdir -p /run/udev mkdir -p $MNT/hostrun/lvm @@ -1782,21 +1824,21 @@ prerun_grub() prerun_systemd-boot() { - mkdir -p ${MNT}/boot/loader/entries - cat > ${MNT}/boot/loader/loader.conf << EOF + mkdir -p $MNT/boot/loader/entries + cat > $MNT/boot/loader/loader.conf << EOF default $DIST timeout 5 editor no EOF - cat > ${MNT}/boot/loader/entries/${DIST}.conf << EOF + cat > $MNT/boot/loader/entries/$DIST.conf << EOF title $DIST Linux -linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/${UCODE}.img") +linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img") initrd /initramfs-$KERNEL.img options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw EOF - cat > ${MNT}/boot/loader/entries/${DIST}-fallback.conf << EOF + cat > $MNT/boot/loader/entries/$DIST-fallback.conf << EOF title $DIST Linux Fallback -linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/${UCODE}.img") +linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img") initrd /initramfs-$KERNEL-fallback.img options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw EOF @@ -1818,17 +1860,21 @@ EOF prerun_syslinux() { - mkdir -pv $MNT/boot/syslinux - cp -rfv $RUN/syslinux/splash.png $MNT/boot/syslinux/ - cp -rfv /usr/lib/syslinux/bios/* $MNT/boot/syslinux/ - cat > $MNT/boot/syslinux/syslinux.cfg << EOF + local cfgdir="$MNT/boot/syslinux" cfgsrcdir="/usr/lib/syslinux/bios" + if [[ $SYS == 'UEFI' ]]; then + cfgdir="$MNT/boot/EFI/syslinux"; cfgsrcdir="/usr/lib/syslinux/efi64/" + fi + + mkdir -pv $cfgdir + cp -rfv $cfgsrcdir/* $cfgdir/ + cat > $cfgdir/syslinux.cfg << EOF UI vesamenu.c32 MENU TITLE $DIST Boot Menu MENU BACKGROUND splash.png TIMEOUT 50 DEFAULT $DIST -# Refer to https://www.syslinux.org/wiki/index.php/Comboot/menu.c32 +# see: https://www.syslinux.org/wiki/index.php/Comboot/menu.c32 MENU WIDTH 78 MENU MARGIN 4 MENU ROWS 4 @@ -1852,15 +1898,15 @@ LABEL $DIST MENU LABEL $DIST Linux LINUX ../vmlinuz-$KERNEL APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw -INITRD $([[ $UCODE ]] && printf "%s" "../${UCODE}.img,")../initramfs-$KERNEL.img +INITRD $([[ $UCODE ]] && printf "%s" "../$UCODE.img,")../initramfs-$KERNEL.img LABEL ${DIST}fallback MENU LABEL $DIST Linux Fallback LINUX ../vmlinuz-$KERNEL APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw -INITRD $([[ $UCODE ]] && printf "%s" "../${UCODE}.img,")../initramfs-$KERNEL-fallback.img +INITRD $([[ $UCODE ]] && printf "%s" "../$UCODE.img,")../initramfs-$KERNEL-fallback.img -# some examples for chainloading other bootloaders +# examples of chainloading other bootloaders #LABEL grub2 #MENU LABEL Grub2 @@ -1882,7 +1928,7 @@ install_bootloader() ROOT_PART_ID="$ROOT_PART" elif [[ $BOOTLDR == 'syslinux' ]]; then ROOT_PART_ID="UUID=$(blkid -s UUID -o value $ROOT_PART)" - elif [[ $BOOTLDR == 'systemd-boot' ]]; then + elif [[ $BOOTLDR == 'systemd-boot' || $BOOTLDR == 'refind-efi' ]]; then ROOT_PART_ID="PARTUUID=$(blkid -s PARTUUID -o value $ROOT_PART)" fi @@ -1902,8 +1948,8 @@ install_bootloader() find $MNT/boot/ -name 'syslinux*' -exec rm -rf '{}' \; >/dev/null 2>&1 fi - prerun_$BOOTLDR printf "Installing and setting up $BOOTLDR\n" + prerun_$BOOTLDR chrun "${BCMDS[$BOOTLDR]}" 2>$ERR errshow 1 "${BCMDS[$BOOTLDR]}" @@ -1913,9 +1959,20 @@ install_bootloader() rm -rf $MNT/hostrun >/dev/null 2>&1 fi - if [[ $BOOTLDR == 'grub' && $SYS == 'UEFI' ]]; then + if [[ $SYS == 'UEFI' ]]; then + # some UEFI firmware require a generic esp/BOOT/BOOTX64.EFI + # see: https://wiki.archlinux.org/index.php/GRUB#UEFI + # also: https://wiki.archlinux.org/index.php/syslinux#UEFI_Systems mkdir -pv $MNT/boot/EFI/BOOT - cp -fv $MNT/boot/EFI/$DIST/grubx64.efi $MNT/boot/EFI/BOOT/BOOTX64.EFI + if [[ $BOOTLDR == 'grub' ]]; then + cp -fv $MNT/boot/EFI/$DIST/grubx64.efi $MNT/boot/EFI/BOOT/BOOTX64.EFI + elif [[ $BOOTLDR == 'syslinux' ]]; then + cp -rf $MNT/boot/EFI/syslinux/* $MNT/boot/EFI/BOOT/ + cp -f $MNT/boot/EFI/syslinux/syslinux.efi $MNT/boot/EFI/BOOT/BOOTX64.EFI + elif [[ $BOOTLDR == 'refind-efi' ]]; then + sed -i '/#extra_kernel_version_strings/ c extra_kernel_version_strings linux-hardened,linux-zen,linux-lts,linux' + cp -fv $MNT/boot/EFI/refind/refind_x64.efi $MNT/boot/EFI/BOOT/BOOTX64.EFI + fi fi return 0