[arch-releng] [RFCv4] [PATCH] [configs/releng] Add UEFI boot support via Linux >= 3.3 EFI boot stub on x86_64

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Thu Apr 5 14:38:06 EDT 2012


Makes an efiboot.img (FAT16) for "El Torito" (additional).
Under an EFI-system, implies that this .ISO works only if is used
as "CD-ROM/DVD-ROM" not in ISO-HYBRID-MBR mode.
If you want, an EFI-ready USB-key, just unpack this "<ISO>/EFI/efiboot.img" (FAT16) to
"<USB-key-FAT-formatted>/EFI" then copy "<ISO>/arch" and setup the filesystem label.

An aditional EFI shell is provided with an startup script for automatic booting
until EFI_STUB supports "linux.conf" to pass boot parms to kernel.
Anyway I think that is a good idea to keep this shell, so can customize boot parms,
or for doing other tasks on systems without an EFI-shell.

RFCv1: Initial efiboot.img build with vmlinuz.efi (Linux with EFI_STUB enabled)
       and archiso.img (initramfs).
RFCv2: Use an startup.nsh with EFI-Shell 2.0 (generated from build.sh) for automatic boot.
RFCv3: Use and older EFI-Shell 1.0 instead of 2.0, since not all UEFI-systems
       are compatible with 2.3+ specs.
RFCv4: The script "startup.nsh" improved by Keshav P R, using a for-loop
       (see notes below from original commit), now that has more than 1-line,
       I moved it to an independent file and is parsed by build.sh.

----
About startup.nsh:
Author: Keshav P R <the.ridikulus.rat at gmail.com>
Date:   Thu Apr 5 10:33:20 2012 +0530
    [configs/releng] Search in all existing UEFI FS mountpoints for archiso efistub kernel file

    There is no guarantee that the efistub kernel will always be in fs0:
    (similar to the case inside linux OS where the sda, sdb confusion exists,
    hence the need for UUIDs), especially when USB (instead os CD/ISO) is
    used for booting.

    Hence loop through all possible fs mountpoints (in UEFI) in startup.nsh
    and try to launch the first mountpoint that contains the archiso files.

    Cd's into the fs%m:\EFI\archiso directory also may remove future issues
    with efistub's linux.conf where the efistub might have problems
    identifying the directory from which the kernel was launched.

    Also add an helpful echo message showing the user the UEFI PATH to the
    archiso kernel file being launched by startup.nsh .

    Hopefully this should work in both CD and USB. Tested in Tianocore
    UDK/EDK2 DuetPkg X64 UEFI 2.3.1 firmware with EdkShellBinPkg's Shell.
----

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386 at yahoo.com.ar>
---
 README                                      |    3 +++
 configs/releng/build.sh                     |   38 +++++++++++++++++++++++++++
 configs/releng/efiboot/EFI/boot/startup.nsh |   10 +++++++
 3 files changed, 51 insertions(+)
 create mode 100644 configs/releng/efiboot/EFI/boot/startup.nsh

diff --git a/README b/README
index 57c87e3..711e51d 100644
--- a/README
+++ b/README
@@ -153,6 +153,9 @@ if nothing is specified on command line.
  + squashfs-tools          for mksquashfs
  + libisoburn              for xorriso
 
+** For configs/releng build.sh needs theses packages (build host):
+ + dosfstools              for mkfs.vfat
+
 ** For these hooks needs these packages (on target root-image)
 * archiso
  + (none)
diff --git a/configs/releng/build.sh b/configs/releng/build.sh
index 2faf210..7cffeaf 100755
--- a/configs/releng/build.sh
+++ b/configs/releng/build.sh
@@ -58,6 +58,43 @@ make_boot() {
     fi
 }
 
+# Prepare EFI "El Torito" boot image (using Linux >= 3.3 EFI boot stub)
+make_boot_efi() {
+    if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
+        if [[ ${arch} == "x86_64" ]]; then
+            mkdir -p ${work_dir}/iso/EFI/archiso
+            dd of=${work_dir}/iso/EFI/archiso/efiboot.img bs=1 seek=20M count=0
+            mkfs.vfat ${work_dir}/iso/EFI/archiso/efiboot.img
+
+            mkdir -p ${work_dir}/efiboot
+            mount ${work_dir}/iso/EFI/archiso/efiboot.img ${work_dir}/efiboot
+
+            mkdir -p ${work_dir}/efiboot/EFI/archiso
+            cp ${work_dir}/iso/${install_dir}/boot/x86_64/vmlinuz ${work_dir}/efiboot/EFI/archiso/vmlinuz.efi
+            cp ${work_dir}/iso/${install_dir}/boot/x86_64/archiso.img ${work_dir}/efiboot/EFI/archiso/archiso.img
+
+            # There are plans to support command line options via a config file (not yet in linux-3.3)
+            #cp ${work_dir}/iso/${install_dir}/boot/x86_64/vmlinuz ${work_dir}/efiboot/EFI/boot/bootx64.efi
+            #cp ${work_dir}/iso/${install_dir}/boot/x86_64/archiso.img ${work_dir}/efiboot/EFI/boot/linux.img
+            #echo "archisolabel=${iso_label} initrd=\EFI\boot\linux.img" | iconv -f ascii -t ucs2 > ${work_dir}/iso/EFI/boot/linux.conf
+
+            # For now, provide an EFI-shell until 'linux.conf' hits mainline.
+            mkdir -p ${work_dir}/efiboot/EFI/boot
+            # EFI Shell 2.0 for UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UEFI_Shell )
+            #wget -O ${work_dir}/efiboot/EFI/boot/bootx64.efi https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi
+            # EFI Shell 1.0 for non UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Efi-shell )
+            wget -O ${work_dir}/efiboot/EFI/boot/bootx64.efi https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi
+
+            # Add an EFI shell script for automatic boot if ESC-key is not pressed within 5 seconds timeout.
+            sed "s|%ARCHISO_LABEL%|${iso_label}|g;
+                 s|%INSTALL_DIR%|${install_dir}|g" ${script_path}/efiboot/EFI/boot/startup.nsh > ${work_dir}/efiboot/EFI/boot/startup.nsh
+
+            umount ${work_dir}/efiboot
+        fi
+        : > ${work_dir}/build.${FUNCNAME}
+    fi
+}
+
 # Prepare /${install_dir}/boot/syslinux
 make_syslinux() {
     if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
@@ -259,6 +296,7 @@ make_common_single() {
     make_packages
     make_setup_mkinitcpio
     make_boot
+    make_boot_efi
     make_syslinux
     make_isolinux
     make_customize_root_image
diff --git a/configs/releng/efiboot/EFI/boot/startup.nsh b/configs/releng/efiboot/EFI/boot/startup.nsh
new file mode 100644
index 0000000..1188d2a
--- /dev/null
+++ b/configs/releng/efiboot/EFI/boot/startup.nsh
@@ -0,0 +1,10 @@
+echo -off
+
+for %m in (0 9)
+    if exist fs%m:\EFI\archiso\vmlinuz.efi then
+        fs%m:
+        cd fs%m:\EFI\archiso
+        echo "Launching Arch Linux ISO Kernel fs%m:\EFI\archiso\vmlinuz.efi"
+        vmlinuz.efi archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% initrd=\EFI\archiso\archiso.img
+    endif
+endfor
-- 
1.7.9.5



More information about the arch-releng mailing list