mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
fix(build_image): Configure legacy bootloaders to set root by UUID.
Make use of the new partition UUIDs for ROOT-A and ROOT-B in the root= kernel parameters provided by the legacy (non-kexec) bootloaders. This makes all of our images bootable as-is without having to pass them through image_to_vm.sh. :-D
This commit is contained in:
parent
21b9f711a4
commit
3fa29024e1
@ -485,6 +485,26 @@ def GetNum(options, image_type, layout_filename, label):
|
||||
return '-1'
|
||||
|
||||
|
||||
def GetUuid(options, image_type, layout_filename, label):
|
||||
"""Returns the unique partition UUID for a given label.
|
||||
|
||||
Note: Only useful if the UUID is specified in the config file, otherwise
|
||||
the value returned unlikely to be what is actually used in the image.
|
||||
|
||||
Args:
|
||||
options: Flags passed to the script
|
||||
image_type: Type of image eg base/test/dev/prod
|
||||
layout_filename: Path to partition configuration file
|
||||
label: Label of the partition you want to read from
|
||||
Returns:
|
||||
String containing the requested UUID
|
||||
"""
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options, layout_filename, image_type)
|
||||
partition = GetPartitionByLabel(partitions, label)
|
||||
return partition['uuid']
|
||||
|
||||
|
||||
def DoDebugOutput(options, image_type, layout_filename):
|
||||
"""Prints out a human readable disk layout in on-disk order.
|
||||
|
||||
@ -557,6 +577,10 @@ def main(argv):
|
||||
'usage': ['<image_type>', '<partition_config_file>', '<label>'],
|
||||
'func': GetNum,
|
||||
},
|
||||
'readuuid': {
|
||||
'usage': ['<image_type>', '<partition_config_file>', '<label>'],
|
||||
'func': GetUuid,
|
||||
},
|
||||
'debug': {
|
||||
'usage': ['<image_type>', '<partition_config_file>'],
|
||||
'func': DoDebugOutput,
|
||||
|
@ -37,6 +37,9 @@ FLAGS "$@" || exit 1
|
||||
eval set -- "${FLAGS_ARGV}"
|
||||
switch_to_strict_mode
|
||||
|
||||
# Useful for getting partition UUID values
|
||||
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
|
||||
|
||||
# Only let dm-verity block if rootfs verification is configured.
|
||||
# Also, set which device mapper correspondes to verity
|
||||
dev_wait=0
|
||||
@ -63,10 +66,11 @@ verity_common="${verity_common} dm_verity.dev_wait=${dev_wait}"
|
||||
# The templates are used by the installer to populate partition 12 with
|
||||
# the correct bootloader configuration.
|
||||
if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
|
||||
# TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
|
||||
# in the initramfs. When we figure that out, switch to root=UUID=${UUID}.
|
||||
sudo mkdir -p ${FLAGS_to}
|
||||
|
||||
# Get partition UUIDs from the json config
|
||||
ROOTA="PARTUUID=$(get_uuid base ROOT-A)"
|
||||
ROOTB="PARTUUID=$(get_uuid base ROOT-B)"
|
||||
|
||||
# Build configuration files for pygrub/pvgrub
|
||||
GRUB_DIR="${FLAGS_to}/boot/grub"
|
||||
@ -77,11 +81,11 @@ timeout 0
|
||||
|
||||
title CoreOS A
|
||||
root (hd0,0)
|
||||
kernel /syslinux/vmlinuz.A ${common_args} root=HDROOTA cros_legacy
|
||||
kernel /syslinux/vmlinuz.A ${common_args} root=${ROOTA} cros_legacy
|
||||
|
||||
title CoreOS B
|
||||
root (hd0,0)
|
||||
kernel /syslinux/vmlinuz.B ${common_args} root=HDROOTB cros_legacy
|
||||
kernel /syslinux/vmlinuz.B ${common_args} root=${ROOTB} cros_legacy
|
||||
EOF
|
||||
info "Emitted ${GRUB_DIR}/menu.lst.A"
|
||||
|
||||
@ -91,7 +95,6 @@ EOF
|
||||
sudo sh -c "cat ${GRUB_DIR}/menu.lst.A >> ${GRUB_DIR}/menu.lst.B"
|
||||
info "Emitted ${GRUB_DIR}/menu.lst.B"
|
||||
|
||||
# HDROOTA will be replaced in image_to_vm.sh
|
||||
sudo cp ${GRUB_DIR}/menu.lst.A ${GRUB_DIR}/menu.lst
|
||||
|
||||
# /boot/syslinux must be installed in partition 12 as /syslinux/.
|
||||
@ -126,7 +129,7 @@ EOF
|
||||
label coreos.A
|
||||
menu label coreos.A
|
||||
kernel vmlinuz.A
|
||||
append ${common_args} root=HDROOTA i915.modeset=1 cros_legacy
|
||||
append ${common_args} root=${ROOTA} i915.modeset=1 cros_legacy
|
||||
EOF
|
||||
info "Emitted ${SYSLINUX_DIR}/root.A.cfg"
|
||||
|
||||
@ -134,7 +137,7 @@ EOF
|
||||
label coreos.B
|
||||
menu label coreos.B
|
||||
kernel vmlinuz.B
|
||||
append ${common_args} root=HDROOTB i915.modeset=1 cros_legacy
|
||||
append ${common_args} root=${ROOTB} i915.modeset=1 cros_legacy
|
||||
EOF
|
||||
info "Emitted ${SYSLINUX_DIR}/root.B.cfg"
|
||||
|
||||
|
@ -112,6 +112,14 @@ get_num() {
|
||||
cgpt_py readnum "${image_type}" "${DISK_LAYOUT_PATH}" ${label}
|
||||
}
|
||||
|
||||
get_uuid() {
|
||||
local image_type=$1
|
||||
local label=$2
|
||||
get_disk_layout_path
|
||||
|
||||
cgpt_py readuuid "${image_type}" "${DISK_LAYOUT_PATH}" ${label}
|
||||
}
|
||||
|
||||
check_valid_layout() {
|
||||
local image_type=$1
|
||||
get_disk_layout_path
|
||||
|
@ -145,41 +145,6 @@ fi
|
||||
TEMP_PMBR="${TEMP_DIR}"/pmbr
|
||||
dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1
|
||||
|
||||
# Setup the bootloader configs to be correct for the image type
|
||||
TEMP_ESP_MNT=$(mktemp -d)
|
||||
cleanup() {
|
||||
safe_umount "${TEMP_ESP_MNT}"
|
||||
rmdir "${TEMP_ESP_MNT}"
|
||||
}
|
||||
trap cleanup INT TERM EXIT
|
||||
mkdir -p "${TEMP_ESP_MNT}"
|
||||
enable_rw_mount "${TEMP_ESP}"
|
||||
sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}"
|
||||
|
||||
SYSLINUX_DIR=${TEMP_ESP_MNT}/syslinux
|
||||
BOOT_DIR=${TEMP_ESP_MNT}/boot
|
||||
GRUB_DIR=${BOOT_DIR}/grub
|
||||
|
||||
# Assume that if we are booting syslinux we are fully virtualized
|
||||
sudo sed -i -e "s%HDROOTA%/dev/sda${NUM_ROOTFS_A}%g" ${SYSLINUX_DIR}/root.A.cfg
|
||||
sudo sed -i -e "s%HDROOTB%/dev/sda${NUM_ROOTFS_B}%g" ${SYSLINUX_DIR}/root.B.cfg
|
||||
|
||||
# Update the menu.lst to be right for xen pygrub/pv-grub or just guess for
|
||||
# everything else.
|
||||
if [ "${FLAGS_format}" = "xen" ]; then
|
||||
sudo sed -i -e "s%HDROOTA%/dev/xvda${NUM_ROOTFS_A}%g" ${GRUB_DIR}/menu.lst
|
||||
sudo sed -i -e "s%HDROOTB%/dev/xvda${NUM_ROOTFS_B}%g" ${GRUB_DIR}/menu.lst
|
||||
else
|
||||
sudo sed -i -e "s%HDROOTA%/dev/sda${NUM_ROOTFS_A}%g" ${GRUB_DIR}/menu.lst
|
||||
sudo sed -i -e "s%HDROOTB%/dev/sda${NUM_ROOTFS_B}%g" ${GRUB_DIR}/menu.lst
|
||||
fi
|
||||
|
||||
cat ${GRUB_DIR}/menu.lst ${SYSLINUX_DIR}/root.A.cfg
|
||||
|
||||
# Unmount everything prior to building a final image
|
||||
trap - INT TERM EXIT
|
||||
cleanup
|
||||
|
||||
# Set up a new partition table
|
||||
PARTITION_SCRIPT_PATH=$( tempfile )
|
||||
write_partition_script "${FLAGS_disk_layout}" "${PARTITION_SCRIPT_PATH}"
|
||||
|
Loading…
Reference in New Issue
Block a user