diff --git a/build_image b/build_image index a64261d11a..d6e2cba551 100755 --- a/build_image +++ b/build_image @@ -22,8 +22,6 @@ DEFAULT_GROUP=developer # Developer-visible flags. DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build an image for." -DEFINE_string boot_args "" \ - "Additional boot arguments to pass to the commandline" DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ "Default all bootloaders to use kernel-based root fs integrity checking." DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index e8e1b760e6..e08414bac3 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -242,11 +242,7 @@ finish_image() { if mountpoint -q "${root_fs_dir}"/boot; then install_grub=1 ${BUILD_LIBRARY_DIR}/configure_bootloaders.sh \ - --arch=${ARCH} \ - --disk_layout="${disk_layout}" \ - --boot_dir="${root_fs_dir}"/usr/boot \ - --esp_dir="${root_fs_dir}"/boot \ - --boot_args="${FLAGS_boot_args}" + --boot_dir="${root_fs_dir}"/usr/boot fi if [[ -n "${FLAGS_developer_data}" ]]; then @@ -273,7 +269,7 @@ finish_image() { # This script must mount the ESP partition differently, so run it after unmount if [[ "${install_grub}" -eq 1 ]]; then local target - for target in i386-pc x86_64-efi; do + for target in i386-pc x86_64-efi x86_64-xen; do ${BUILD_LIBRARY_DIR}/grub_install.sh \ --target="${target}" --disk_image="${disk_img}" done diff --git a/build_library/configure_bootloaders.sh b/build_library/configure_bootloaders.sh index 09470c6f53..27b862cbec 100755 --- a/build_library/configure_bootloaders.sh +++ b/build_library/configure_bootloaders.sh @@ -4,8 +4,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Helper script to generate GRUB bootloader configuration files for -# x86 platforms. +# Helper script to generate bootloader configuration files for systems +# that predate our new GRUB2 based gptprio bootloader. SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) . "${SCRIPT_ROOT}/common.sh" || exit 1 @@ -14,16 +14,8 @@ SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) assert_inside_chroot # Flags. -DEFINE_string arch "x86" \ - "The boot architecture: arm or x86. (Default: x86)" DEFINE_string boot_dir "/tmp/boot" \ "Path to boot directory in root filesystem (Default: /tmp/boot)" -DEFINE_string esp_dir "" \ - "Path to ESP partition mount point (Default: none)" -DEFINE_string boot_args "" \ - "Additional boot arguments to pass to the commandline (Default: '')" -DEFINE_string disk_layout "base" \ - "The disk layout type to use for this image." # Parse flags FLAGS "$@" || exit 1 @@ -34,17 +26,10 @@ switch_to_strict_mode common_args="console=tty0 ro noswap cros_legacy" common_args="${common_args} ${FLAGS_boot_args}" -# Get partition UUIDs from the json config -get_uuid() { - "${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${FLAGS_disk_layout}" \ - readuuid "$1" -} - # Filesystem command line args. root_args="root=LABEL=ROOT rootflags=subvol=root" -gptprio_args="${root_args} usr=gptprio:" -slot_a_args="${root_args} usr=PARTUUID=$(get_uuid USR-A)" -slot_b_args="${root_args} usr=PARTUUID=$(get_uuid USR-B)" +slot_a_args="${root_args} usr=PARTLABEL=USR-A" +slot_b_args="${root_args} usr=PARTLABEL=USR-B" GRUB_DIR="${FLAGS_boot_dir}/grub" SYSLINUX_DIR="${FLAGS_boot_dir}/syslinux" @@ -73,11 +58,6 @@ EOF default 1 $(< "${GRUB_DIR}/menu.lst.A") EOF - sudo cp "${GRUB_DIR}/menu.lst.A" "${GRUB_DIR}/menu.lst" - - # menu.lst needs to go under boot/grub so pvgrub can find it reliably - sudo mkdir -p "${FLAGS_esp_dir}/boot/grub" - sudo cp "${GRUB_DIR}/menu.lst" "${FLAGS_esp_dir}/boot/grub" } # Build configuration files for syslinux @@ -87,45 +67,11 @@ configure_syslinux() { # Add ttyS0 as a secondary console, useful for qemu -nographic # This leaves /dev/console mapped to tty0 (vga) which is reasonable default. - if [[ ${common_args} == *console=ttyS* ]] ; then - syslinux_args="${common_args}" - else - syslinux_args="console=ttyS0,115200n8 ${common_args}" - fi + syslinux_args="console=ttyS0,115200n8 ${common_args}" - sudo_clobber "${SYSLINUX_DIR}/syslinux.cfg" < "${out}" -done - -info "Generating ${GRUB_DIR}/${CORE_NAME}" -grub-mkimage \ - --compression=auto \ - --format "${FLAGS_target}" \ - --prefix "${GRUB_PREFIX}" \ - --output "${STAGE_DIR}/${GRUB_DIR}/${CORE_NAME}" \ - "${CORE_MODULES[@]}" - -info "Installing GRUB ${FLAGS_target} to ${FLAGS_disk_image##*/}" +info "Installing GRUB ${FLAGS_target} in ${FLAGS_disk_image##*/}" LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}") ESP_DIR=$(mktemp --directory) @@ -117,7 +96,33 @@ if [[ ! -b "${LOOP_DEV}p1" ]]; then fi sudo mount -t vfat "${LOOP_DEV}p1" "${ESP_DIR}" -sudo cp -r "${STAGE_DIR}/." "${ESP_DIR}/." +sudo mkdir -p "${ESP_DIR}/${GRUB_DIR}" + +info "Compressing modules in ${GRUB_DIR}" +for file in "/usr/lib/grub/${FLAGS_target}"/*{.lst,.mod}; do + out="${ESP_DIR}/${GRUB_DIR}/${file##*/}" + gzip --best --stdout "${file}" | sudo_clobber "${out}" +done + +info "Generating ${GRUB_DIR}/load.cfg" +# Include a small initial config in the core image to search for the ESP +# by filesystem ID in case the platform doesn't provide the boot disk. +# The existing $root value is given as a hint so it is searched first. +ESP_FSID=$(sudo grub-probe -t fs_uuid -d "${LOOP_DEV}p1") +sudo_clobber "${ESP_DIR}/${GRUB_DIR}/load.cfg" <