| Index: src/platform/installer/chromeos_install.sh
|
| diff --git a/src/platform/installer/chromeos_install.sh b/src/platform/installer/chromeos_install.sh
|
| index 419f17d3d9a436fa0e5fea74398abfb771fd4abe..4564a4cc253c4e9e93ceb97ad83ab714a8ad4560 100755
|
| --- a/src/platform/installer/chromeos_install.sh
|
| +++ b/src/platform/installer/chromeos_install.sh
|
| @@ -6,21 +6,14 @@
|
|
|
| # A script to install from removable media to hard disk.
|
|
|
| -if [ "$USER" != "chronos" ]
|
| -then
|
| - echo ""
|
| - echo "Note: You must be the 'chronos' user to run this script."
|
| - echo ""
|
| - echo "Usage: $0 [destination_device] [skip_source_removable_check]"
|
| - echo ""
|
| - echo "This will install the usb image to your machine's hard disk."
|
| - echo "By default, it will attempt to install to '/dev/sda'."
|
| - echo "First 'su chronos' and then run the script. It will ask"
|
| - echo "for the root password before messing with your hard disk."
|
| - echo "Skips checking whether the source device is removable if second"
|
| - echo "argument is 'true'."
|
| - exit 1
|
| -fi
|
| +echo ""
|
| +echo "Usage: $0 [destination_device] [skip_source_removable_check]"
|
| +echo ""
|
| +echo "This will install the usb image to your machine's hard disk."
|
| +echo "By default, it will attempt to install to '/dev/sda'."
|
| +echo "Skips checking whether the source device is removable if second"
|
| +echo "argument is 'true'."
|
| +echo ""
|
|
|
| DST=/dev/sda
|
| if [ -n "$1" ]
|
| @@ -83,61 +76,19 @@ then
|
| exit 1
|
| fi
|
|
|
| -# Ask for root password to be sure.
|
| -echo "This will install from '$SRC' to '$DST'. If you are sure this is "
|
| -echo "what you want then feel free to enter the root password to proceed."
|
| -sudo -K # Force them to enter a password
|
| +# TODO: We should install the mbr into the image rather than taking it from the
|
| +# source device as we do here.
|
| +MBR="/tmp/gptmbr.bin"
|
| +sudo dd if="$SRC" of="$MBR" bs=512 count=1
|
|
|
| -# Verify sizes. Since we use sfdisk, this needs to be done after we start
|
| -# asking for the root password.
|
| -SIZE=`sudo sfdisk -l "$SRC" 2>/dev/null | grep "$SRC_PARTITION" | grep '*' | awk '{ print $6 }'`
|
| -SIZE=$((SIZE * 1024))
|
| -if [ $SIZE -eq 0 ]
|
| -then
|
| - echo "Error: Unable to get system partition size."
|
| - exit 1
|
| -fi
|
| -SIZE_NEEDED=$((SIZE * 4)) # Assume 2 system images, swap, and user space.
|
| -DST_SIZE=`cat /sys/block/$DST_DEV/size`
|
| -DST_SIZE=$((DST_SIZE * 512))
|
| -if [ $DST_SIZE -lt $SIZE_NEEDED ]
|
| -then
|
| - echo "Error: Destination device is too small ($DST_SIZE vs $SIZE_NEEDED)"
|
| - exit 1
|
| -fi
|
| -
|
| -# Location to temporarily mount the new system image to fix things up.
|
| -ROOTFS_DIR="/tmp/chromeos_hd_install"
|
| -
|
| -# From now on we die on error. We set up a failure handler and continue.
|
| -error_handler() {
|
| - ! sudo umount "$ROOTFS_DIR"
|
| +. /usr/sbin/chromeos_install_functions.sh
|
|
|
| - echo "Sorry, an error occurred after we messed with the hard disk."
|
| - echo "The chromeos image was NOT installed successfully and there is "
|
| - echo "a chance that you will not be able to boot off the netbook hard disk."
|
| -}
|
| -set -e
|
| -trap error_handler EXIT
|
| +# Make sure that the destination file/device is ok to blow away.
|
| +echo "Installing from '$SRC_PARTITION' to '$DST'"
|
| +do_verify "$SRC_PARTITION" "$DST" "full"
|
|
|
| -# Set up the partition table. This is different from the USB partition table
|
| -# because the user paritition expands to fill the space on the disk.
|
| -# NOTE: We currently create an EFI partition rather than swap since the
|
| -# eeepc can take advantage of this to speed POST time.
|
| -sudo dd if="$SRC" of="$DST" bs=512 count=1
|
| -
|
| -PARTITION_NUM_SECTORS=$((SIZE / 512))
|
| -# size of the device in 512 bytes sectors:
|
| -DEVICE_NUM_SECTORS=$(cat /sys/block/${DST#/dev/}/size)
|
| -
|
| -sudo sfdisk --force -uS "$DST" <<EOF
|
| -,$(($DEVICE_NUM_SECTORS - (3 * $PARTITION_NUM_SECTORS) - 1)),L,-,
|
| -,$PARTITION_NUM_SECTORS,ef,-,
|
| -,$PARTITION_NUM_SECTORS,L,*,
|
| -,$PARTITION_NUM_SECTORS,L,-,
|
| -;
|
| -EOF
|
| -sync
|
| +# Perform standard installation to destination.
|
| +install_chromeos "$SRC_PARTITION" "$DST" "H" "full"
|
|
|
| # Tell kernel to update partition devices based on the new MBR:
|
| sudo sfdisk -R "$DST"
|
| @@ -151,56 +102,24 @@ then
|
| exit 1
|
| fi
|
|
|
| -# Copy the system image. We sync first to try to make the copy as safe as we
|
| -# can. We skip the first block which contains the filesystem label (aka
|
| -# volume name). It's 16 bytes in length at 120 bytes in the superblock,
|
| -# which is itself at offset 1024 of the device.
|
| -echo ""
|
| -echo "Copying the system image. This might take a while..."
|
| -sync
|
| -sudo dd if="$SRC_PARTITION" of="$DST_PARTITION" bs=1M seek=1 skip=1
|
| -# Copy all but the first 2 kibibytes now
|
| -sudo dd if="$SRC_PARTITION" of="$DST_PARTITION" bs=1024 seek=2 skip=2 count=1022
|
| -
|
| -# Check new file system label. We skip the first char and prefix with 'H'
|
| -NEW_LABEL=`expr substr "$LABEL" 2 ${#LABEL}`
|
| -NEW_LABEL="H${NEW_LABEL}"
|
| -if [ ${#NEW_LABEL} -gt 15 ]
|
| -then
|
| - echo "New label " "$NEW_LABEL is too long (greater than 15 bytes)"
|
| -fi
|
| +# From now on we die on error. We set up a failure handler and continue.
|
| +error_handler() {
|
| + ! sudo umount "$ROOTFS_DIR"
|
|
|
| -# Copy first 2 kibibytes of the partition to a temp file
|
| -TEMP_FILE=/tmp/install_part_head
|
| -sudo dd if="$SRC_PARTITION" of="$TEMP_FILE" bs=1024 count=2
|
| -
|
| -# Manually update the label. First zero it, then write the new label.
|
| -SUPERBLOCK_OFFSET=1024
|
| -LABEL_FIELD_OFFSET=120
|
| -LABEL_FIELD_LENGTH=16
|
| -sudo dd if=/dev/zero of="$TEMP_FILE" bs=1 \
|
| - seek=$(( $SUPERBLOCK_OFFSET + $LABEL_FIELD_OFFSET )) \
|
| - count=$LABEL_FIELD_LENGTH conv=notrunc
|
| -echo -n "$NEW_LABEL" | sudo dd of="$TEMP_FILE" \
|
| - seek=$(( $SUPERBLOCK_OFFSET + $LABEL_FIELD_OFFSET )) \
|
| - bs=1 count=15 conv=notrunc
|
| -
|
| -# Copy the temp file into the new partition
|
| -sudo dd if="$TEMP_FILE" of="$DST_PARTITION"
|
| -sudo rm -f "$TEMP_FILE"
|
| -sync
|
| + echo "Sorry, an error occurred after we messed with the hard disk."
|
| + echo "The chromeos image was NOT installed successfully and there is "
|
| + echo "a chance that you will not be able to boot off the netbook hard disk."
|
| +}
|
| +set -e
|
|
|
| -# Mount root partition
|
| -mkdir -p "$ROOTFS_DIR"
|
| +# Mount root partition and run postinst script.
|
| +ROOTFS_DIR=$(mktemp -d)
|
| +trap error_handler EXIT
|
| sudo mount "$DST_PARTITION" "$ROOTFS_DIR"
|
| -# run postinst script
|
| sudo "$ROOTFS_DIR"/postinst "$DST_PARTITION"
|
| sudo umount "$ROOTFS_DIR"
|
| -
|
| -# set up stateful partition
|
| -STATEFUL_PARTITION="${DST}1"
|
| -sudo mkfs.ext3 "$STATEFUL_PARTITION"
|
| -sudo tune2fs -L "H-STATE" "$STATEFUL_PARTITION"
|
| +trap - EXIT
|
| +rmdir "$ROOTFS_DIR"
|
|
|
| # Force data to disk before we declare done.
|
| sync
|
| @@ -209,5 +128,3 @@ echo "------------------------------------------------------------"
|
| echo ""
|
| echo "Installation to '$DST' complete."
|
| echo "Please shutdown, remove the USB device, cross your fingers, and reboot."
|
| -
|
| -trap - EXIT
|
|
|