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

Side by Side Diff: mount_gpt_image.sh

Issue 4974006: Allow RO rootfs and writeable stateful. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git
Patch Set: . Created 10 years, 1 month 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 \ 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
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 17 matching lines...) Expand all
119 get_gpt_partitions 131 get_gpt_partitions
120 fi 132 fi
121 133
122 # Mount directories and setup symlinks. 134 # Mount directories and setup symlinks.
123 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ 135 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \
124 "${FLAGS_rootfs_mountpt}/var" 136 "${FLAGS_rootfs_mountpt}/var"
125 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ 137 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \
126 "${FLAGS_rootfs_mountpt}/usr/local" 138 "${FLAGS_rootfs_mountpt}/usr/local"
127 # Setup symlinks in /usr/local so you can emerge packages into /usr/local. 139 # Setup symlinks in /usr/local so you can emerge packages into /usr/local.
128 140
129 if [ ${FLAGS_read_only} -eq ${FLAGS_FALSE} ]; then 141 if [ ${FLAGS_read_only} -eq ${FLAGS_FALSE} -a \
sosa 2010/11/16 23:04:24 Should be -o FLAGS_safe = true ... if the stateful
Nick Sanders 2010/11/17 00:15:33 What does this do exactly, why do we want to write
sosa 2010/11/17 00:32:38 In a nutshell, there are symlinks in /usr/local (i
Nick Sanders 2010/11/17 01:00:26 Ok, that makes sense, thanks!
142 ${FLAGS_safe} -eq ${FLAGS_FALSE} ]; then
130 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ 143 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
131 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" 144 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
132 fi 145 fi
133 echo "Image specified by ${FLAGS_from} mounted at"\ 146 echo "Image specified by ${FLAGS_from} mounted at"\
134 "${FLAGS_rootfs_mountpt} successfully." 147 "${FLAGS_rootfs_mountpt} successfully."
135 } 148 }
136 149
137 # Find the last image built on the board. 150 # Find the last image built on the board.
138 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then 151 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then
139 FLAGS_from="$(./get_latest_image.sh --board="${FLAGS_board}")" 152 FLAGS_from="$(./get_latest_image.sh --board="${FLAGS_board}")"
140 fi 153 fi
141 154
142 # Turn paths into absolute paths. 155 # Turn paths into absolute paths.
143 FLAGS_from=`eval readlink -f ${FLAGS_from}` 156 FLAGS_from=`eval readlink -f ${FLAGS_from}`
144 FLAGS_rootfs_mountpt=`eval readlink -f ${FLAGS_rootfs_mountpt}` 157 FLAGS_rootfs_mountpt=`eval readlink -f ${FLAGS_rootfs_mountpt}`
145 FLAGS_stateful_mountpt=`eval readlink -f ${FLAGS_stateful_mountpt}` 158 FLAGS_stateful_mountpt=`eval readlink -f ${FLAGS_stateful_mountpt}`
146 159
147 # Perform desired operation. 160 # Perform desired operation.
148 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then 161 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then
149 unmount_image 162 unmount_image
150 else 163 else
151 mount_image 164 mount_image
152 fi 165 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