| 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 # Load functions and constants for chromeos-install. | |
| 13 . "$(dirname "$0")/chromeos-common.sh" || exit 1 | |
| 14 | |
| 15 # Update /boot/extlinux.conf. | 12 # Update /boot/extlinux.conf. |
| 16 INSTALL_ROOT=`dirname "$0"` | 13 INSTALL_ROOT=$(dirname "$0") |
| 17 INSTALL_DEV="$1" | 14 INSTALL_DEV="$1" |
| 18 POSTCOMMIT="$2" | 15 POSTCOMMIT="$2" |
| 16 # Load helper functions |
| 17 . "${INSTALL_ROOT}"/usr/sbin/chromeos-common.sh |
| 19 # Find whole disk device. | 18 # Find whole disk device. |
| 20 ROOT_DEV=${INSTALL_DEV%%[0-9]*} | 19 ROOT_DEV=$(get_block_dev_from_partition_dev ${INSTALL_DEV}) |
| 21 NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]} | 20 NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]} |
| 22 | 21 |
| 23 case ${NEW_PART_NUM} in | 22 case ${NEW_PART_NUM} in |
| 24 "3" ) | 23 "3" ) |
| 25 BOOT_SLOT="A" | 24 BOOT_SLOT="A" |
| 26 ;; | 25 ;; |
| 27 "5" ) | 26 "5" ) |
| 28 BOOT_SLOT="B" | 27 BOOT_SLOT="B" |
| 29 ;; | 28 ;; |
| 30 * ) | 29 * ) |
| 31 # Not a valid boot location. | 30 # Not a valid boot location. |
| 32 echo "Not a valid target parition number: ${NEW_PART_NUM}" | 31 echo "Not a valid target parition number: ${NEW_PART_NUM}" |
| 33 exit 1 | 32 exit 1 |
| 34 ;; | 33 ;; |
| 35 esac | 34 esac |
| 36 | 35 |
| 37 if [ "$POSTCOMMIT" != "--postcommit" ]; then | 36 if [ "$POSTCOMMIT" != "--postcommit" ]; then |
| 38 # Pre-commit. Returning an error here will prevent ever booting into the | 37 # Pre-commit. Returning an error here will prevent ever booting into the |
| 39 # installed system. | 38 # installed system. |
| 40 | 39 |
| 41 echo "Postinst running" | 40 echo "Postinst running" |
| 42 echo " Set boot target to ${INSTALL_DEV}: \ | 41 echo " Set boot target to ${INSTALL_DEV}: \ |
| 43 Partition ${NEW_PART_NUM}, Slot ${BOOT_SLOT}" | 42 Partition ${NEW_PART_NUM}, Slot ${BOOT_SLOT}" |
| 44 | 43 |
| 45 echo "Updating /boot/extlinux.conf target" | 44 if [ -f /boot/extlinux.conf ]; then |
| 46 # If the mount-point is read-write, update the bootloader | 45 echo "Updating /boot/extlinux.conf target" |
| 47 # Only update extlinux.conf if $1 is non-empty | 46 # If the mount-point is read-write, update the bootloader |
| 48 if [ -n "$INSTALL_DEV" ]; then | 47 # Only update extlinux.conf if $1 is non-empty |
| 49 # Set default label to chromeos-hd. | 48 if [ -n "$INSTALL_DEV" ]; then |
| 50 sed -i 's/^DEFAULT .*/DEFAULT chromeos-hd/' \ | 49 # Set default label to chromeos-hd. |
| 51 "$INSTALL_ROOT"/boot/extlinux.conf || true | 50 sed -i 's/^DEFAULT .*/DEFAULT chromeos-hd/' \ |
| 52 sed -i "{ s:HDROOT:$INSTALL_DEV: }" \ | 51 "$INSTALL_ROOT"/boot/extlinux.conf || true |
| 53 "$INSTALL_ROOT"/boot/extlinux.conf || true | 52 sed -i "{ s:HDROOT:$INSTALL_DEV: }" \ |
| 53 "$INSTALL_ROOT"/boot/extlinux.conf || true |
| 54 fi |
| 54 fi | 55 fi |
| 55 | 56 |
| 57 |
| 56 echo "Updating grub target for EFI BIOS" | 58 echo "Updating grub target for EFI BIOS" |
| 57 # Set up grub.cfg | 59 # Set up grub.cfg |
| 58 ${INSTALL_ROOT}/usr/sbin/chromeos-setimage ${BOOT_SLOT} \ | 60 "${INSTALL_ROOT}"/usr/sbin/chromeos-setimage ${BOOT_SLOT} \ |
| 59 --dst=${ROOT_DEV} --run_as_root | 61 --dst=${ROOT_DEV} --run_as_root |
| 60 | 62 |
| 61 # Set up gpt boot selection for legacy devices. | 63 # Set up gpt boot selection for legacy devices. |
| 62 # flush linux caches; seems to be necessary | 64 # flush linux caches; seems to be necessary |
| 63 sync | 65 sync |
| 64 echo 3 > /proc/sys/vm/drop_caches | 66 echo 3 > /proc/sys/vm/drop_caches |
| 65 | 67 |
| 68 |
| 66 echo "Updating gpt PMBR target for legacy BIOS" | 69 echo "Updating gpt PMBR target for legacy BIOS" |
| 67 # Configure the PMBR to boot the new image. | 70 # Configure the PMBR to boot the new image. |
| 68 # | 71 # |
| 69 # IMPORTANT NOTE: postinst is run by the previoulsy installed image | 72 # IMPORTANT NOTE: postinst is run by the previoulsy installed image |
| 70 # rather than the new image. So changes here need to be backwards compatible | 73 # rather than the new image. So changes here need to be backwards compatible |
| 71 # with the old image's gpt binaries. | 74 # with the old image's gpt binaries. |
| 72 # | 75 # |
| 73 if [ -x /usr/bin/cgpt ]; then | 76 if [ -x /usr/bin/cgpt ]; then |
| 74 cgpt boot -i $NEW_PART_NUM ${ROOT_DEV} 2>&1 | 77 cgpt boot -i $NEW_PART_NUM ${ROOT_DEV} 2>&1 |
| 75 else | 78 else |
| 76 # The old gpt tool requires a -b arg to specify the PMBR bootcode. We don't | 79 # The old gpt tool requires a -b arg to specify the PMBR bootcode. We don't |
| 77 # want to change the code, so we have to extract it, then put it back. | 80 # want to change the code, so we have to extract it, then put it back. |
| 78 dd if=${ROOT_DEV} bs=512 count=1 of=/tmp/oldpmbr.bin | 81 dd if=${ROOT_DEV} bs=512 count=1 of=/tmp/oldpmbr.bin |
| 79 gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 | 82 gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 |
| 80 fi | 83 fi |
| 81 else | 84 else |
| 82 # Post-commit. At this point an unexpected reboot may boot the installed | 85 # Post-commit. At this point an unexpected reboot may boot the installed |
| 83 # system, but returning an error here will cause the updater to try to | 86 # system, but returning an error here will cause the updater to try to |
| 84 # not boot the installed system, instead keeping the existing system. | 87 # not boot the installed system, instead keeping the existing system. |
| 85 echo -n # this is a noop, required for 'sh' | 88 echo -n # this is a noop, required for 'sh' |
| 86 fi | 89 fi |
| 87 | 90 |
| 88 | 91 |
| OLD | NEW |