flatcar-scripts/bin/cros_update_image.sh
Kees Cook 224817fda9 Relocate stateful_parition/var to stateful_partition/var_overlay
To avoid needing to migrate fresh dev images's /var contents when
using the encrypted partition, move the /var bits out of the old
stateful_partition/var location into stateful_partition/var_overlay.

The (initially empty) system /var will continue to either live
in stateful_partition/var (in the unencrypted case), or in
stateful_partition/encrypted/var (in the encrypted case).

The contents needed for gmerge will be symlinked into place at runtime
(via CL I6e68b1f334f5d5b3c4d2977008435bd929191ce7). While the installer
already makes sure that /var is not shipped on an image, this change
additionally make sure that the other contents installed by the ebuilds
will not show up in the actual /var either.

BUG=chromium-os:22172
TEST=link build, boot, install, manual testing.

Change-Id: Ie6480a59929818fe5d36a46abf533b648fb78850
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26355
Reviewed-by: Chris Sosa <sosa@chromium.org>
2012-07-09 09:06:30 -07:00

76 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2012 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.
# Usage:
# update_image.sh [image_to_update] [packages...]
usage()
{
cat <<EOF
usage:
update_image.sh [image_to_update] [packages...]
EOF
}
if [[ $# < 2 ]]; then
echo "Not enough arguments supplied."
usage
exit 1
fi
if [[ -f /home/${USER}/trunk/src/scripts/.default_board ]]; then
BOARD=$( cat /home/${USER}/trunk/src/scripts/.default_board )
else
BOARD=st1q
fi
IMAGE=$( readlink -f ${1} )
IMAGE_DIR=$( dirname "${IMAGE}" )
shift
PKGS=$@
if [[ -z "${IMAGE}" || ! -f ${IMAGE} ]]; then
echo "Missing required argument 'image_to_update'"
usage
exit 1
fi
cd ${IMAGE_DIR}
if ! [[ -x ./unpack_partitions.sh && -x ./pack_partitions.sh ]]; then
echo "Could not find image manipulation scripts."
exit 1
fi
./unpack_partitions.sh ${IMAGE}
mkdir -p ./rootfs
mkdir -p ./stateful_part
mkdir -p ./orig_partitions
rm -rf ./orig_partitions/*
cp ./part_* ./orig_partitions
sudo mount -o loop part_3 rootfs
sudo mount -o loop part_1 stateful_part
sudo mount --bind stateful_part/dev_image rootfs/usr/local
sudo mount --bind stateful_part/var_overlay rootfs/var
emerge-${BOARD} --root="./rootfs" \
--root-deps=rdeps --nodeps --usepkgonly ${PKGS}
#if the kernel is one of the packages that got updated
#we need to update the kernel partition as well.
if [[ ${PKGS/kernel/} != ${PKGS} ]]; then
rm -rf part_2
sudo dd if="/dev/zero" of=part_2 bs=512 count=8192
sudo dd if="./rootfs/boot/vmlinuz" of=part_2 bs=512 count=8192 conv=notrunc
fi
sudo umount rootfs/usr/local
sudo umount rootfs/var
sudo umount rootfs
sudo umount stateful_part
./pack_partitions.sh ${IMAGE}
cd -