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

Commit 831af0f

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

File tree

3 files changed

+82
-36
lines changed

3 files changed

+82
-36
lines changed

build_library/grub.cfg

+50-25
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

+7-7
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

+25-4
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,9 +594,30 @@ 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+
mkisofs -v -l -r -J -o $2 \
606+
-eltorito-boot isolinux/isolinux.bin \
607+
-eltorito-catalog isolinux/boot.cat \
608+
-no-emul-boot \
609+
-boot-load-size 4 \
610+
-boot-info-table \
611+
-eltorito-alt-boot \
612+
-eltorito-platform efi \
613+
-eltorito-boot isolinux/efi.img \
614+
-no-emul-boot \
615+
.
616+
617+
isohybrid --uefi $2
618+
599619
popd >/dev/null
620+
600621
}
601622

602623
# If a config format is defined write it!

0 commit comments

Comments
 (0)