| Index: src/scripts/mount_gpt_image.sh
|
| diff --git a/src/scripts/mount_gpt_image.sh b/src/scripts/mount_gpt_image.sh
|
| index 7d59ef4496a01b3e4f54361bf2a17a6d370174f0..a739675d4965933f9c10bf4395c3afb702d7b846 100755
|
| --- a/src/scripts/mount_gpt_image.sh
|
| +++ b/src/scripts/mount_gpt_image.sh
|
| @@ -9,6 +9,9 @@
|
|
|
| . "$(dirname "$0")/common.sh"
|
|
|
| +# For functions related to gpt images.
|
| +. "$(dirname "$0")/chromeos-common.sh"
|
| +
|
| get_default_board
|
|
|
| # Flags.
|
| @@ -18,7 +21,8 @@ DEFINE_boolean unmount $FLAGS_FALSE \
|
| "Unmount previously mounted dir." u
|
| DEFINE_string from "/dev/sdc" \
|
| "Directory containing image or device with image on it" f
|
| -DEFINE_boolean test $FLAGS_FALSE "Use chromiumos_test_image.bin" t
|
| +DEFINE_string image "chromiumos_image.bin"\
|
| + "Name of the bin file if a directory is specified in the from flag" i
|
| DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r"
|
| DEFINE_string "stateful_mountpt" "/tmp/s" \
|
| "Mount point for stateful partition" "s"
|
| @@ -31,13 +35,16 @@ eval set -- "${FLAGS_ARGV}"
|
| # Die on error
|
| set -e
|
|
|
| -# Common umounts for either a device or directory
|
| -function unmount_common() {
|
| +# Common unmounts for either a device or directory
|
| +function unmount_image() {
|
| echo "Unmounting image from ${FLAGS_stateful_mountpt}" \
|
| "and ${FLAGS_rootfs_mountpt}"
|
| # Don't die on error to force cleanup
|
| set +e
|
| if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then
|
| + # Reset symlinks in /usr/local.
|
| + setup_symlinks_on_root "/usr/local" "/var" \
|
| + "${FLAGS_stateful_mountpt}"
|
| sudo umount "${FLAGS_rootfs_mountpt}/usr/local"
|
| fi
|
| sudo umount "${FLAGS_rootfs_mountpt}/var"
|
| @@ -46,55 +53,63 @@ function unmount_common() {
|
| set -e
|
| }
|
|
|
| -# Sets up the rootfs and stateful partitions specified by
|
| -# ${FLAGS_from}${prefix}[31] to the given mount points and sets up var and
|
| -# usr/local
|
| -# ${1} - prefix name for the partition
|
| -# ${2} - extra mount options for the partitions
|
| -function mount_common() {
|
| +function get_usb_partitions() {
|
| + sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
|
| + sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
|
| +}
|
| +
|
| +function get_gpt_partitions() {
|
| + local filename="${FLAGS_image}"
|
| +
|
| + # Mount the rootfs partition using a loopback device.
|
| + local offset=$(partoffset "${FLAGS_from}/${filename}" 3)
|
| + sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
|
| + "${FLAGS_rootfs_mountpt}"
|
| +
|
| + # Mount the stateful partition using a loopback device.
|
| + offset=$(partoffset "${FLAGS_from}/${filename}" 1)
|
| + sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
|
| + "${FLAGS_stateful_mountpt}"
|
| +}
|
| +
|
| +# Mount a gpt based image.
|
| +function mount_image() {
|
| mkdir -p "${FLAGS_rootfs_mountpt}"
|
| mkdir -p "${FLAGS_stateful_mountpt}"
|
| - sudo mount ${2} "${FLAGS_from}${1}3" "${FLAGS_rootfs_mountpt}"
|
| - sudo mount ${2} "${FLAGS_from}${1}1" "${FLAGS_stateful_mountpt}"
|
| +
|
| + # Get the partitions for the image / device.
|
| + if [ -b ${FLAGS_from} ] ; then
|
| + get_usb_partitions
|
| + else
|
| + get_gpt_partitions
|
| + fi
|
| +
|
| + # Mount var unconditionally and then setup /usr/local for user of dev mode.
|
| sudo mount --bind "${FLAGS_stateful_mountpt}/var" \
|
| "${FLAGS_rootfs_mountpt}/var"
|
| if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then
|
| sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \
|
| "${FLAGS_rootfs_mountpt}/usr/local"
|
| + # Setup symlinks in /usr/local so you can emerge packages into /usr/local.
|
| + setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
|
| + "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
|
| fi
|
| - echo "Root FS specified by "${FLAGS_from}${1}3" mounted at"\
|
| + echo "Image specified by ${FLAGS_from} mounted at"\
|
| "${FLAGS_rootfs_mountpt} successfully."
|
| }
|
|
|
| -# Find the last image built on the board
|
| +# Find the last image built on the board.
|
| if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then
|
| IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
|
| FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)"
|
| fi
|
|
|
| -# Turn into absolute path
|
| +# Turn path into an absolute path.
|
| FLAGS_from=`eval readlink -f ${FLAGS_from}`
|
|
|
| -# Set the file name of the image if ${FLAGS_from} is not a device and cd
|
| -if [ -d "${FLAGS_from}" ] ; then
|
| - cd "${FLAGS_from}"
|
| - IMAGE_NAME=chromiumos_image.bin
|
| - [ ${FLAGS_test} -eq ${FLAGS_TRUE} ] && IMAGE_NAME=chromiumos_test_image.bin
|
| -fi
|
| -
|
| +# Perform desired operation.
|
| if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then
|
| - unmount_common
|
| - if [ -d "${FLAGS_from}" ] ; then
|
| - echo "Re-packing partitions onto ${FLAGS_from}/${IMAGE_NAME}"
|
| - ./pack_partitions.sh ${IMAGE_NAME} 2> /dev/null
|
| - sudo rm part_*
|
| - fi
|
| + unmount_image
|
| else
|
| - if [ -b ${FLAGS_from} ] ; then
|
| - mount_common "" ""
|
| - else
|
| - echo "Unpacking partitions from ${FLAGS_from}/${IMAGE_NAME}"
|
| - ./unpack_partitions.sh ${IMAGE_NAME} 2> /dev/null
|
| - mount_common "/part_" "-o loop"
|
| - fi
|
| + mount_image
|
| fi
|
|
|