mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 21:46:58 +02:00
Clean up cros_make_image_bootable and image_to_vm
image_to_vm.sh was running chromeos-setimage. This script was not meant to be run outside of a CrOS environment, but its use here predates the cros_make_image_bootable script. The change converts the rehashing and imaging over to using cros_make_image_bootable. The vm image uses the usb boot target but defaults the usb drive to sda3. update_bootloaders is fixed to not clobber existing syslinux templates. cros_make_image_bootable flag override support was broken and this fixes it. TEST=build a new image wtih rootfs checking and without and ensure both woth with image_to_vm. Also make sure they still boot normally on available hardware. BUG=chromium-os:5939 Review URL: http://codereview.chromium.org/3189018 Change-Id: Ib4ac25f1a76f25ac7ce4538614ba247df9caea91
This commit is contained in:
parent
bfafc9cfd2
commit
537caa90c0
@ -19,12 +19,20 @@ fi
|
|||||||
set -e
|
set -e
|
||||||
. "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize
|
. "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize
|
||||||
|
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
BOOT_DESC_FILE="${1}/boot.desc"
|
BOOT_DESC_FILE="${1}/boot.desc"
|
||||||
IMAGE="${1}/${2}"
|
IMAGE="${1}/${2}"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
FLAG_OVERRIDES="${@}"
|
||||||
|
|
||||||
if [ ! -r "${BOOT_DESC_FILE}" ]; then
|
if [ ! -r "${BOOT_DESC_FILE}" ]; then
|
||||||
warning "${BOOT_DESC_FILE} cannot be read!"
|
warn "${BOOT_DESC_FILE} cannot be read!"
|
||||||
warning "Falling back to command line parsing"
|
warn "Falling back to command line parsing"
|
||||||
BOOT_DESC="${@}"
|
BOOT_DESC="${@}"
|
||||||
else
|
else
|
||||||
BOOT_DESC="$(cat ${BOOT_DESC_FILE} | tr -s '\n' ' ')"
|
BOOT_DESC="$(cat ${BOOT_DESC_FILE} | tr -s '\n' ' ')"
|
||||||
@ -92,12 +100,8 @@ DEFINE_string espfs_mountpoint "/tmp/espfs" \
|
|||||||
DEFINE_boolean use_dev_keys ${FLAGS_FALSE} \
|
DEFINE_boolean use_dev_keys ${FLAGS_FALSE} \
|
||||||
"Use developer keys for signing. (Default: false)"
|
"Use developer keys for signing. (Default: false)"
|
||||||
|
|
||||||
# Parse command-line flags present after positional args, if any. This needs
|
# Parse the boot.desc and any overrides
|
||||||
# to happen before we parse boot.desc (otherwise the flags would be lost)
|
eval set -- "${BOOT_DESC} ${FLAG_OVERRIDES}"
|
||||||
FLAGS "${@}" || exit 1
|
|
||||||
|
|
||||||
# Parse the boot.desc
|
|
||||||
eval set -- "${BOOT_DESC}"
|
|
||||||
FLAGS "${@}" || exit 1
|
FLAGS "${@}" || exit 1
|
||||||
|
|
||||||
# Only now can we die on error. shflags functions leak non-zero error codes,
|
# Only now can we die on error. shflags functions leak non-zero error codes,
|
||||||
|
@ -115,8 +115,7 @@ fi
|
|||||||
|
|
||||||
# Memory units are in MBs
|
# Memory units are in MBs
|
||||||
DEFAULT_MEM="1024"
|
DEFAULT_MEM="1024"
|
||||||
TEMP_IMAGE="${IMAGES_DIR}/temp_image.img"
|
TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin"
|
||||||
|
|
||||||
|
|
||||||
# If we're not building for VMWare, don't build the vmx
|
# If we're not building for VMWare, don't build the vmx
|
||||||
if [ "${FLAGS_format}" != "vmware" ]; then
|
if [ "${FLAGS_format}" != "vmware" ]; then
|
||||||
@ -189,43 +188,18 @@ else
|
|||||||
sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \
|
sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \
|
||||||
--enable_tablet=false
|
--enable_tablet=false
|
||||||
fi
|
fi
|
||||||
# Remount read-only so that when we call setimage, it will recreate correct
|
|
||||||
# boot hashes for verifying the rootfs integrity. This is a bit of a cheat
|
# Modify the unverified usb template which uses a default usb_disk of sdb3
|
||||||
# but it will have to do. We don't assume legacy bootloaders are secure so
|
sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg"
|
||||||
# we update the hash too, but the hash in part_2 doesn't change which would
|
|
||||||
# cause failures on a Chrome OS boot (without re-running build_kernel_image).
|
# Unmount everything prior to building a final image
|
||||||
sudo mount -o remount,ro "${TEMP_MNT}"
|
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# Check if the current image was build with --enable_rootfs_verification
|
|
||||||
enable_rootfs_verification=
|
|
||||||
if grep -qE '^chromeos-v' "${TEMP_ESP_MNT}"/syslinux/default.cfg; then
|
|
||||||
enable_rootfs_verification=--enable_rootfs_verification
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update the bootloader and verified hashes for the given rootfs in the
|
|
||||||
# vm and fixup changes.
|
|
||||||
DST_DEV=/dev/sda
|
|
||||||
BOOT_SLOT=A
|
|
||||||
syslinux_cfg="${TEMP_MNT}/boot/syslinux/root.${BOOT_SLOT}.cfg"
|
|
||||||
grub_cfg="${TEMP_MNT}/boot/efi/boot/grub.cfg"
|
|
||||||
sudo "${TEMP_MNT}"/usr/sbin/chromeos-setimage ${BOOT_SLOT} \
|
|
||||||
--dst=${DST_DEV} --run_as_root \
|
|
||||||
--update_syslinux_cfg="${syslinux_cfg}" \
|
|
||||||
--update_grub_cfg="${grub_cfg}" \
|
|
||||||
--rootfs_image="${TEMP_ROOTFS}" \
|
|
||||||
--esp_mounted_at="${TEMP_ESP_MNT}" \
|
|
||||||
--kernel_image="${TEMP_KERN}" \
|
|
||||||
--update_vmlinuz=${TEMP_MNT}/boot/vmlinuz \
|
|
||||||
${enable_rootfs_verification}
|
|
||||||
|
|
||||||
trap - INT TERM EXIT
|
trap - INT TERM EXIT
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
# Make 3 GiB output image
|
# Make 3 GiB output image
|
||||||
TEMP_IMG=$(mktemp)
|
|
||||||
# TOOD(adlr): pick a size that will for sure accomodate the partitions
|
# TOOD(adlr): pick a size that will for sure accomodate the partitions
|
||||||
sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \
|
dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \
|
||||||
seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1))
|
seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1))
|
||||||
|
|
||||||
# Set up the partition table
|
# Set up the partition table
|
||||||
@ -242,6 +216,14 @@ dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \
|
|||||||
dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \
|
dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \
|
||||||
seek="${START_ESP}"
|
seek="${START_ESP}"
|
||||||
|
|
||||||
|
# Make the built-image bootable and ensure that the legacy default usb boot
|
||||||
|
# uses /dev/sda instead of /dev/sdb3.
|
||||||
|
# NOTE: The TEMP_IMG must live in the same image dir as the original image
|
||||||
|
# to operate automatically below.
|
||||||
|
${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${TEMP_IMG}") \
|
||||||
|
$(basename "${TEMP_IMG}") \
|
||||||
|
--usb_disk /dev/sda3
|
||||||
|
|
||||||
echo Creating final image
|
echo Creating final image
|
||||||
# Convert image to output format
|
# Convert image to output format
|
||||||
if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" ]; then
|
if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user