| Index: src/scripts/image_to_usb.sh
|
| diff --git a/src/scripts/image_to_usb.sh b/src/scripts/image_to_usb.sh
|
| index 7aa6707d29a3620894fa4742782d795621d5e0e8..ecd4173adf3cf737918826776b21f48d289b1e42 100755
|
| --- a/src/scripts/image_to_usb.sh
|
| +++ b/src/scripts/image_to_usb.sh
|
| @@ -8,11 +8,17 @@
|
|
|
| # Load common constants. This should be the first executable line.
|
| # The path to common.sh should be relative to your script's location.
|
| -. "$(dirname "$0")/common.sh"
|
| +THIS_DIR="$(dirname "$0")"
|
| +. "${THIS_DIR}/common.sh"
|
|
|
| -IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
|
| -# Default to the most recent image
|
| -DEFAULT_FROM="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)"
|
| +# Default to the current directory or the most recent image if none found.
|
| +DEFAULT_FROM=
|
| +if [ -f "${THIS_DIR}/rootfs.image" ]; then
|
| + DEFAULT_FROM="$THIS_DIR"
|
| +else
|
| + IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
|
| + DEFAULT_FROM="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)"
|
| +fi
|
|
|
| # Script can be run either inside or outside the chroot.
|
| if [ $INSIDE_CHROOT -eq 1 ]
|
| @@ -32,6 +38,8 @@ DEFINE_string from "$DEFAULT_FROM" \
|
| "Directory containing rootfs.image and mbr.image"
|
| DEFINE_string to "$DEFAULT_TO" "$DEFAULT_TO_HELP"
|
| DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y"
|
| +DEFINE_string data_part_size_mb '' \
|
| + "Override automatic calculation of user data partition size with value in MB."
|
|
|
| # Parse command line
|
| FLAGS "$@" || exit 1
|
| @@ -44,92 +52,32 @@ set -e
|
| # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
|
| FLAGS_from=`eval readlink -f $FLAGS_from`
|
| FLAGS_to=`eval readlink -f $FLAGS_to`
|
| -
|
| -function do_cleanup {
|
| - sudo losetup -d "$LOOP_DEV"
|
| -}
|
| -
|
| -# Copy MBR and rootfs to output image
|
| -if [ -b "$FLAGS_to" ]
|
| -then
|
| - # Output to a block device (i.e., a real USB key), so need sudo dd
|
| - echo "Copying USB image ${FLAGS_from} to device ${FLAGS_to}..."
|
| -
|
| - # Make sure this is really what the user wants, before nuking the device
|
| - if [ $FLAGS_yes -ne $FLAGS_TRUE ]
|
| - then
|
| - echo "This will erase all data on this device:"
|
| - sudo fdisk -l "$FLAGS_to" | grep Disk | head -1
|
| - read -p "Are you sure (y/N)? " SURE
|
| - SURE="${SURE:0:1}" # Get just the first character
|
| - if [ "$SURE" != "y" ]
|
| - then
|
| - echo "Ok, better safe than sorry."
|
| - exit 1
|
| - fi
|
| - fi
|
| -
|
| - echo "attempting to unmount any mounts on the USB device"
|
| +if [ -b "$FLAGS_to" ] ; then
|
| + echo "attempting to unmount any mounts on the destination device"
|
| for i in "$FLAGS_to"*
|
| do
|
| - ! sudo umount "$i"
|
| + ! sudo umount "$i"
|
| done
|
| sleep 3
|
| +fi
|
|
|
| - PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") # Bytes
|
| -
|
| - echo "Copying root fs..."
|
| - sudo "${SCRIPTS_DIR}"/file_copy.py \
|
| - if="${FLAGS_from}/rootfs.image" \
|
| - of="$FLAGS_to" bs=4M \
|
| - seek_bytes=$(( ($PART_SIZE * 2) + 512 ))
|
| -
|
| - # Set up loop device
|
| - LOOP_DEV=$(sudo losetup -f)
|
| - if [ -z "$LOOP_DEV" ]
|
| - then
|
| - echo "No free loop device. Free up a loop device or reboot. exiting."
|
| - exit 1
|
| - fi
|
| -
|
| - trap do_cleanup EXIT
|
| +MBR="${FLAGS_from}/mbr.image"
|
| +GPT="${FLAGS_from}/gpt"
|
| +if [ -n "$FLAGS_data_part_size_mb" ] ; then
|
| + STATEFUL_PART_SIZE=$((FLAGS_data_part_size_mb * 1024 * 1024))
|
| +fi
|
| +. "${FLAGS_from}/chromeos_install_functions.sh"
|
|
|
| - echo "Creating stateful partition..."
|
| - sudo losetup -o 512 "$LOOP_DEV" "$FLAGS_to"
|
| - sudo mkfs.ext3 -F -b 4096 -L C-STATE "$LOOP_DEV" $(( $PART_SIZE / 4096 ))
|
| - sync
|
| - sudo losetup -d "$LOOP_DEV"
|
| - sync
|
| +# Make sure that the destination file/device is ok to blow away.
|
| +do_verify "${FLAGS_from}/rootfs.image" "$FLAGS_to" "minimal"
|
|
|
| - trap - EXIT
|
| +# Perform standard installation to destination.
|
| +install_chromeos "${FLAGS_from}/rootfs.image" "$FLAGS_to" "C" "minimal"
|
|
|
| - echo "Copying MBR..."
|
| - sudo "${SCRIPTS_DIR}"/file_copy.py \
|
| - if="${FLAGS_from}/mbr.image" of="$FLAGS_to"
|
| - sync
|
| - echo "Done."
|
| +if [ -b "$FLAGS_to" ] ; then
|
| + echo "Done. You may remove your device and try to boot it."
|
| else
|
| - # Output to a file, so just cat the source images together
|
| -
|
| - PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image")
|
| -
|
| - echo "Creating empty stateful partition"
|
| - dd if=/dev/zero of="${FLAGS_from}/stateful_partition.image" bs=1 count=1 \
|
| - seek=$(($PART_SIZE - 1))
|
| - mkfs.ext3 -F -L C-STATE "${FLAGS_from}/stateful_partition.image"
|
| -
|
| - # Create a sparse output file
|
| - dd if=/dev/zero of="${FLAGS_to}" bs=1 count=1 \
|
| - seek=$(( ($PART_SIZE * 2) + 512 - 1))
|
| -
|
| - echo "Copying USB image to file ${FLAGS_to}..."
|
| -
|
| - dd if="${FLAGS_from}/mbr.image" of="$FLAGS_to" conv=notrunc
|
| - dd if="${FLAGS_from}/stateful_partition.image" of="$FLAGS_to" seek=1 bs=512 \
|
| - conv=notrunc
|
| - cat "${FLAGS_from}/rootfs.image" >> "$FLAGS_to"
|
| -
|
| - echo "Done. To copy to USB keyfob, outside the chroot, do something like:"
|
| + echo "Done. To copy to USB keyfob, outside the chroot, do something like:"
|
| echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M"
|
| echo "where /dev/sdb is the entire keyfob."
|
| if [ $INSIDE_CHROOT -eq 1 ]
|
|
|