diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index b909e1204e..742116e4ac 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -204,6 +204,7 @@ finish_image() { local disk_layout="$2" local root_fs_dir="$3" local image_contents="$4" + local install_grub=0 local disk_img="${BUILD_DIR}/${image_name}" @@ -220,10 +221,10 @@ finish_image() { # Only configure bootloaders if there is a boot partition if mountpoint -q "${root_fs_dir}"/boot; then + install_grub=1 ${BUILD_LIBRARY_DIR}/configure_bootloaders.sh \ --arch=${ARCH} \ --disk_layout="${disk_layout}" \ - --disk_image="${disk_img}" \ --boot_dir="${root_fs_dir}"/usr/boot \ --esp_dir="${root_fs_dir}"/boot \ --boot_args="${FLAGS_boot_args}" @@ -249,4 +250,13 @@ finish_image() { rm -rf "${BUILD_DIR}"/configroot cleanup_mounts "${root_fs_dir}" trap - EXIT + + # 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 + ${BUILD_LIBRARY_DIR}/grub_install.sh \ + --target="${target}" --disk_image="${disk_img}" + done + fi } diff --git a/build_library/configure_bootloaders.sh b/build_library/configure_bootloaders.sh index 7458838646..09470c6f53 100755 --- a/build_library/configure_bootloaders.sh +++ b/build_library/configure_bootloaders.sh @@ -24,7 +24,6 @@ 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." -DEFINE_string disk_image "" "The disk image." # Parse flags FLAGS "$@" || exit 1 @@ -52,6 +51,7 @@ SYSLINUX_DIR="${FLAGS_boot_dir}/syslinux" # Build configuration files for pygrub/pvgrub configure_pvgrub() { + info "Installing legacy PV-GRUB configuration" sudo mkdir -p "${GRUB_DIR}" # Add hvc0 for hypervisors @@ -68,18 +68,21 @@ title CoreOS B Root root (hd0,0) kernel /syslinux/vmlinuz.B ${grub_args} ${slot_b_args} EOF - info "Emitted ${GRUB_DIR}/menu.lst.A" sudo_clobber "${GRUB_DIR}/menu.lst.B" < "${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##*/}" +LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}") +ESP_DIR=$(mktemp --directory) +sudo mount -t vfat "${LOOP_DEV}p1" "${ESP_DIR}" +sudo cp -r "${STAGE_DIR}/." "${ESP_DIR}/." + +# This script will get called a few times, no need to re-copy grub.cfg +if [[ ! -f "${ESP_DIR}/coreos/grub/grub.cfg" ]]; then + info "Installing grub.cfg" + sudo cp "${BUILD_LIBRARY_DIR}/grub.cfg" "${ESP_DIR}/coreos/grub/grub.cfg" +fi + +# Now target specific steps to make the system bootable +case "${FLAGS_target}" in + i386-pc) + info "Installing MBR and the BIOS Boot partition." + sudo cp "/usr/lib/grub/i386-pc/boot.img" "${ESP_DIR}/${GRUB_DIR}" + sudo grub-bios-setup --device-map=/dev/null \ + --directory="${ESP_DIR}/${GRUB_DIR}" "${LOOP_DEV}" + ;; + x86_64-efi) + info "Installing default x86_64 UEFI bootloader." + sudo mkdir -p "${ESP_DIR}/EFI/boot" + sudo cp "${STAGE_DIR}/${GRUB_DIR}/${CORE_NAME}" \ + "${ESP_DIR}/EFI/boot/bootx64.efi" + ;; +esac + +cleanup +trap - EXIT +command_completed diff --git a/build_library/qemu_template.sh b/build_library/qemu_template.sh index a4c107e366..30de34c9be 100755 --- a/build_library/qemu_template.sh +++ b/build_library/qemu_template.sh @@ -20,7 +20,7 @@ Options: -c FILE Config drive as an iso or fat filesystem image. -a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub] -p PORT The port on localhost to map to the VM's sshd. [2222] - -s Safe settings: single simple cpu, ide disks. + -s Safe settings: single simple cpu and no KVM. -h this ;-) This script is a wrapper around qemu for starting CoreOS virtual machines. @@ -131,11 +131,11 @@ fi # Start assembling our default command line arguments if [ "${SAFE_ARGS}" -eq 1 ]; then - disk_type="ide" + # Disable KVM, for testing things like UEFI which don't like it + set -- -machine accel=tcg "$@" else - disk_type="virtio" # Emulate the host CPU closely in both features and cores. - set -- -cpu host -smp "${VM_NCPUS}" "$@" + set -- -machine accel=kvm -cpu host -smp "${VM_NCPUS}" "$@" fi # ${CONFIG_DRIVE} or ${CONFIG_IMAGE} will be mounted in CoreOS as /media/configdrive @@ -146,11 +146,11 @@ if [ -n "${CONFIG_DRIVE}" ]; then fi if [ -n "${CONFIG_IMAGE}" ]; then - set -- -drive if=${disk_type},file="${CONFIG_IMAGE}" "$@" + set -- -drive if=virtio,file="${CONFIG_IMAGE}" "$@" fi if [ -n "${VM_IMAGE}" ]; then - set -- -drive if=${disk_type},file="${SCRIPT_DIR}/${VM_IMAGE}" "$@" + set -- -drive if=virtio,file="${SCRIPT_DIR}/${VM_IMAGE}" "$@" fi if [ -n "${VM_KERNEL}" ]; then @@ -173,7 +173,6 @@ fi qemu-system-x86_64 \ -name "$VM_NAME" \ -m ${VM_MEMORY} \ - -machine accel=kvm:tcg \ -net nic,vlan=0,model=virtio \ -net user,vlan=0,hostfwd=tcp::"${SSH_PORT}"-:22,hostname="${VM_NAME}" \ "$@"