Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: mount_gpt_image.sh

Issue 3479007: Add read only flag to mount_gpt_image (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Remove eval and re-tested. Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 \
22 "Mount in read only mode -- skips stateful items."
21 DEFINE_boolean unmount $FLAGS_FALSE \ 23 DEFINE_boolean unmount $FLAGS_FALSE \
22 "Unmount previously mounted dir." u 24 "Unmount previously mounted dir." u
23 DEFINE_string from "/dev/sdc" \ 25 DEFINE_string from "/dev/sdc" \
24 "Directory containing image or device with image on it" f 26 "Directory containing image or device with image on it" f
25 DEFINE_string image "chromiumos_image.bin"\ 27 DEFINE_string image "chromiumos_image.bin"\
26 "Name of the bin file if a directory is specified in the from flag" i 28 "Name of the bin file if a directory is specified in the from flag" i
27 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" 29 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r"
28 DEFINE_string "stateful_mountpt" "/tmp/s" \ 30 DEFINE_string "stateful_mountpt" "/tmp/s" \
29 "Mount point for stateful partition" "s" 31 "Mount point for stateful partition" "s"
30 DEFINE_string "esp_mountpt" "" \ 32 DEFINE_string "esp_mountpt" "" \
31 "Mount point for esp partition" "e" 33 "Mount point for esp partition" "e"
32 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m 34 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m
33 35
34 # Parse flags 36 # Parse flags
35 FLAGS "$@" || exit 1 37 FLAGS "$@" || exit 1
36 eval set -- "${FLAGS_ARGV}" 38 eval set -- "${FLAGS_ARGV}"
37 39
38 # Die on error 40 # Die on error
39 set -e 41 set -e
40 42
41 # Common unmounts for either a device or directory 43 # Common unmounts for either a device or directory
42 function unmount_image() { 44 function unmount_image() {
43 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ 45 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \
44 "and ${FLAGS_rootfs_mountpt}" 46 "and ${FLAGS_rootfs_mountpt}"
45 # Don't die on error to force cleanup 47 # Don't die on error to force cleanup
46 set +e 48 set +e
47 # Reset symlinks in /usr/local. 49 # Reset symlinks in /usr/local.
48 setup_symlinks_on_root "/usr/local" "/var" \ 50 if mount | grep "${FLAGS_rootfs_mountpt} (rw,bind)"; then
49 "${FLAGS_stateful_mountpt}" 51 setup_symlinks_on_root "/usr/local" "/var" \
50 fix_broken_symlinks "${FLAGS_rootfs_mountpt}" 52 "${FLAGS_stateful_mountpt}"
53 fix_broken_symlinks "${FLAGS_rootfs_mountpt}"
54 fi
51 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" 55 sudo umount "${FLAGS_rootfs_mountpt}/usr/local"
52 sudo umount "${FLAGS_rootfs_mountpt}/var" 56 sudo umount "${FLAGS_rootfs_mountpt}/var"
53 if [[ -n "${FLAGS_esp_mountpt}" ]]; then 57 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
54 sudo umount -d "${FLAGS_esp_mountpt}" 58 sudo umount -d "${FLAGS_esp_mountpt}"
55 fi 59 fi
56 sudo umount -d "${FLAGS_stateful_mountpt}" 60 sudo umount -d "${FLAGS_stateful_mountpt}"
57 sudo umount -d "${FLAGS_rootfs_mountpt}" 61 sudo umount -d "${FLAGS_rootfs_mountpt}"
58 set -e 62 set -e
59 } 63 }
60 64
61 function get_usb_partitions() { 65 function get_usb_partitions() {
62 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" 66 local ro_flag=""
63 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" 67 [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro"
68
69 sudo mount ${ro_flag} "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
70 sudo mount ${ro_flag} "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
64 if [[ -n "${FLAGS_esp_mountpt}" ]]; then 71 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
65 sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}" 72 sudo mount ${ro_flag} "${FLAGS_from}12" "${FLAGS_esp_mountpt}"
66 fi 73 fi
67 } 74 }
68 75
69 function get_gpt_partitions() { 76 function get_gpt_partitions() {
70 local filename="${FLAGS_image}" 77 local filename="${FLAGS_image}"
71 78
72 # Mount the rootfs partition using a loopback device. 79 # Mount the rootfs partition using a loopback device.
73 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) 80 local offset=$(partoffset "${FLAGS_from}/${filename}" 3)
74 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ 81 local ro_flag=""
75 "${FLAGS_rootfs_mountpt}" 82 [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro"
83
84 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
85 "${FLAGS_from}/${filename}" "${FLAGS_rootfs_mountpt}"
76 86
77 # Mount the stateful partition using a loopback device. 87 # Mount the stateful partition using a loopback device.
78 offset=$(partoffset "${FLAGS_from}/${filename}" 1) 88 offset=$(partoffset "${FLAGS_from}/${filename}" 1)
79 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ 89 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
80 "${FLAGS_stateful_mountpt}" 90 "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}"
81 91
82 # Mount the stateful partition using a loopback device. 92 # Mount the stateful partition using a loopback device.
83 if [[ -n "${FLAGS_esp_mountpt}" ]]; then 93 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
84 offset=$(partoffset "${FLAGS_from}/${filename}" 12) 94 offset=$(partoffset "${FLAGS_from}/${filename}" 12)
85 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ 95 sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
86 "${FLAGS_esp_mountpt}" 96 "${FLAGS_from}/${filename}" "${FLAGS_esp_mountpt}"
87 fi 97 fi
88 } 98 }
89 99
90 # Mount a gpt based image. 100 # Mount a gpt based image.
91 function mount_image() { 101 function mount_image() {
92 mkdir -p "${FLAGS_rootfs_mountpt}" 102 mkdir -p "${FLAGS_rootfs_mountpt}"
93 mkdir -p "${FLAGS_stateful_mountpt}" 103 mkdir -p "${FLAGS_stateful_mountpt}"
94 if [[ -n "${FLAGS_esp_mountpt}" ]]; then 104 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
95 mkdir -p "${FLAGS_esp_mountpt}" 105 mkdir -p "${FLAGS_esp_mountpt}"
96 fi 106 fi
97 107
98 # Get the partitions for the image / device. 108 # Get the partitions for the image / device.
99 if [ -b ${FLAGS_from} ] ; then 109 if [ -b ${FLAGS_from} ] ; then
100 get_usb_partitions 110 get_usb_partitions
101 else 111 else
102 get_gpt_partitions 112 get_gpt_partitions
103 fi 113 fi
104 114
105 # Mount directories and setup symlinks. 115 # Mount directories and setup symlinks.
106 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ 116 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \
107 "${FLAGS_rootfs_mountpt}/var" 117 "${FLAGS_rootfs_mountpt}/var"
108 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ 118 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \
109 "${FLAGS_rootfs_mountpt}/usr/local" 119 "${FLAGS_rootfs_mountpt}/usr/local"
110 # Setup symlinks in /usr/local so you can emerge packages into /usr/local. 120 # Setup symlinks in /usr/local so you can emerge packages into /usr/local.
111 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ 121
112 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" 122 if [ ${FLAGS_read_only} -eq ${FLAGS_FALSE} ]; then
123 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
124 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
125 fi
113 echo "Image specified by ${FLAGS_from} mounted at"\ 126 echo "Image specified by ${FLAGS_from} mounted at"\
114 "${FLAGS_rootfs_mountpt} successfully." 127 "${FLAGS_rootfs_mountpt} successfully."
115 } 128 }
116 129
117 # Find the last image built on the board. 130 # Find the last image built on the board.
118 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then 131 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then
119 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" 132 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
120 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" 133 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)"
121 fi 134 fi
122 135
123 # Turn path into an absolute path. 136 # Turn path into an absolute path.
124 FLAGS_from=`eval readlink -f ${FLAGS_from}` 137 FLAGS_from=`eval readlink -f ${FLAGS_from}`
125 138
126 # Perform desired operation. 139 # Perform desired operation.
127 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then 140 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then
128 unmount_image 141 unmount_image
129 else 142 else
130 mount_image 143 mount_image
131 fi 144 fi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698