OLD | NEW |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This script can be called to switch from kernel slot A / sda3 | 6 # This script can be called to switch from kernel slot A / sda3 |
7 # to kernel slot B / sda5 and vice versa. | 7 # to kernel slot B / sda5 and vice versa. |
8 | 8 |
9 ROOT_DEV=$(rootdev -s) | 9 ROOT_DEV=$(rootdev -s) |
10 OTHER_ROOT_DEV=$(echo $ROOT_DEV | tr '35' '53') | 10 OTHER_ROOT_DEV=$(echo $ROOT_DEV | tr '35' '53') |
11 | 11 |
12 if [ "${ROOT_DEV}" = "${OTHER_ROOT_DEV}" ] | 12 if [ "${ROOT_DEV}" = "${OTHER_ROOT_DEV}" ] |
13 then | 13 then |
14 echo "Not a normal rootfs partition (3 or 5): ${ROOT_DEV}" | 14 echo "Not a normal rootfs partition (3 or 5): ${ROOT_DEV}" |
15 exit 1 | 15 exit 1 |
16 fi | 16 fi |
17 | 17 |
18 DEV=${ROOT_DEV%[0-9]} | |
19 # Note: this works only for single digit partition numbers. | |
20 ROOT_PART=$(echo "${ROOT_DEV}" | sed -e 's/^.*\([0-9]\)$/\1/') | |
hungte
2010/09/13 02:37:32
sed -e 's/.*[^0-9]//' would be simpler.
| |
21 | |
18 # Successfully being able to mount the other partition | 22 # Successfully being able to mount the other partition |
19 # and run postinst guarantees that there is a real partition there. | 23 # and run postinst guarantees that there is a real partition there. |
20 echo "Running postinst on $OTHER_ROOT_DEV" | 24 echo "Running postinst on $OTHER_ROOT_DEV" |
21 MOUNTPOINT=$(mktemp -d) | 25 MOUNTPOINT=$(mktemp -d) |
22 mkdir -p "$MOUNTPOINT" | 26 mkdir -p "$MOUNTPOINT" |
23 mount -o ro "$OTHER_ROOT_DEV" "$MOUNTPOINT" | 27 mount -o ro "$OTHER_ROOT_DEV" "$MOUNTPOINT" |
24 "$MOUNTPOINT"/postinst --noupdate_firmware "$OTHER_ROOT_DEV" | 28 "$MOUNTPOINT"/postinst --noupdate_firmware "$OTHER_ROOT_DEV" |
25 POSTINST_RETURN_CODE=$? | 29 POSTINST_RETURN_CODE=$? |
26 umount "$MOUNTPOINT" | 30 umount "$MOUNTPOINT" |
27 rmdir "$MOUNTPOINT" | 31 rmdir "$MOUNTPOINT" |
28 | 32 |
33 # Destroy this root partition if we've successfully switched. | |
34 if [ "${POSTINST_RETURN_CODE}" = "0" ]; then | |
35 cgpt add -i "$((${ROOT_PART} - 1))" -P 0 -S 0 -T 0 "${DEV}" | |
36 RC=$? | |
37 if [ "${RC}" != "0" ]; then | |
38 echo "Failed to run cgpt" | |
39 return 1 | |
40 fi | |
41 fi | |
42 | |
29 exit $POSTINST_RETURN_CODE | 43 exit $POSTINST_RETURN_CODE |
OLD | NEW |