Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 9e68ec0

Browse files
Nick OwensCoreOS Admin
authored andcommitted
build_library: support uefi boot from iso
1 parent 8ce4a15 commit 9e68ec0

3 files changed

Lines changed: 110 additions & 36 deletions

File tree

build_library/grub.cfg

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Main GRUB config
22

3+
# figure out the root
4+
if [ "$grub_platform" = "efi" ]; then
5+
if [ -e "($cmddevice)/isolinux/efi.img" ]; then
6+
set isoboot="1"
7+
fi
8+
9+
# on efi, $cmddevice has the disk grub was invoked from.
10+
set root="$cmddevice"
11+
else
12+
search --fs-uuid @@ESP_FSID@@ --set root --hint "$root"
13+
fi
14+
315
# Set the prefix back to the correct value after we're done with memdisk
416
set prefix=($root)/coreos/grub
517

@@ -57,23 +69,25 @@ if [ "$net_default_server" != "" ]; then
5769
fi
5870

5971
# Search for the OEM partition, load additional configuration if found.
60-
if [ "$secure_boot" = "0" ]; then
72+
if [ "$secure_boot" = "0" -a -z "$isoboot" ]; then
6173
search --no-floppy --set oem --part-label OEM --hint "$root"
6274
if [ -n "$oem" -a -f "($oem)/grub.cfg" ]; then
6375
source "($oem)/grub.cfg"
6476
fi
6577
fi
6678

6779
# Determine if this is a first boot.
68-
search --no-floppy --set first_boot \
69-
--disk-uuid 00000000-0000-0000-0000-000000000001
70-
if [ -n "$first_boot" ]; then
71-
# Note we explicitly request the disk-guid randomization, first_boot only triggers ignition.
72-
set first_boot="coreos.first_boot=1 coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001"
73-
fi
74-
75-
if [ -n "$oem_id" ]; then
76-
set oem_id="coreos.oem.id=$oem_id"
80+
if [ -z "$isoboot" ]; then
81+
search --no-floppy --set first_boot \
82+
--disk-uuid 00000000-0000-0000-0000-000000000001
83+
if [ -n "$first_boot" ]; then
84+
# Note we explicitly request the disk-guid randomization, first_boot only triggers ignition.
85+
set first_boot="coreos.first_boot=1 coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001"
86+
fi
87+
88+
if [ -n "$oem_id" ]; then
89+
set oem_id="coreos.oem.id=$oem_id"
90+
fi
7791
fi
7892

7993
# If no specific console has been set by the OEM then select based on
@@ -107,19 +121,27 @@ fi
107121
# Assemble the options applicable to all the kernels below
108122
set linux_cmdline="rootflags=rw mount.usrflags=ro consoleblank=0 $linux_root $linux_console $first_boot $oem_id $linux_append"
109123

110-
menuentry "CoreOS default" --id=coreos {
111-
gptprio.next -d usr -u usr_uuid
112-
if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then
113-
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
114-
else
115-
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
116-
fi
117-
}
118-
119-
menuentry "CoreOS USR-A" --id=coreos-a {
120-
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTLABEL=USR-A $linux_cmdline
121-
}
124+
if [ -z "$isoboot" ]; then
125+
menuentry "CoreOS default" --id=coreos {
126+
gptprio.next -d usr -u usr_uuid
127+
if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then
128+
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
129+
else
130+
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
131+
fi
132+
}
133+
134+
menuentry "CoreOS USR-A" --id=coreos-a {
135+
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTLABEL=USR-A $linux_cmdline
136+
}
137+
138+
menuentry "CoreOS USR-B" --id=coreos-b {
139+
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTLABEL=USR-B $linux_cmdline
140+
}
141+
else
142+
menuentry "CoreOS default" --id=coreos {
143+
linux$suf /coreos/vmlinuz coreos.autologin= $linux_console
144+
initrd$suf /coreos/cpio.gz
145+
}
146+
fi
122147

123-
menuentry "CoreOS USR-B" --id=coreos-b {
124-
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTLABEL=USR-B $linux_cmdline
125-
}

build_library/grub_install.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ case "${FLAGS_target}" in
5454
CORE_NAME="core.img"
5555
;;
5656
x86_64-efi)
57-
CORE_MODULES+=( serial linuxefi efi_gop getenv smbios efinet verify http )
57+
CORE_MODULES+=( serial linuxefi efi_gop getenv smbios efinet verify http iso9660 )
5858
CORE_NAME="core.efi"
5959
;;
6060
x86_64-xen)
6161
CORE_NAME="core.elf"
6262
;;
6363
arm64-efi)
64-
CORE_MODULES+=( serial efi_gop getenv smbios efinet verify http )
64+
CORE_MODULES+=( serial linux efi_gop getenv smbios efinet verify http iso9660 )
6565
CORE_NAME="core.efi"
6666
BOARD_GRUB=1
6767
;;
@@ -134,19 +134,16 @@ for file in "${GRUB_SRC}"/*{.lst,.mod}; do
134134
done
135135

136136
info "Generating ${GRUB_DIR}/load.cfg"
137-
# Include a small initial config in the core image to search for the ESP
138-
# by filesystem ID in case the platform doesn't provide the boot disk.
139-
# The existing $root value is given as a hint so it is searched first.
140-
ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1")
137+
# Include a small initial config to set prefix and dump variables.
141138
sudo_clobber "${ESP_DIR}/${GRUB_DIR}/load.cfg" <<EOF
142-
search.fs_uuid ${ESP_FSID} root \$root
143139
set prefix=(memdisk)
144140
set
145141
EOF
146142

147143
# Generate a memdisk containing the appropriately generated grub.cfg. Doing
148144
# this because we need conflicting default behaviors between verity and
149145
# non-verity images.
146+
ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1")
150147
GRUB_TEMP_DIR=$(mktemp -d)
151148
if [[ ! -f "${ESP_DIR}/coreos/grub/grub.cfg.tar" ]]; then
152149
info "Generating grub.cfg memdisk"
@@ -162,6 +159,9 @@ if [[ ! -f "${ESP_DIR}/coreos/grub/grub.cfg.tar" ]]; then
162159
sed 's/@@MOUNTUSR@@/mount.usr/' > "${GRUB_TEMP_DIR}/grub.cfg"
163160
fi
164161

162+
# fix up ESP UUID for PC boot. EFI boot will be able to provide the disk to grub.
163+
sed --in-place --expression "s/@@ESP_FSID@@/${ESP_FSID}/" "${GRUB_TEMP_DIR}/grub.cfg"
164+
165165
sudo tar cf "${ESP_DIR}/coreos/grub/grub.cfg.tar" \
166166
-C "${GRUB_TEMP_DIR}" "grub.cfg"
167167
fi

build_library/vm_image_util.sh

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,17 @@ _write_cpio_disk() {
570570
}
571571

572572
_write_iso_disk() {
573-
local base_dir="${VM_TMP_ROOT}/usr"
573+
local base_dir="${VM_TMP_ROOT}"
574574
local iso_target="${VM_TMP_DIR}/rootiso"
575575
local dst_dir=$(_dst_dir)
576576
local vmlinuz_name="$(_dst_name ".vmlinuz")"
577+
local efi_img="isolinux/efi.img"
577578

578579
mkdir "${iso_target}"
579580
pushd "${iso_target}" >/dev/null
580581
mkdir isolinux syslinux coreos
581582
_write_cpio_common "$1" "${iso_target}/coreos/cpio.gz"
582-
cp "${base_dir}"/boot/vmlinuz "${iso_target}/coreos/vmlinuz"
583+
cp "${base_dir}/boot/coreos/vmlinuz-a" "${iso_target}/coreos/vmlinuz"
583584
cp -R /usr/share/syslinux/* isolinux/
584585
cat<<EOF > isolinux/isolinux.cfg
585586
INCLUDE /syslinux/syslinux.cfg
@@ -594,8 +595,59 @@ label coreos
594595
kernel /coreos/vmlinuz
595596
append initrd=/coreos/cpio.gz coreos.autologin
596597
EOF
597-
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 .
598-
isohybrid $2
598+
599+
600+
# this weird dance is here because isolinux and isohybrid work for amd64,
601+
# but not arm64. also, a bare FAT partition works for amd64 in QEMU/OVMF,
602+
# but not for arm64 in QEMU/ArmVirtPkg. however, a full GPT image with an
603+
# ESP inside *does* work for QEMU/ArmVirtPkg.
604+
case $BOARD in
605+
amd64-usr)
606+
mformat -i "${efi_img}" -C -v COREOS -f 2880
607+
608+
mmd -i "${efi_img}" EFI
609+
mmd -i "${efi_img}" EFI/BOOT
610+
611+
mcopy -i "${efi_img}" -o "${base_dir}"/boot/EFI/boot/* "::EFI/BOOT/"
612+
613+
mkisofs -v -l -r -J -o $2 \
614+
-eltorito-boot isolinux/isolinux.bin \
615+
-eltorito-catalog isolinux/boot.cat \
616+
-no-emul-boot \
617+
-boot-load-size 4 \
618+
-boot-info-table \
619+
-eltorito-alt-boot \
620+
-eltorito-platform efi \
621+
-eltorito-boot "${efi_img}" \
622+
-no-emul-boot \
623+
.
624+
625+
isohybrid --uefi $2
626+
;;
627+
arm64-usr)
628+
dd if=/dev/zero of="${efi_img}" bs=1MiB count=3
629+
sgdisk --zap-all "${efi_img}"
630+
sgdisk --largest-new=1 "${efi_img}"
631+
sgdisk --typecode=1:EF00 "${efi_img}"
632+
sgdisk --change-name=1:COREOS "${efi_img}"
633+
sgdisk --verify "${efi_img}"
634+
635+
mformat -i "${efi_img}"@@1M -v COREOS -f 2880
636+
637+
mmd -i "${efi_img}"@@1M EFI
638+
mmd -i "${efi_img}"@@1M EFI/BOOT
639+
640+
mcopy -i "${efi_img}"@@1M -o "${base_dir}"/boot/EFI/boot/* "::EFI/BOOT/"
641+
642+
mkisofs -v -l -r -J -o $2 \
643+
-eltorito-platform efi \
644+
-eltorito-boot "${efi_img}" \
645+
-boot-info-table \
646+
-no-emul-boot \
647+
.
648+
;;
649+
esac
650+
599651
popd >/dev/null
600652
}
601653

0 commit comments

Comments
 (0)