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

Commit 812a105

Browse files
author
Nick Owens
committed
build_library: support uefi boot from iso
1 parent 39c3ec9 commit 812a105

File tree

3 files changed

+98
-43
lines changed

3 files changed

+98
-43
lines changed

build_library/grub.cfg

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

3+
# dump vars as they are when grub loads this config
4+
set
5+
6+
# figure out the root
7+
if [ "$grub_platform" = "efi" ]; then
8+
if [ -e "$cmddevice/isolinux/efi.img" ]; then
9+
set isoboot="1"
10+
fi
11+
12+
# on efi, $cmddevice has the disk grub was invoked from.
13+
set root="$cmddevice"
14+
else
15+
search --fs-uuid @@ESP_FSID@@ --set root --hint "$root"
16+
fi
17+
318
# Set the prefix back to the correct value after we're done with memdisk
419
set prefix=($root)/coreos/grub
520

@@ -57,23 +72,25 @@ if [ "$net_default_server" != "" ]; then
5772
fi
5873

5974
# Search for the OEM partition, load additional configuration if found.
60-
if [ "$secure_boot" = "0" ]; then
75+
if [ "$secure_boot" = "0" -a -z "$isoboot" ]; then
6176
search --no-floppy --set oem --part-label OEM --hint "$root"
6277
if [ -n "$oem" -a -f "($oem)/grub.cfg" ]; then
6378
source "($oem)/grub.cfg"
6479
fi
6580
fi
6681

6782
# 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"
83+
if [ -z "$isoboot" ]; then
84+
search --no-floppy --set first_boot \
85+
--disk-uuid 00000000-0000-0000-0000-000000000001
86+
if [ -n "$first_boot" ]; then
87+
# Note we explicitly request the disk-guid randomization, first_boot only triggers ignition.
88+
set first_boot="coreos.first_boot=1 coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001"
89+
fi
90+
91+
if [ -n "$oem_id" ]; then
92+
set oem_id="coreos.oem.id=$oem_id"
93+
fi
7794
fi
7895

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

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-
}
127+
if [ -z "$isoboot" ]; then
128+
menuentry "CoreOS default" --id=coreos {
129+
gptprio.next -d usr -u usr_uuid
130+
if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then
131+
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
132+
else
133+
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTUUID=$usr_uuid $linux_cmdline
134+
fi
135+
}
136+
137+
menuentry "CoreOS USR-A" --id=coreos-a {
138+
linux$suf /coreos/vmlinuz-a @@MOUNTUSR@@=PARTLABEL=USR-A $linux_cmdline
139+
}
140+
141+
menuentry "CoreOS USR-B" --id=coreos-b {
142+
linux$suf /coreos/vmlinuz-b @@MOUNTUSR@@=PARTLABEL=USR-B $linux_cmdline
143+
}
144+
else
145+
menuentry "CoreOS default" --id=coreos {
146+
linux$suf /coreos/vmlinuz coreos.autologin= $linux_console
147+
initrd$suf /coreos/cpio.gz
148+
}
149+
fi
122150

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: 6 additions & 14 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
;;
@@ -133,20 +133,10 @@ for file in "${GRUB_SRC}"/*{.lst,.mod}; do
133133
gzip --best --stdout "${file}" | sudo_clobber "${out}"
134134
done
135135

136-
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")
141-
sudo_clobber "${ESP_DIR}/${GRUB_DIR}/load.cfg" <<EOF
142-
search.fs_uuid ${ESP_FSID} root \$root
143-
set prefix=(memdisk)
144-
set
145-
EOF
146-
147136
# Generate a memdisk containing the appropriately generated grub.cfg. Doing
148137
# this because we need conflicting default behaviors between verity and
149138
# non-verity images.
139+
ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1")
150140
GRUB_TEMP_DIR=$(mktemp -d)
151141
if [[ ! -f "${ESP_DIR}/coreos/grub/grub.cfg.tar" ]]; then
152142
info "Generating grub.cfg memdisk"
@@ -162,6 +152,9 @@ if [[ ! -f "${ESP_DIR}/coreos/grub/grub.cfg.tar" ]]; then
162152
sed 's/@@MOUNTUSR@@/mount.usr/' > "${GRUB_TEMP_DIR}/grub.cfg"
163153
fi
164154

155+
# fix up ESP UUID for PC boot. EFI boot will be able to provide the disk to grub.
156+
sed --in-place --expression "s/@@ESP_FSID@@/${ESP_FSID}/" "${GRUB_TEMP_DIR}/grub.cfg"
157+
165158
sudo tar cf "${ESP_DIR}/coreos/grub/grub.cfg.tar" \
166159
-C "${GRUB_TEMP_DIR}" "grub.cfg"
167160
fi
@@ -171,7 +164,6 @@ sudo grub-mkimage \
171164
--compression=auto \
172165
--format "${FLAGS_target}" \
173166
--directory "${GRUB_SRC}" \
174-
--config "${ESP_DIR}/${GRUB_DIR}/load.cfg" \
175167
--memdisk "${ESP_DIR}/coreos/grub/grub.cfg.tar" \
176168
--output "${ESP_DIR}/${GRUB_DIR}/${CORE_NAME}" \
177169
"${CORE_MODULES[@]}"

build_library/vm_image_util.sh

Lines changed: 42 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"
575+
local fat_target="${VM_TMP_DIR}/rootfat"
575576
local dst_dir=$(_dst_dir)
576577
local vmlinuz_name="$(_dst_name ".vmlinuz")"
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}/usr/boot/vmlinuz" "${iso_target}/coreos/vmlinuz"
583584
cp -R /usr/share/syslinux/* isolinux/
584585
cat<<EOF > isolinux/isolinux.cfg
585586
INCLUDE /syslinux/syslinux.cfg
@@ -594,9 +595,46 @@ 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+
# create fat image of grub for EFI
600+
# 2880K floppy which fits our grub nicely.
601+
dd if=/dev/zero of=isolinux/efi.img bs=512 count=5760 2>/dev/null
602+
mformat -i isolinux/efi.img -v EFI -f 2880
603+
mmd -i isolinux/efi.img efi
604+
mmd -i isolinux/efi.img efi/boot
605+
606+
local grub_arch
607+
local grub_name
608+
case $BOARD in
609+
amd64-usr)
610+
loader_name="bootx64.efi"
611+
# this copies shim+grub to the fat
612+
mcopy -i isolinux/efi.img -o "${base_dir}/boot/efi/boot/${loader_name}" "::efi/boot/${loader_name}"
613+
mcopy -i isolinux/efi.img -o "${base_dir}/boot/efi/boot/grub.efi" "::efi/boot/grub.efi"
614+
;;
615+
arm64-usr)
616+
# no shim on arm64 yet.
617+
loader_name="bootaa64.efi"
618+
mcopy -i isolinux/efi.img -o "${base_dir}/boot/efi/boot/${loader_name}" "::efi/boot/${loader_name}"
619+
;;
620+
esac
621+
622+
mkisofs -v -l -r -J -o $2 \
623+
-eltorito-boot isolinux/isolinux.bin \
624+
-eltorito-catalog isolinux/boot.cat \
625+
-no-emul-boot \
626+
-boot-load-size 4 \
627+
-boot-info-table \
628+
-eltorito-alt-boot \
629+
-eltorito-platform efi \
630+
-eltorito-boot isolinux/efi.img \
631+
-no-emul-boot \
632+
.
633+
634+
isohybrid --uefi $2
635+
599636
popd >/dev/null
637+
600638
}
601639

602640
# If a config format is defined write it!

0 commit comments

Comments
 (0)