-
-
Save tseglevskiy/676e0ffedae141f1303f794897da40ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Main GRUB config | |
# Set the prefix back to the correct value after we're done with memdisk | |
set prefix=($root)/coreos/grub | |
# Load any and all video drivers. | |
# Required under UEFI to boot Linux with a working console. | |
insmod all_video | |
# Default menuentry id and boot timeout | |
set default="coreos" | |
set timeout=1 | |
# Default kernel args for root filesystem, console, and CoreOS. | |
set linux_root="root=LABEL=ROOT" | |
set linux_console="" | |
set first_boot="" | |
set randomize_disk_guid="" | |
set oem_id="" | |
# Anything else the OEM adds should use this variable. | |
set linux_append="" | |
set secure_boot="0" | |
if [ "$grub_platform" = "efi" ]; then | |
getenv -e SecureBoot -g 8be4df61-93ca-11d2-aa0d-00e098032b8c -b sb | |
getenv -e SetupMode -g 8be4df61-93ca-11d2-aa0d-00e098032b8c -b setupmode | |
if [ "$sb" = "01" -a "$setupmode" = "00" ]; then | |
set secure_boot="1" | |
getenv -e NetBootVerificationKey -g b8ade7d5-d400-4213-8d15-d47be0a621bf -b gpgpubkey | |
if [ "$gpgpubkey" != "" ]; then | |
trust_var gpgpubkey | |
fi | |
fi | |
fi | |
if [ "$net_default_server" != "" ]; then | |
smbios --type 1 --get-uuid 8 --set uuid | |
smbios --type 1 --get-string 7 --set serial | |
set mac=$net_default_mac | |
# Re-DHCP as grub to get the API endpoint | |
net_bootp $net_default_interface | |
# This is awful, but grub doesn't support a nice way to do this | |
for i in "$net_efinet0_dhcp_boot_file" "$net_efinet1_dhcp_boot_file" "$net_efinet2_dhcp_boot_file" "$net_efinet3_dhcp_boot_file" "$net_efinet4_dhcp_boot_file" "$net_efinet5_dhcp_boot_file" "$net_efinet6_dhcp_boot_file" "$net_efinet7_dhcp_boot_file" "$net_efinet8_dhcp_boot_file" "$net_efinet9_dhcp_boot_file"; do | |
if [ "$i" != "" ]; then | |
set endpoint="$i" | |
break | |
fi | |
done | |
if [ "$endpoint" != "" ]; then | |
set url="${endpoint}?uuid=$uuid&serial=$serial&mac=$mac" | |
if [ "$gpgpubkey" != "" ]; then | |
set check_signatures="enforce" | |
fi | |
configfile $url | |
fi | |
fi | |
# Search for the OEM partition, load additional configuration if found. | |
if [ "$secure_boot" = "0" ]; then | |
search --no-floppy --set oem --label OEM "$root" | |
if [ -n "$oem" -a -f "($oem)/grub.cfg" ]; then | |
source "($oem)/grub.cfg" | |
fi | |
fi | |
# Determine if this is a first boot. | |
if [ -f "($root)/coreos/first_boot" ]; then | |
set first_boot="coreos.first_boot=detected" | |
fi | |
# Determine if the disk GUID needs to be randomized. | |
search --no-floppy --set randomize_disk_guid --fs-uuid 00000000-0000-0000-0000-000000000001 | |
if [ -n "$randomize_disk_guid" ]; then | |
set randomize_disk_guid="coreos.randomize_disk_guid=00000000-0000-0000-0000-000000000001" | |
fi | |
set oem="" | |
if [ -n "$oem_id" ]; then | |
set oem="coreos.oem.id=$oem_id" | |
fi | |
# If no specific console has been set by the OEM then select based on | |
# platform, most systems use vga text as primary and ttyS0 as secondary. | |
if [ -z "$linux_console" ]; then | |
if [ "$grub_platform" = pc ]; then | |
set linux_console="console=ttyS0,115200n8 console=tty0" | |
serial com0 --speed=115200 --word=8 --parity=no | |
terminal_input console serial_com0 | |
terminal_output console serial_com0 | |
elif [ "$grub_platform" = efi ]; then | |
set linux_console="console=ttyS0,115200n8 console=tty0" | |
elif [ "$grub_platform" = xen ]; then | |
set linux_console="console=hvc0" | |
fi | |
fi | |
set suf="" | |
# UEFI uses linuxefi/initrdefi instead of linux/initrd | |
if [ "$grub_platform" = efi ]; then | |
set suf="efi" | |
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 $randomize_disk_guid $oem $linux_append" | |
# Re-implement grub_abort() since no command exposes it. | |
function abort { | |
echo | |
echo "Aborted. Press enter to exit GRUB." | |
read anything | |
exit | |
} | |
# Select the kernel and usr partition to boot. | |
function gptprio { | |
# TODO: device name is no longer needed, should make it optional... | |
gptprio.next -d usr_device -u usr_uuid | |
if [ $? -ne 0 -o -z "$usr_uuid" ]; then | |
echo | |
echo "Reading or updating the GPT failed!" | |
echo "Please file a bug with any messages above to CoreOS:" | |
echo " https://issues.coreos.com" | |
abort | |
fi | |
set gptprio_cmdline="mount.usr=PARTUUID=$usr_uuid" | |
if [ "$usr_uuid" = "7130c94a-213a-4e5a-8e26-6cce9662f132" ]; then | |
set gptprio_kernel="/coreos/vmlinuz-a" | |
else | |
set gptprio_kernel="/coreos/vmlinuz-b" | |
fi | |
} | |
menuentry "CoreOS default" --id=coreos --unrestricted { | |
gptprio | |
linux$suf $gptprio_kernel $gptprio_cmdline $linux_cmdline | |
} | |
menuentry "CoreOS USR-A" --id=coreos-a { | |
linux$suf /coreos/vmlinuz-a mount.usr=PARTLABEL=USR-A $linux_cmdline | |
} | |
menuentry "CoreOS USR-B" --id=coreos-b { | |
linux$suf /coreos/vmlinuz-b mount.usr=PARTLABEL=USR-B $linux_cmdline | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment