diff --git a/build_library/grub.cfg b/build_library/grub.cfg index 99433f23c0..86c0d813eb 100644 --- a/build_library/grub.cfg +++ b/build_library/grub.cfg @@ -1,5 +1,17 @@ # Main GRUB config +# figure out the root +if [ "$grub_platform" = "efi" ]; then + if [ -e "($cmddevice)/isolinux/efi.img" ]; then + set isoboot="1" + fi + + # on efi, $cmddevice has the disk grub was invoked from. + set root="$cmddevice" +else + search --fs-uuid @@ESP_FSID@@ --set root --hint "$root" +fi + # Set the prefix back to the correct value after we're done with memdisk set prefix=($root)/coreos/grub @@ -57,7 +69,7 @@ if [ "$net_default_server" != "" ]; then fi # Search for the OEM partition, load additional configuration if found. -if [ "$secure_boot" = "0" ]; then +if [ "$secure_boot" = "0" -a -z "$isoboot" ]; then search --no-floppy --set oem --part-label OEM --hint "$root" if [ -n "$oem" -a -f "($oem)/grub.cfg" ]; then source "($oem)/grub.cfg" @@ -65,15 +77,17 @@ if [ "$secure_boot" = "0" ]; then fi # Determine if this is a first boot. -search --no-floppy --set first_boot \ - --disk-uuid 00000000-0000-0000-0000-000000000001 -if [ -n "$first_boot" ]; then - # Note we explicitly request the disk-guid randomization, first_boot only triggers ignition. - set first_boot="coreos.first_boot=1 coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001" -fi - -if [ -n "$oem_id" ]; then - set oem_id="coreos.oem.id=$oem_id" +if [ -z "$isoboot" ]; then + search --no-floppy --set first_boot \ + --disk-uuid 00000000-0000-0000-0000-000000000001 + if [ -n "$first_boot" ]; then + # Note we explicitly request the disk-guid randomization, first_boot only triggers ignition. + set first_boot="coreos.first_boot=1 coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001" + fi + + if [ -n "$oem_id" ]; then + set oem_id="coreos.oem.id=$oem_id" + fi fi # If no specific console has been set by the OEM then select based on @@ -107,19 +121,27 @@ fi # Assemble the options applicable to all the kernels below set linux_cmdline="rootflags=rw mount.usrflags=ro consoleblank=0 $linux_root $linux_console $first_boot $oem_id $linux_append" -menuentry "CoreOS default" --id=coreos { - gptprio.next -d usr -u usr_uuid - if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then - linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline - else - linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline - fi -} - -menuentry "CoreOS USR-A" --id=coreos-a { - linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTLABEL=USR-A $linux_cmdline -} +if [ -z "$isoboot" ]; then + menuentry "CoreOS default" --id=coreos { + gptprio.next -d usr -u usr_uuid + if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then + linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline + else + linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline + fi + } + + menuentry "CoreOS USR-A" --id=coreos-a { + linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTLABEL=USR-A $linux_cmdline + } + + menuentry "CoreOS USR-B" --id=coreos-b { + linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTLABEL=USR-B $linux_cmdline + } +else + menuentry "CoreOS default" --id=coreos { + linux$suf /coreos/vmlinuz coreos.autologin= $linux_console + initrd$suf /coreos/cpio.gz + } +fi -menuentry "CoreOS USR-B" --id=coreos-b { - linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTLABEL=USR-B $linux_cmdline -} diff --git a/build_library/grub_install.sh b/build_library/grub_install.sh index 9737e615ae..98a29a26ec 100755 --- a/build_library/grub_install.sh +++ b/build_library/grub_install.sh @@ -54,14 +54,14 @@ case "${FLAGS_target}" in CORE_NAME="core.img" ;; x86_64-efi) - CORE_MODULES+=( serial linuxefi efi_gop getenv smbios efinet verify http ) + CORE_MODULES+=( serial linuxefi efi_gop getenv smbios efinet verify http iso9660 ) CORE_NAME="core.efi" ;; x86_64-xen) CORE_NAME="core.elf" ;; arm64-efi) - CORE_MODULES+=( serial efi_gop getenv smbios efinet verify http ) + CORE_MODULES+=( serial linux efi_gop getenv smbios efinet verify http iso9660 ) CORE_NAME="core.efi" BOARD_GRUB=1 ;; @@ -134,12 +134,8 @@ for file in "${GRUB_SRC}"/*{.lst,.mod}; do done info "Generating ${GRUB_DIR}/load.cfg" -# Include a small initial config in the core image to search for the ESP -# by filesystem ID in case the platform doesn't provide the boot disk. -# The existing $root value is given as a hint so it is searched first. -ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1") +# Include a small initial config to set prefix and dump variables. sudo_clobber "${ESP_DIR}/${GRUB_DIR}/load.cfg" < "${GRUB_TEMP_DIR}/grub.cfg" fi + # fix up ESP UUID for PC boot. EFI boot will be able to provide the disk to grub. + sed --in-place --expression "s/@@ESP_FSID@@/${ESP_FSID}/" "${GRUB_TEMP_DIR}/grub.cfg" + sudo tar cf "${ESP_DIR}/coreos/grub/grub.cfg.tar" \ -C "${GRUB_TEMP_DIR}" "grub.cfg" fi diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 770176758b..808e667c44 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -570,16 +570,17 @@ _write_cpio_disk() { } _write_iso_disk() { - local base_dir="${VM_TMP_ROOT}/usr" + local base_dir="${VM_TMP_ROOT}" local iso_target="${VM_TMP_DIR}/rootiso" local dst_dir=$(_dst_dir) local vmlinuz_name="$(_dst_name ".vmlinuz")" + local efi_img="isolinux/efi.img" mkdir "${iso_target}" pushd "${iso_target}" >/dev/null mkdir isolinux syslinux coreos _write_cpio_common "$1" "${iso_target}/coreos/cpio.gz" - cp "${base_dir}"/boot/vmlinuz "${iso_target}/coreos/vmlinuz" + cp "${base_dir}/boot/coreos/vmlinuz-a" "${iso_target}/coreos/vmlinuz" cp -R /usr/share/syslinux/* isolinux/ cat< isolinux/isolinux.cfg INCLUDE /syslinux/syslinux.cfg @@ -594,8 +595,59 @@ label coreos kernel /coreos/vmlinuz append initrd=/coreos/cpio.gz coreos.autologin EOF - mkisofs -v -l -r -J -o $2 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . - isohybrid $2 + + + # this weird dance is here because isolinux and isohybrid work for amd64, + # but not arm64. also, a bare FAT partition works for amd64 in QEMU/OVMF, + # but not for arm64 in QEMU/ArmVirtPkg. however, a full GPT image with an + # ESP inside *does* work for QEMU/ArmVirtPkg. + case $BOARD in + amd64-usr) + mformat -i "${efi_img}" -C -v COREOS -f 2880 + + mmd -i "${efi_img}" EFI + mmd -i "${efi_img}" EFI/BOOT + + mcopy -i "${efi_img}" -o "${base_dir}"/boot/EFI/boot/* "::EFI/BOOT/" + + mkisofs -v -l -r -J -o $2 \ + -eltorito-boot isolinux/isolinux.bin \ + -eltorito-catalog isolinux/boot.cat \ + -no-emul-boot \ + -boot-load-size 4 \ + -boot-info-table \ + -eltorito-alt-boot \ + -eltorito-platform efi \ + -eltorito-boot "${efi_img}" \ + -no-emul-boot \ + . + + isohybrid --uefi $2 + ;; + arm64-usr) + dd if=/dev/zero of="${efi_img}" bs=1MiB count=3 + sgdisk --zap-all "${efi_img}" + sgdisk --largest-new=1 "${efi_img}" + sgdisk --typecode=1:EF00 "${efi_img}" + sgdisk --change-name=1:COREOS "${efi_img}" + sgdisk --verify "${efi_img}" + + mformat -i "${efi_img}"@@1M -v COREOS -f 2880 + + mmd -i "${efi_img}"@@1M EFI + mmd -i "${efi_img}"@@1M EFI/BOOT + + mcopy -i "${efi_img}"@@1M -o "${base_dir}"/boot/EFI/boot/* "::EFI/BOOT/" + + mkisofs -v -l -r -J -o $2 \ + -eltorito-platform efi \ + -eltorito-boot "${efi_img}" \ + -boot-info-table \ + -no-emul-boot \ + . + ;; + esac + popd >/dev/null }