| OLD | NEW |
| (Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # Script to convert a recovery image into an SSD image. Changes are made in- |
| 8 # place. |
| 9 |
| 10 # Load common constants and variables. |
| 11 . "$(dirname "$0")/common_minimal.sh" |
| 12 |
| 13 usage() { |
| 14 cat <<EOF |
| 15 Usage: $PROG <image> [--force] |
| 16 |
| 17 In-place converts recovery <image> into an SSD image. With --force, does not ask
for |
| 18 confirmation from the user. |
| 19 |
| 20 EOF |
| 21 } |
| 22 |
| 23 if [ $# -gt 2 ]; then |
| 24 usage |
| 25 exit 1 |
| 26 fi |
| 27 |
| 28 type -P cgpt &>/dev/null || |
| 29 { echo "cgpt tool must be in the path"; exit 1; } |
| 30 |
| 31 # Abort on errors. |
| 32 set -e |
| 33 |
| 34 IMAGE=$1 |
| 35 IS_FORCE=$2 |
| 36 |
| 37 if [ "${IS_FORCE}" != "--force" ]; then |
| 38 echo "This will modify ${IMAGE} in-place and convert it into an SSD image." |
| 39 read -p "Are you sure you want to continue (y/N)?" SURE |
| 40 SURE="${SURE:0:1}" |
| 41 [ "${SURE}" != "y" ] && exit 1 |
| 42 fi |
| 43 |
| 44 kerna_offset=$(partoffset ${IMAGE} 2) |
| 45 kernb_offset=$(partoffset ${IMAGE} 4) |
| 46 # Kernel partition sizes should be the same. |
| 47 kern_size=$(partsize ${IMAGE} 2) |
| 48 |
| 49 # Move Kernel B to Kernel A. |
| 50 kernb=$(make_temp_file) |
| 51 echo "Replacing Kernel partition A with Kernel partition B" |
| 52 extract_image_partition ${IMAGE} 4 ${kernb} |
| 53 replace_image_partition ${IMAGE} 2 ${kernb} |
| 54 |
| 55 # Overwrite the vblock. |
| 56 stateful_dir=$(make_temp_dir) |
| 57 tmp_vblock=$(make_temp_file) |
| 58 mount_image_partition_ro ${IMAGE} 1 ${stateful_dir} |
| 59 sudo cp ${stateful_dir}/vmlinuz_hd.vblock ${tmp_vblock} |
| 60 # Unmount before overwriting image to avoid sync issues. |
| 61 sudo umount -d ${stateful_dir} |
| 62 echo "Overwriting kernel partition A vblock with SSD vblock" |
| 63 sudo dd if=${tmp_vblock} of=${IMAGE} seek=${kerna_offset} bs=512 conv=notrunc |
| 64 |
| 65 # Zero out Kernel B partition. |
| 66 echo "Zeroing out Kernel partition B" |
| 67 sudo dd if=/dev/zero of=${IMAGE} seek=${kernb_offset} bs=512 count=${kern_size}
conv=notrunc |
| 68 echo "${IMAGE} was converted to an SSD image." |
| OLD | NEW |