mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 14:41:31 +02:00
recovery installer: fix build_gpt and build_image
Change-Id: I3cbb62827a33894f47d26dd047134b6c39c6667b Review URL: http://codereview.chromium.org/2813029
This commit is contained in:
parent
b59dd19d2d
commit
40551cd9ca
22
build_gpt.sh
22
build_gpt.sh
@ -23,8 +23,6 @@ DEFINE_string board "$DEFAULT_BOARD" \
|
|||||||
"The board to build an image for."
|
"The board to build an image for."
|
||||||
DEFINE_string arm_extra_bootargs "" \
|
DEFINE_string arm_extra_bootargs "" \
|
||||||
"Additional command line options to pass to the ARM kernel."
|
"Additional command line options to pass to the ARM kernel."
|
||||||
DEFINE_boolean recovery $FLAGS_FALSE \
|
|
||||||
"Build GPT for a recovery image. Default: False."
|
|
||||||
DEFINE_integer rootfs_partition_size 1024 \
|
DEFINE_integer rootfs_partition_size 1024 \
|
||||||
"rootfs parition size in MBs."
|
"rootfs parition size in MBs."
|
||||||
|
|
||||||
@ -81,7 +79,6 @@ set -e
|
|||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Check for missing parts.
|
# Check for missing parts.
|
||||||
# For recovery image, only populate ROOT-A and KERN-A
|
|
||||||
ROOTFS_IMG="${IMAGEDIR}/rootfs.image"
|
ROOTFS_IMG="${IMAGEDIR}/rootfs.image"
|
||||||
if [[ ! -s ${ROOTFS_IMG} ]]; then
|
if [[ ! -s ${ROOTFS_IMG} ]]; then
|
||||||
error "Can't find ${ROOTFS_IMG}"
|
error "Can't find ${ROOTFS_IMG}"
|
||||||
@ -95,13 +92,13 @@ if [[ ! -s ${KERNEL_IMG} ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image"
|
STATEFUL_IMG="${IMAGEDIR}/stateful_partition.image"
|
||||||
if [ ! -s ${STATEFUL_IMG} ] && [ ${FLAGS_recovery} -eq $FLAGS_FALSE ]; then
|
if [ ! -s ${STATEFUL_IMG} ]; then
|
||||||
error "Can't find ${STATEFUL_IMG}"
|
error "Can't find ${STATEFUL_IMG}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ESP_IMG="${IMAGEDIR}/esp.image"
|
ESP_IMG="${IMAGEDIR}/esp.image"
|
||||||
if [ ! -s ${ESP_IMG} ] && [ ${FLAGS_recovery} -eq $FLAGS_FALSE ]; then
|
if [ ! -s ${ESP_IMG} ]; then
|
||||||
error "Can't find ${ESP_IMG}"
|
error "Can't find ${ESP_IMG}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -117,7 +114,7 @@ fi
|
|||||||
# Create the GPT. This has the side-effect of setting some global vars
|
# Create the GPT. This has the side-effect of setting some global vars
|
||||||
# describing the partition table entries (see the comments in the source).
|
# describing the partition table entries (see the comments in the source).
|
||||||
install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG \
|
install_gpt $OUTDEV $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG \
|
||||||
false $FLAGS_recovery $FLAGS_rootfs_partition_size
|
false $FLAGS_rootfs_partition_size
|
||||||
|
|
||||||
if [[ "$ARCH" = "arm" ]]; then
|
if [[ "$ARCH" = "arm" ]]; then
|
||||||
# assume /dev/mmcblk1. we could not get this from ${OUTDEV}
|
# assume /dev/mmcblk1. we could not get this from ${OUTDEV}
|
||||||
@ -152,19 +149,6 @@ echo "Copying rootfs..."
|
|||||||
$sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \
|
$sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \
|
||||||
seek=${START_ROOTFS_A}
|
seek=${START_ROOTFS_A}
|
||||||
|
|
||||||
# TODO(tgao): write a script to populate ROOT-B and KERN-B with user-specified
|
|
||||||
# rootfs and kernel. Do NOT remove if block below until then (otherwise
|
|
||||||
# chromeos-installer will fail b/c it expects to install from partition B)
|
|
||||||
if [ ${FLAGS_recovery} -eq $FLAGS_TRUE ]; then
|
|
||||||
echo "Copying kernel B..."
|
|
||||||
$sudo dd if=${KERNEL_IMG} of=${OUTDEV} conv=notrunc bs=512 \
|
|
||||||
seek=${START_KERN_B}
|
|
||||||
|
|
||||||
echo "Copying rootfs B..."
|
|
||||||
$sudo dd if=${ROOTFS_IMG} of=${OUTDEV} conv=notrunc bs=512 \
|
|
||||||
seek=${START_ROOTFS_B}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Copying EFI system partition..."
|
echo "Copying EFI system partition..."
|
||||||
$sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP}
|
$sudo dd if=${ESP_IMG} of=${OUTDEV} conv=notrunc bs=512 seek=${START_ESP}
|
||||||
|
|
||||||
|
52
build_image
52
build_image
@ -44,8 +44,6 @@ DEFINE_boolean factory_install ${FLAGS_FALSE} \
|
|||||||
is also required in image_to_usb."
|
is also required in image_to_usb."
|
||||||
DEFINE_string arm_extra_bootargs "" \
|
DEFINE_string arm_extra_bootargs "" \
|
||||||
"Additional command line options to pass to the ARM kernel."
|
"Additional command line options to pass to the ARM kernel."
|
||||||
DEFINE_boolean recovery ${FLAGS_FALSE} \
|
|
||||||
"Build a recovery image. Default: False."
|
|
||||||
DEFINE_integer rootfs_partition_size 1024 \
|
DEFINE_integer rootfs_partition_size 1024 \
|
||||||
"rootfs parition size in MBs."
|
"rootfs parition size in MBs."
|
||||||
DEFINE_integer rootfs_size 720 \
|
DEFINE_integer rootfs_size 720 \
|
||||||
@ -96,11 +94,6 @@ if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
|
|||||||
DEVELOPER_IMAGE_NAME=chromiumos_image.bin
|
DEVELOPER_IMAGE_NAME=chromiumos_image.bin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If we are creating a recovery image, rename pristine image.
|
|
||||||
if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then
|
|
||||||
PRISTINE_IMAGE_NAME=recovery_image.bin
|
|
||||||
fi
|
|
||||||
|
|
||||||
OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}}
|
OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}}
|
||||||
|
|
||||||
BOARD="${FLAGS_board}"
|
BOARD="${FLAGS_board}"
|
||||||
@ -283,35 +276,6 @@ update_dev_packages() {
|
|||||||
${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR}"
|
${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Modifies an existing image to add recovery packages
|
|
||||||
update_recovery_packages() {
|
|
||||||
local image_name=$1
|
|
||||||
|
|
||||||
echo "Adding recovery packages to ${image_name}"
|
|
||||||
|
|
||||||
# Create stateful partition of the same size as the rootfs.
|
|
||||||
trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT
|
|
||||||
|
|
||||||
${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
|
|
||||||
--image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \
|
|
||||||
-s "${STATEFUL_FS_DIR}"
|
|
||||||
|
|
||||||
# Install recovery installer.
|
|
||||||
sudo ${EMERGE_BOARD_CMD} --root=${ROOT_FS_DIR} --usepkg \
|
|
||||||
--root-deps=rdeps --nodeps chromeos-recovery
|
|
||||||
|
|
||||||
# Re-run ldconfig to fix /etc/ldconfig.so.cache.
|
|
||||||
sudo /sbin/ldconfig -r "${ROOT_FS_DIR}"
|
|
||||||
|
|
||||||
# Mark the image as a developer image (input to chromeos_startup).
|
|
||||||
sudo mkdir -p "${ROOT_FS_DIR}/root"
|
|
||||||
sudo touch "${ROOT_FS_DIR}/root/.recovery_installer"
|
|
||||||
|
|
||||||
trap - EXIT
|
|
||||||
${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR}"
|
|
||||||
}
|
|
||||||
|
|
||||||
create_base_image() {
|
create_base_image() {
|
||||||
|
|
||||||
trap "cleanup && delete_prompt" EXIT
|
trap "cleanup && delete_prompt" EXIT
|
||||||
@ -499,18 +463,12 @@ EOF
|
|||||||
|
|
||||||
trap delete_prompt EXIT
|
trap delete_prompt EXIT
|
||||||
|
|
||||||
RECOVERY="--norecovery"
|
|
||||||
if [[ ${FLAGS_recovery} -eq ${FLAGS_TRUE} ]]; then
|
|
||||||
RECOVERY="--recovery"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create the GPT-formatted image.
|
# Create the GPT-formatted image.
|
||||||
${SCRIPTS_DIR}/build_gpt.sh \
|
${SCRIPTS_DIR}/build_gpt.sh \
|
||||||
--arch=${ARCH} \
|
--arch=${ARCH} \
|
||||||
--board=${FLAGS_board} \
|
--board=${FLAGS_board} \
|
||||||
--arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
|
--arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
|
||||||
--rootfs_partition_size=${FLAGS_rootfs_partition_size} \
|
--rootfs_partition_size=${FLAGS_rootfs_partition_size} \
|
||||||
${RECOVERY} \
|
|
||||||
"${OUTPUT_DIR}" \
|
"${OUTPUT_DIR}" \
|
||||||
"${OUTPUT_IMG}"
|
"${OUTPUT_IMG}"
|
||||||
}
|
}
|
||||||
@ -523,13 +481,6 @@ mkdir -p "${ESP_FS_DIR}"
|
|||||||
|
|
||||||
create_base_image ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}
|
create_base_image ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}
|
||||||
|
|
||||||
# Create a recovery image based on the chromium os base image.
|
|
||||||
if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ] ; then
|
|
||||||
update_recovery_packages ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}
|
|
||||||
fi
|
|
||||||
trap - EXIT
|
|
||||||
|
|
||||||
|
|
||||||
# Create a developer image based on the chromium os base image.
|
# Create a developer image based on the chromium os base image.
|
||||||
if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then
|
if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then
|
||||||
echo "Creating developer image from base image ${OUTPUT_IMG}"
|
echo "Creating developer image from base image ${OUTPUT_IMG}"
|
||||||
@ -554,9 +505,6 @@ rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}"
|
|||||||
|
|
||||||
echo "Done. Image created in ${OUTPUT_DIR}"
|
echo "Done. Image created in ${OUTPUT_DIR}"
|
||||||
echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
|
echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
|
||||||
if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then
|
|
||||||
echo "Recovery image created as ${PRISTINE_IMAGE_NAME}"
|
|
||||||
fi
|
|
||||||
if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
|
if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
|
||||||
echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
|
echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
|
||||||
fi
|
fi
|
||||||
|
90
mod_image_for_recovery.sh
Executable file
90
mod_image_for_recovery.sh
Executable file
@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
# Script to modify a pristine/dev Chrome OS image to be used for recovery
|
||||||
|
|
||||||
|
. "$(dirname "$0")/common.sh"
|
||||||
|
|
||||||
|
# Script must be run inside the chroot.
|
||||||
|
restart_in_chroot_if_needed $*
|
||||||
|
|
||||||
|
DEFINE_string image_dir "" \
|
||||||
|
"Directory to pristine/base image."
|
||||||
|
DEFINE_string image_name "chromiumos_image.bin" \
|
||||||
|
"Name of Chrome OS image to modify."
|
||||||
|
|
||||||
|
# Parse command line
|
||||||
|
FLAGS "$@" || exit 1
|
||||||
|
eval set -- "${FLAGS_ARGV}"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z $FLAGS_image_dir ] || [ ! -d $FLAGS_image_dir ]; then
|
||||||
|
echo "Error: invalid flag --image_dir"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SRC_PATH="${FLAGS_image_dir}/${FLAGS_image_name}"
|
||||||
|
if [ -z $FLAGS_image_name ] || [ ! -f $SRC_PATH ]; then
|
||||||
|
echo "Error: invalid flag --image_name"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
OUTPUT_DIR=$FLAGS_image_dir
|
||||||
|
ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
|
||||||
|
STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition"
|
||||||
|
RECOVERY_IMAGE="recovery_image.bin"
|
||||||
|
|
||||||
|
mount_gpt_cleanup() {
|
||||||
|
"${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Modifies an existing image for recovery use
|
||||||
|
update_recovery_packages() {
|
||||||
|
local image_name=$1
|
||||||
|
local sector_size=512 # sector size in bytes
|
||||||
|
local num_sectors_vb=128 # number of sectors in kernel verification blob
|
||||||
|
# Start offset of kernel A (aligned to 4096-sector boundary)
|
||||||
|
local start_kern_a=4096
|
||||||
|
local vb_file="${STATEFUL_FS_DIR}/verification_blob.kernel"
|
||||||
|
|
||||||
|
echo "Modifying image ${image_name} for recovery use"
|
||||||
|
|
||||||
|
trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT
|
||||||
|
|
||||||
|
${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
|
||||||
|
--image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \
|
||||||
|
-s "${STATEFUL_FS_DIR}"
|
||||||
|
|
||||||
|
# Mark the image as a recovery image (needed for recovery boot)
|
||||||
|
sudo touch "${STATEFUL_FS_DIR}/.recovery"
|
||||||
|
|
||||||
|
# Copy verification blob out of kernel A into stateful partition
|
||||||
|
# so that we can restore it during recovery
|
||||||
|
sudo touch $vb_file
|
||||||
|
echo "Backing up kernel verification blob onto stateful partition ..."
|
||||||
|
sudo dd if="$image_name" of="$vb_file" skip=$start_kern_a bs=$sector_size \
|
||||||
|
count=$num_sectors_vb conv=notrunc
|
||||||
|
|
||||||
|
# Overwrite verification blob with recovery image verification blob
|
||||||
|
# TODO(tgao): resign kernel for recovery image
|
||||||
|
echo "Overwrite kernel verification blob with resigned blob for recovery..."
|
||||||
|
sudo dd if=/dev/zero of="$image_name" seek=$start_kern_a bs=$sector_size \
|
||||||
|
count=$num_sectors_vb conv=notrunc
|
||||||
|
|
||||||
|
trap - EXIT
|
||||||
|
${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
|
||||||
|
-s "${STATEFUL_FS_DIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
|
||||||
|
DST_PATH="${OUTPUT_DIR}/${RECOVERY_IMAGE}"
|
||||||
|
echo "Making a copy of original image ${SRC_PATH}"
|
||||||
|
cp $SRC_PATH $DST_PATH
|
||||||
|
update_recovery_packages $DST_PATH
|
||||||
|
echo "Recovery image created at ${DST_PATH}"
|
Loading…
x
Reference in New Issue
Block a user