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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mount_gpt_image.sh
diff --git a/mount_gpt_image.sh b/mount_gpt_image.sh
index 247428047c9a9a4d01c1f80343bffcb022898b46..ee7b3cc6f60de363332c1434e045b212a4ffec35 100755
--- a/mount_gpt_image.sh
+++ b/mount_gpt_image.sh
@@ -18,6 +18,8 @@ get_default_board
# Flags.
DEFINE_string board "$DEFAULT_BOARD" \
"The board for which the image was built." b
+DEFINE_boolean read_only $FLAGS_FALSE \
+ "Mount in read only mode -- skips stateful items."
DEFINE_boolean unmount $FLAGS_FALSE \
"Unmount previously mounted dir." u
DEFINE_string from "/dev/sdc" \
@@ -45,9 +47,11 @@ function unmount_image() {
# Don't die on error to force cleanup
set +e
# Reset symlinks in /usr/local.
- setup_symlinks_on_root "/usr/local" "/var" \
- "${FLAGS_stateful_mountpt}"
- fix_broken_symlinks "${FLAGS_rootfs_mountpt}"
+ if mount | grep "${FLAGS_rootfs_mountpt} (rw,bind)"; then
+ setup_symlinks_on_root "/usr/local" "/var" \
+ "${FLAGS_stateful_mountpt}"
+ fix_broken_symlinks "${FLAGS_rootfs_mountpt}"
+ fi
sudo umount "${FLAGS_rootfs_mountpt}/usr/local"
sudo umount "${FLAGS_rootfs_mountpt}/var"
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
@@ -59,10 +63,13 @@ function unmount_image() {
}
function get_usb_partitions() {
- sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
- sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
+ local ro_flag=""
+ [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro"
+
+ sudo mount ${ro_flag} "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
+ sudo mount ${ro_flag} "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
- sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}"
+ sudo mount ${ro_flag} "${FLAGS_from}12" "${FLAGS_esp_mountpt}"
fi
}
@@ -71,19 +78,22 @@ function get_gpt_partitions() {
# 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}"
+ local ro_flag=""
+ [ ${FLAGS_read_only} -eq ${FLAGS_TRUE} ] && ro_flag="-o ro"
+
+ sudo mount ${ro_flag} -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}"
+ sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
+ "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}"
# Mount the stateful partition using a loopback device.
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
offset=$(partoffset "${FLAGS_from}/${filename}" 12)
- sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
- "${FLAGS_esp_mountpt}"
+ sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
+ "${FLAGS_from}/${filename}" "${FLAGS_esp_mountpt}"
fi
}
@@ -108,8 +118,11 @@ function mount_image() {
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}"
+
+ if [ ${FLAGS_read_only} -eq ${FLAGS_FALSE} ]; then
+ setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
+ "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
+ fi
echo "Image specified by ${FLAGS_from} mounted at"\
"${FLAGS_rootfs_mountpt} successfully."
}
« 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