• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2011 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6usage() {
7  cat <<EOF
8Usage: $PROG <image> [--force]
9
10In-place converts recovery <image> into an SSD image. With --force, does not
11ask for confirmation from the user.
12
13EOF
14  exit 1
15}
16
17if [ $# -lt 1 ] || [ $# -gt 3 ]; then
18  usage
19else
20  IMAGE=$1
21  shift
22fi
23
24for arg in "$@"; do
25  case "$arg" in
26  --force)
27    IS_FORCE=${arg}
28    ;;
29  *)
30    usage
31    ;;
32  esac
33done
34
35# Load common constants (and use GPT if set above) and variables.
36. "$(dirname "$0")/common.sh"
37
38# Abort on errors.
39set -e
40
41if [ "${IS_FORCE}" != "--force" ]; then
42  echo "This will modify ${IMAGE} in-place and convert it into an SSD image."
43  read -p "Are you sure you want to continue (y/N)? " SURE
44  SURE="${SURE:0:1}"
45  [ "${SURE}" != "y" ] && exit 1
46fi
47
48loopdev=$(loopback_partscan "${IMAGE}")
49loop_kerna="${loopdev}p2"
50loop_kernb="${loopdev}p4"
51
52# Move Kernel B to Kernel A.
53info "Replacing Kernel partition A with Kernel partition B"
54sudo cp "${loop_kernb}" "${loop_kerna}"
55
56# Overwrite the vblock.
57info "Overwriting kernel partition A vblock with SSD vblock"
58stateful_dir=$(make_temp_dir)
59tmp_vblock=$(make_temp_file)
60sudo mount -o ro "${loopdev}p1" "${stateful_dir}"
61sudo cp "${stateful_dir}/vmlinuz_hd.vblock" "${tmp_vblock}"
62# Unmount before overwriting image to avoid sync issues.
63sudo umount "${stateful_dir}"
64sudo dd if="${tmp_vblock}" of="${loop_kerna}" bs=512 conv=notrunc
65
66# Zero out Kernel B partition.
67info "Zeroing out Kernel partition B"
68# This will throw a "disk is full" error, so ignore it.
69sudo cp /dev/zero "${loop_kernb}" 2>/dev/null || :
70
71info "${IMAGE} was converted to an SSD image."
72