| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 # Helper script that mounts chromium os image from a device or directory | 7 # Helper script that mounts chromium os image from a device or directory |
| 8 # and creates mount points for /var and /usr/local (if in dev_mode). | 8 # and creates mount points for /var and /usr/local (if in dev_mode). |
| 9 | 9 |
| 10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
| 11 | 11 |
| 12 # For functions related to gpt images. | 12 # For functions related to gpt images. |
| 13 . "$(dirname "$0")/chromeos-common.sh" | 13 . "$(dirname "$0")/chromeos-common.sh" |
| 14 locate_gpt | 14 locate_gpt |
| 15 | 15 |
| 16 get_default_board | 16 get_default_board |
| 17 | 17 |
| 18 # Flags. | 18 # Flags. |
| 19 DEFINE_string board "$DEFAULT_BOARD" \ | 19 DEFINE_string board "$DEFAULT_BOARD" \ |
| 20 "The board for which the image was built." b | 20 "The board for which the image was built." b |
| 21 DEFINE_boolean read_only $FLAGS_FALSE \ | 21 DEFINE_boolean read_only $FLAGS_FALSE \ |
| 22 "Mount in read only mode -- skips stateful items." | 22 "Mount in read only mode -- skips stateful items." |
| 23 DEFINE_boolean safe $FLAGS_FALSE \ |
| 24 "Mount rootfs in read only mode." |
| 23 DEFINE_boolean unmount $FLAGS_FALSE \ | 25 DEFINE_boolean unmount $FLAGS_FALSE \ |
| 24 "Unmount previously mounted dir." u | 26 "Unmount previously mounted dir." u |
| 25 DEFINE_string from "/dev/sdc" \ | 27 DEFINE_string from "/dev/sdc" \ |
| 26 "Directory containing image or device with image on it" f | 28 "Directory containing image or device with image on it" f |
| 27 DEFINE_string image "chromiumos_image.bin"\ | 29 DEFINE_string image "chromiumos_image.bin"\ |
| 28 "Name of the bin file if a directory is specified in the from flag" i | 30 "Name of the bin file if a directory is specified in the from flag" i |
| 29 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" | 31 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" |
| 30 DEFINE_string "stateful_mountpt" "/tmp/s" \ | 32 DEFINE_string "stateful_mountpt" "/tmp/s" \ |
| 31 "Mount point for stateful partition" "s" | 33 "Mount point for stateful partition" "s" |
| 32 DEFINE_string "esp_mountpt" "" \ | 34 DEFINE_string "esp_mountpt" "" \ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 if [[ -n "${FLAGS_esp_mountpt}" ]]; then | 59 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
| 58 sudo umount -d "${FLAGS_esp_mountpt}" | 60 sudo umount -d "${FLAGS_esp_mountpt}" |
| 59 fi | 61 fi |
| 60 sudo umount -d "${FLAGS_stateful_mountpt}" | 62 sudo umount -d "${FLAGS_stateful_mountpt}" |
| 61 sudo umount -d "${FLAGS_rootfs_mountpt}" | 63 sudo umount -d "${FLAGS_rootfs_mountpt}" |
| 62 set -e | 64 set -e |
| 63 } | 65 } |
| 64 | 66 |
| 65 function get_usb_partitions() { | 67 function get_usb_partitions() { |
| 66 local ro_flag="" | 68 local ro_flag="" |
| 69 local safe_flag="" |
| 67 [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro" | 70 [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro" |
| 71 [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} -o \ |
| 72 ${FLAGS_safe} -eq ${FLAGS_TRUE} ] && safe_flag="-o ro -t ext2" |
| 68 | 73 |
| 69 sudo mount ${ro_flag} "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" | 74 sudo mount ${safe_flag} "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" |
| 70 sudo mount ${ro_flag} "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" | 75 sudo mount ${ro_flag} "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" |
| 71 if [[ -n "${FLAGS_esp_mountpt}" ]]; then | 76 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
| 72 sudo mount ${ro_flag} "${FLAGS_from}12" "${FLAGS_esp_mountpt}" | 77 sudo mount ${ro_flag} "${FLAGS_from}12" "${FLAGS_esp_mountpt}" |
| 73 fi | 78 fi |
| 74 } | 79 } |
| 75 | 80 |
| 76 function get_gpt_partitions() { | 81 function get_gpt_partitions() { |
| 77 local filename="${FLAGS_image}" | 82 local filename="${FLAGS_image}" |
| 78 | 83 |
| 79 # Mount the rootfs partition using a loopback device. | 84 # Mount the rootfs partition using a loopback device. |
| 80 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) | 85 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) |
| 81 local ro_flag="" | 86 local ro_flag="" |
| 87 local safe_flag="" |
| 88 |
| 82 if [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ]; then | 89 if [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ]; then |
| 83 ro_flag="-o ro" | 90 ro_flag="-o ro" |
| 91 fi |
| 92 |
| 93 if [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} -o \ |
| 94 ${FLAGS_safe} -eq ${FLAGS_TRUE} ]; then |
| 95 safe_flag="-o ro -t ext2" |
| 84 else | 96 else |
| 85 # Make sure any callers can actually mount and modify the fs | 97 # Make sure any callers can actually mount and modify the fs |
| 86 # if desired. | 98 # if desired. |
| 87 # cros_make_image_bootable should restore the bit if needed. | 99 # cros_make_image_bootable should restore the bit if needed. |
| 88 enable_rw_mount "${FLAGS_from}/${filename}" "$(( offset * 512 ))" | 100 enable_rw_mount "${FLAGS_from}/${filename}" "$(( offset * 512 ))" |
| 89 fi | 101 fi |
| 90 | 102 |
| 91 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \ | 103 sudo mount ${safe_flag} -o loop,offset=$(( offset * 512 )) \ |
| 92 "${FLAGS_from}/${filename}" "${FLAGS_rootfs_mountpt}" | 104 "${FLAGS_from}/${filename}" "${FLAGS_rootfs_mountpt}" |
| 93 | 105 |
| 94 # Mount the stateful partition using a loopback device. | 106 # Mount the stateful partition using a loopback device. |
| 95 offset=$(partoffset "${FLAGS_from}/${filename}" 1) | 107 offset=$(partoffset "${FLAGS_from}/${filename}" 1) |
| 96 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \ | 108 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \ |
| 97 "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}" | 109 "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}" |
| 98 | 110 |
| 99 # Mount the stateful partition using a loopback device. | 111 # Mount the stateful partition using a loopback device. |
| 100 if [[ -n "${FLAGS_esp_mountpt}" ]]; then | 112 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
| 101 offset=$(partoffset "${FLAGS_from}/${filename}" 12) | 113 offset=$(partoffset "${FLAGS_from}/${filename}" 12) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 155 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
| 144 FLAGS_rootfs_mountpt=`eval readlink -f ${FLAGS_rootfs_mountpt}` | 156 FLAGS_rootfs_mountpt=`eval readlink -f ${FLAGS_rootfs_mountpt}` |
| 145 FLAGS_stateful_mountpt=`eval readlink -f ${FLAGS_stateful_mountpt}` | 157 FLAGS_stateful_mountpt=`eval readlink -f ${FLAGS_stateful_mountpt}` |
| 146 | 158 |
| 147 # Perform desired operation. | 159 # Perform desired operation. |
| 148 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then | 160 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then |
| 149 unmount_image | 161 unmount_image |
| 150 else | 162 else |
| 151 mount_image | 163 mount_image |
| 152 fi | 164 fi |
| OLD | NEW |