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

Commit

Permalink
build_library: support uefi boot from iso
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Owens committed Jun 1, 2016
1 parent 39c3ec9 commit d2c3dcd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 31 deletions.
60 changes: 35 additions & 25 deletions build_library/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,25 @@ 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"
fi
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
Expand Down Expand Up @@ -107,19 +109,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
}
8 changes: 6 additions & 2 deletions build_library/grub_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -140,6 +140,10 @@ info "Generating ${GRUB_DIR}/load.cfg"
ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1")
sudo_clobber "${ESP_DIR}/${GRUB_DIR}/load.cfg" <<EOF
search.fs_uuid ${ESP_FSID} root \$root
if [ "$root" = "(memdisk)" ]; then
set root="(hd0)"
set isoboot="1"
fi
set prefix=(memdisk)
set
EOF
Expand Down
44 changes: 40 additions & 4 deletions build_library/vm_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 fat_target="${VM_TMP_DIR}/rootfat"
local dst_dir=$(_dst_dir)
local vmlinuz_name="$(_dst_name ".vmlinuz")"

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}/usr/boot/vmlinuz" "${iso_target}/coreos/vmlinuz"
cp -R /usr/share/syslinux/* isolinux/
cat<<EOF > isolinux/isolinux.cfg
INCLUDE /syslinux/syslinux.cfg
Expand All @@ -594,9 +595,44 @@ 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

# create fat image of grub for EFI
local grub_arch
local grub_name
case $BOARD in
amd64-usr)
grub_arch="x86_64-efi"
grub_name="bootx64.efi"
;;
arm64-usr)
grub_arch="arm64-efi"
grub_name="bootaa64.efi"
;;
esac

# 2880K floppy which fits our grub nicely.
dd if=/dev/zero of=isolinux/efi.img bs=512 count=5760 2>/dev/null
mformat -i isolinux/efi.img -v EFI -f 2880
mmd -i isolinux/efi.img efi
mmd -i isolinux/efi.img efi/boot
mcopy -i isolinux/efi.img -o "${base_dir}/boot/coreos/grub/${grub_arch}/core.efi" "::efi/boot/${grub_name}"

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 isolinux/efi.img \
-no-emul-boot \
.

isohybrid --uefi $2

popd >/dev/null

}

# If a config format is defined write it!
Expand Down

0 comments on commit d2c3dcd

Please sign in to comment.