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

Commit 6b0a548

Browse files
author
Nick Owens
committed
build_library: support uefi boot from iso
1 parent 8ce4a15 commit 6b0a548

3 files changed

Lines changed: 92 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: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ _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")"
@@ -579,7 +579,7 @@ _write_iso_disk() {
579579
pushd "${iso_target}" >/dev/null
580580
mkdir isolinux syslinux coreos
581581
_write_cpio_common "$1" "${iso_target}/coreos/cpio.gz"
582-
cp "${base_dir}"/boot/vmlinuz "${iso_target}/coreos/vmlinuz"
582+
cp "${base_dir}/boot/coreos/vmlinuz-a" "${iso_target}/coreos/vmlinuz"
583583
cp -R /usr/share/syslinux/* isolinux/
584584
cat<<EOF > isolinux/isolinux.cfg
585585
INCLUDE /syslinux/syslinux.cfg
@@ -594,8 +594,42 @@ label coreos
594594
kernel /coreos/vmlinuz
595595
append initrd=/coreos/cpio.gz coreos.autologin
596596
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
597+
598+
# create fat image of grub for EFI
599+
mformat -i isolinux/efi.img -C -v EFI -f 2880
600+
mmd -i isolinux/efi.img EFI
601+
mmd -i isolinux/efi.img EFI/BOOT
602+
603+
mcopy -i isolinux/efi.img -o "${base_dir}"/boot/EFI/boot/* "::EFI/BOOT/"
604+
605+
# syslinux won't work on arm64, and there is no point in isohybrid
606+
# for arm64/uefi.
607+
case $BOARD in
608+
amd64-usr)
609+
mkisofs -v -l -r -J -o $2 \
610+
-eltorito-boot isolinux/isolinux.bin \
611+
-eltorito-catalog isolinux/boot.cat \
612+
-no-emul-boot \
613+
-boot-load-size 4 \
614+
-boot-info-table \
615+
-eltorito-alt-boot \
616+
-eltorito-platform efi \
617+
-eltorito-boot isolinux/efi.img \
618+
-no-emul-boot \
619+
.
620+
621+
isohybrid --uefi $2
622+
;;
623+
arm64-usr)
624+
mkisofs -v -l -r -J -o $2 \
625+
-eltorito-platform efi \
626+
-eltorito-boot isolinux/efi.img \
627+
-boot-info-table \
628+
-no-emul-boot \
629+
.
630+
;;
631+
esac
632+
599633
popd >/dev/null
600634
}
601635

0 commit comments

Comments
 (0)