OLD | NEW |
1 #!/bin/sh -e | 1 #!/bin/sh -e |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This script is called after an AutoUpdate or USB install. The first argument | 7 # This script is called after an AutoUpdate or USB install. The first argument |
8 # is the partition where the new rootfs is installed or empty. If non-empty | 8 # is the partition where the new rootfs is installed or empty. If non-empty |
9 # the rootfs should be updated w/ the new bootloader config. If empty, the | 9 # the rootfs should be updated w/ the new bootloader config. If empty, the |
10 # rootfs is mounted-read only and should not be updated. | 10 # rootfs is mounted-read only and should not be updated. |
11 | 11 |
12 # Update /boot/extlinux.conf. | 12 # Update /boot/extlinux.conf. |
13 INSTALL_ROOT=`dirname "$0"` | 13 INSTALL_ROOT=`dirname "$0"` |
14 INSTALL_DEV="$1" | 14 INSTALL_DEV="$1" |
15 POSTCOMMIT="$2" | 15 POSTCOMMIT="$2" |
| 16 # Find whole disk device. |
| 17 ROOT_DEV=${INSTALL_DEV%%[0-9]*} |
| 18 NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]} |
| 19 |
| 20 case ${NEW_PART_NUM} in |
| 21 "3" ) |
| 22 BOOT_SLOT="A" |
| 23 ;; |
| 24 "5" ) |
| 25 BOOT_SLOT="B" |
| 26 ;; |
| 27 * ) |
| 28 # Not a valid boot location. |
| 29 echo "Not a valid target parition number: ${NEW_PART_NUM}" |
| 30 exit 1 |
| 31 ;; |
| 32 esac |
16 | 33 |
17 if [ "$POSTCOMMIT" != "--postcommit" ]; then | 34 if [ "$POSTCOMMIT" != "--postcommit" ]; then |
18 # Pre-commit. Returning an error here will prevent ever booting into the | 35 # Pre-commit. Returning an error here will prevent ever booting into the |
19 # installed system. | 36 # installed system. |
20 | 37 |
| 38 echo "Postinst running" |
| 39 echo " Set boot target to ${INSTALL_DEV}: \ |
| 40 Partition ${NEW_PART_NUM}, Slot ${BOOT_SLOT}" |
| 41 |
| 42 echo "Updating /boot/extlinux.conf target" |
21 # If the mount-point is read-write, update the bootloader | 43 # If the mount-point is read-write, update the bootloader |
22 # Only update extlinux.conf if $1 is non-empty | 44 # Only update extlinux.conf if $1 is non-empty |
23 if [ -n "$INSTALL_DEV" ]; then | 45 if [ -n "$INSTALL_DEV" ]; then |
24 # Set default label to chromeos-hd. | 46 # Set default label to chromeos-hd. |
25 sed -i 's/^DEFAULT .*/DEFAULT chromeos-hd/' \ | 47 sed -i 's/^DEFAULT .*/DEFAULT chromeos-hd/' \ |
26 "$INSTALL_ROOT"/boot/extlinux.conf || true | 48 "$INSTALL_ROOT"/boot/extlinux.conf || true |
27 sed -i "{ s:HDROOT:$INSTALL_DEV: }" \ | 49 sed -i "{ s:HDROOT:$INSTALL_DEV: }" \ |
28 "$INSTALL_ROOT"/boot/extlinux.conf || true | 50 "$INSTALL_ROOT"/boot/extlinux.conf || true |
29 fi | 51 fi |
30 | 52 |
| 53 echo "Updating grub target for EFI BIOS" |
| 54 # Set up grub.cfg |
| 55 ${INSTALL_ROOT}/usr/sbin/chromeos-setimage ${BOOT_SLOT} \ |
| 56 --dst=${ROOT_DEV} --run_as_root |
| 57 |
| 58 # Set up gpt boot selection for legacy devices. |
| 59 # flush linux caches; seems to be necessary |
| 60 sync |
| 61 echo 3 > /proc/sys/vm/drop_caches |
| 62 |
| 63 echo "Updating gpt PMBR target for legacy BIOS" |
| 64 # Configure the PMBR to boot the new image. |
| 65 # TODO(wfrichar): The current gpt tool requires a -b arg to specify the PMBR |
| 66 # bootcode. We don't want to change the code, so we have to extract it, then |
| 67 # put it back. We'll fix this RSN. |
| 68 |
| 69 # IMPORTANT NOTE: postinst is run by the previoulsy installed image |
| 70 # rather than the new image. So changes here need to be backwards compatible |
| 71 # with the old image's gpt binaries. |
| 72 dd if=${ROOT_DEV} bs=512 count=1 of=/tmp/oldpmbr.bin |
| 73 gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 |
31 else | 74 else |
32 # Post-commit. At this point an unexpected reboot may boot the installed | 75 # Post-commit. At this point an unexpected reboot may boot the installed |
33 # system, but returning an error here will cause the updater to try to | 76 # system, but returning an error here will cause the updater to try to |
34 # not boot the installed system, instead keeping the existing system. | 77 # not boot the installed system, instead keeping the existing system. |
35 | 78 |
36 echo -n # this is a noop, required for 'sh' | 79 echo -n # this is a noop, required for 'sh' |
37 fi | 80 fi |
38 | 81 |
39 | 82 |
OLD | NEW |