Skip to content

Commit

Permalink
UEFI boot loader support #11
Browse files Browse the repository at this point in the history
- Initial support for systemd as UEFI boot loader in the installer
- Script to generate efiboot.img for hybrid USB boot
- Updated makefiles to add EFI support for CD boot
  • Loading branch information
Ratler committed Nov 3, 2017
1 parent be9eeb8 commit 88f4213
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -38,7 +38,7 @@ ISO_TARGET = $(ISO_SOURCE)/BUILD
### ISO_DATE ISO_CNAME ISO_KVER ISO_PVER ISO_GRSVER ISO_LUNAR_MODULE \
### ISO_KSUFFIX ISO_MAKES ISO_REDUCE ISO_BUILD ISO_KARCH ISO_GCCARCH

export ISO_SOURCE ISO_TARGET ISO_BUILD
export ISO_SOURCE ISO_TARGET ISO_BUILD ISO_VERSION ISO_CODENAME ISO_DATE ISO_LABEL

.SUFFIXES:

Expand Down
26 changes: 22 additions & 4 deletions lunar-install/sbin/lunar-install
Expand Up @@ -6,7 +6,7 @@
# portions Copyright 2002 by rodzilla #
# portions Copyright 2003-2004 by tchan, kc8apf #
# portions Copyright 2004-2007 by Auke Kok #
# portions Copyright 2008-2014 by Stefan Wold #
# portions Copyright 2008-2017 by Stefan Wold #
# #
#############################################################
# #
Expand Down Expand Up @@ -62,6 +62,9 @@ chroot_run()
mount --bind /tmp $TARGET/tmp
mount --bind /sys $TARGET/sys
mount --bind /run $TARGET/run
if mountpoint -q /sys/firmware/efi/efivars; then
mount --bind /sys/firmware/efi/efivars $TARGET/sys/firmware/efi/efivars
fi
if [ -n "$USE_SWAP" ]; then
chroot $TARGET swapon -a
fi
Expand All @@ -74,6 +77,9 @@ chroot_run()
chroot $TARGET swapoff -a
fi
umount $TARGET/run
if mountpoint -q $TARGET/sys/firmware/efi/efivars; then
umount $TARGET/sys/firmware/efi/efivars
fi
umount $TARGET/sys
umount $TARGET/tmp
umount $TARGET/dev
Expand Down Expand Up @@ -298,6 +304,7 @@ menu_list_targets()
*XFS*) PTYPE="(XFS)" ;;
*Minix*) PTYPE="(minix)" ;;
*BTRFS*) PTYPE="(btrfs)" ;;
*FAT*) PTYPE="(FAT/FAT32)" ;;
*) PTYPE="(unknown)" ;;
esac

Expand Down Expand Up @@ -393,6 +400,7 @@ menu_get_filesystem()
REISER="Reiserfs file system (*)"
XFS="XFS file system (*)"
JFS="JFS file system (*)"
VFAT="FAT32 file system"
SWAP="Swap (Virtual memory or paging filesystem)"

$DIALOG --title "$TITLE" --default-item "ext4" --menu "$HELP" 0 0 0 \
Expand All @@ -402,6 +410,7 @@ menu_get_filesystem()
"ext2" "$EXT2" \
"xfs" "$XFS" \
"jfs" "$JFS" \
"vfat" "$VFAT" \
"swap" "$SWAP"
}

Expand Down Expand Up @@ -794,6 +803,8 @@ menu_select_partitions()
FORCE="-F"
elif [[ "$FSYS" == "btrfs" ]]; then
FORCE="-f"
elif [[ "$FSYS" == "vfat" ]]; then # Enforce creation of 32-bit filesystem
FORCE="-F 32"
else
unset FORCE
fi
Expand Down Expand Up @@ -1578,16 +1589,23 @@ install_kernels()
install_bootloader() {
while true ; do
BCOMMAND=`$DIALOG --title "Boot loader menu" --default-item "G" --item-help --menu "You will need a boot loader to start linux automatically when your computer boots. You can chose not to install a boot loader now, or pick one of the available boot loaders and options below. You can always change to the other boot loader later." 0 0 0 \
$(if pkg_avail grub2 ; then echo "G" ; echo "grub2" ; echo "Install grub2 as boot loader"; fi) \
$(if pkg_avail grub ; then echo "B" ; echo "grub" ; echo "Install grub as boot loader"; fi) \
$(if pkg_avail lilo ; then echo "L" ; echo "lilo" ; echo "Install lilo as boot loader"; fi) \
$(if pkg_avail systemd && [ -d /sys/firmware/efi ]; then echo "S" ; echo "systemd (UEFI only))" ; echo "Install systemd-boot as boot loader (UEFI)"; fi) \
$(if pkg_avail grub2 ; then echo "G" ; echo "grub2" ; echo "Install grub2 as boot loader (BIOS)"; fi) \
$(if pkg_avail grub ; then echo "B" ; echo "grub" ; echo "Install grub as boot loader (BIOS)"; fi) \
$(if pkg_avail lilo ; then echo "L" ; echo "lilo" ; echo "Install lilo as boot loader (BIOS)"; fi) \
"N" "none" "Do not install a boot loader"`
if [ $? != 0 ] ; then
continue
fi
case $BCOMMAND in
S)
BOOTLOADER=systemd
chroot_run lsh update_plugin $BOOTLOADER "install"
chroot_run bootctl install
msgbox "The systemd boot loader package was installed. From now on, when you add a kernel, it will be available through UEFI on boot."
;;
L)
BOOTLOADER=lilo
transfer_package $BOOTLOADER
Expand Down
60 changes: 48 additions & 12 deletions mkfiles/iso.mk
@@ -1,4 +1,4 @@
.INTERMEDIATE: iso iso-target iso-modules iso-tools iso-files iso-strip iso-isolinux
.INTERMEDIATE: iso iso-target iso-modules iso-tools iso-files iso-strip iso-isolinux iso-efi

iso: $(ISO_SOURCE)/lunar-$(ISO_VERSION).iso

Expand All @@ -14,14 +14,14 @@ iso-target: $(ISO_TARGET)/.iso-target

# Host system iso tools
iso-tools:
@which mkisofs || lin cdrtools
@which xorriso || lin libisoburn
@which isohybrid || lin syslinux

@which efitool-mkusb || lin efitools

# Remove non iso modules
include $(ISO_SOURCE)/conf/modules.iso

SYSLINUX_FILES=isolinux.bin ldlinux.c32 libcom32.c32 libutil.c32
SYSLINUX_FILES=isolinux.bin isohdpfx.bin ldlinux.c32 libcom32.c32 libutil.c32

$(ISO_TARGET)/.iso-modules: iso-target $(addprefix $(ISO_TARGET)/isolinux/, $(SYSLINUX_FILES))
@echo iso-modules
Expand Down Expand Up @@ -78,6 +78,9 @@ $(addprefix $(ISO_TARGET)/usr/share/syslinux/, $(SYSLINUX_FILES)): $(ISO_TARGET)
$(ISO_TARGET)/isolinux/isolinux.bin: $(ISO_TARGET)/usr/share/syslinux/isolinux.bin
@cp $< $@

$(ISO_TARGET)/isolinux/isohdpfx.bin: $(ISO_TARGET)/usr/share/syslinux/isohdpfx.bin
@cp $< $@

$(ISO_TARGET)/isolinux/ldlinux.c32: $(ISO_TARGET)/usr/share/syslinux/ldlinux.c32
@cp $< $@

Expand Down Expand Up @@ -114,16 +117,49 @@ $(ISO_TARGET)/.iso-isolinux: iso-target

iso-isolinux: $(ISO_TARGET)/.iso-isolinux $(addprefix $(ISO_TARGET)/isolinux/, $(SYSLINUX_FILES)) $(ISO_TARGET)/isolinux/linux $(ISO_TARGET)/isolinux/initrd $(addprefix $(ISO_TARGET)/isolinux/, $(ISOLINUX_FILES))

# Setup EFI for USB and CD
$(ISO_TARGET)/.iso-efi: iso-target
@echo "Setting up iso-efi"
@mkdir -p $(ISO_TARGET)/EFI/boot $(ISO_TARGET)/loader/entries $(ISO_TARGET)/EFI/lunariso
@touch $@

$(ISO_TARGET)/EFI/boot/bootx64.efi: /usr/share/efitools/efi/PreLoader.efi
@cp $< $@

$(ISO_TARGET)/EFI/boot/HashTool.efi: /usr/share/efitools/efi/HashTool.efi
@cp $< $@

$(ISO_TARGET)/EFI/boot/loader.efi: $(ISO_TARGET)/usr/lib/systemd/boot/efi/systemd-bootx64.efi
@cp $< $@

$(ISO_TARGET)/loader/loader.conf: $(ISO_SOURCE)/efiboot/loader/loader.conf
@cp $< $@

$(ISO_TARGET)/loader/entries/lunariso-x86_64.conf: $(ISO_SOURCE)/efiboot/loader/entries/lunariso-x86_64-cd.conf $(ISO_TARGET)/.iso-efi
@sed -e 's:%VERSION%:$(ISO_VERSION):g' -e 's:%CODENAME%:$(ISO_CODENAME):g' -e 's:%DATE%:$(ISO_DATE):g' -e 's:%LABEL%:$(ISO_LABEL):' $< > $@

$(ISO_TARGET)/EFI/lunariso/efiboot.img: $(ISO_TARGET)/.iso-efi
@echo "Creating EFI boot image"
@$(ISO_SOURCE)/scripts/create-efi-image

iso-efi: $(ISO_TARGET)/.iso-efi $(ISO_TARGET)/EFI/boot/bootx64.efi $(ISO_TARGET)/EFI/boot/HashTool.efi $(ISO_TARGET)/EFI/boot/loader.efi $(ISO_TARGET)/loader/loader.conf $(ISO_TARGET)/loader/entries/lunariso-x86_64.conf $(ISO_TARGET)/EFI/lunariso/efiboot.img

# Generate the actual image
$(ISO_SOURCE)/lunar-$(ISO_VERSION).iso: iso-tools iso-files iso-isolinux iso-strip installer
$(ISO_SOURCE)/lunar-$(ISO_VERSION).iso: iso-tools iso-files iso-isolinux iso-efi iso-strip installer
@echo iso
@mkisofs -o $@.tmp -R -J -l \
-V '$(ISO_LABEL)' \
-d -D -N -no-emul-boot -boot-load-size 4 -boot-info-table \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
@xorriso -as mkisofs \
-iso-level 3 \
-o $@.tmp -l \
-eltorito-boot isolinux/isolinux.bin \
-eltorito-catalog isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-isohybrid-mbr $(ISO_TARGET)/isolinux/isohdpfx.bin \
-eltorito-alt-boot \
-e EFI/lunariso/efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-m '$(ISO_TARGET)/.*' \
-m '$(ISO_TARGET)/boot/*' \
-m '$(ISO_TARGET)/etc/lunar/local/*' \
-m '$(ISO_TARGET)/tmp/*' \
-m '$(ISO_TARGET)/var/tmp/*' \
Expand All @@ -141,6 +177,6 @@ $(ISO_SOURCE)/lunar-$(ISO_VERSION).iso: iso-tools iso-files iso-isolinux iso-str
-m '$(ISO_TARGET)/usr/src' \
-m '$(ISO_TARGET)/var/state/lunar/module_history' \
-m 'doc' \
-A 'Lunar-$(ISO_VERSION)' $(ISO_TARGET)
@isohybrid $@.tmp
-volid '$(ISO_LABEL)' \
-appid 'Lunar-$(ISO_VERSION)' $(ISO_TARGET)
@mv $@.tmp $@
33 changes: 33 additions & 0 deletions scripts/create-efi-image
@@ -0,0 +1,33 @@
#!/bin/bash

set -e

MNTDIR=$(mktemp -d /tmp/efiboot-XXXXXX)
BOOTIMGSIZE="${1:-50}M"
BOOTIMGFILE="${2:-$ISO_TARGET/EFI/lunariso/efiboot.img}"

finishScript() {
umount -d $MNTDIR
rmdir $MNTDIR
}

trap finishScript 0 2 3 15

if [ ! -d "$(dirname $BOOTIMGFILE)" ]; then
echo "Missing EFI dir in $ISO_TARGET, previous step failed..."
exit 1
fi

truncate -s $BOOTIMGSIZE $BOOTIMGFILE
mkfs.fat -n LUNAR_EFI $BOOTIMGFILE > /dev/null
mount $BOOTIMGFILE $MNTDIR
mkdir -p $MNTDIR/EFI/{lunariso,boot} $MNTDIR/loader/entries
cp $ISO_TARGET/boot/{linux,initrd} $MNTDIR/EFI/lunariso/
cp $ISO_TARGET/EFI/boot/{bootx64.efi,HashTool.efi} $MNTDIR/EFI/boot/
cp $ISO_TARGET/usr/lib/systemd/boot/efi/systemd-bootx64.efi $MNTDIR/EFI/boot/loader.efi
cp $ISO_SOURCE/efiboot/loader/loader.conf $MNTDIR/loader/loader.conf
sed -e "s:%VERSION%:${ISO_VERSION}:g" \
-e "s:%CODENAME%:${ISO_CODENAME}:g" \
-e "s:%DATE%:${ISO_DATE}:g" \
-e "s:%LABEL%:${ISO_LABEL}:g" \
$ISO_SOURCE/efiboot/loader/entries/lunariso-x86_64-usb.conf > $MNTDIR/loader/entries/lunariso-x86_64.conf

0 comments on commit 88f4213

Please sign in to comment.