Add read only flag to mount_gpt_image

Change-Id: I33ea8b2148a3e49a6c5de25f2957306130ff092e

BUG=
TEST=Ran and verified with and without flag.  Checked mount and tried writing
file to rootfs (to verify it was ro).  Also re-ran cros_make_image_bootable
to make sure it worked fine after changes.

Review URL: http://codereview.chromium.org/3479007
This commit is contained in:
Chris Sosa 2010-09-28 18:24:13 -07:00
parent e86529b046
commit e7f1a2b6bb

View File

@ -18,6 +18,8 @@ get_default_board
# Flags. # Flags.
DEFINE_string board "$DEFAULT_BOARD" \ DEFINE_string board "$DEFAULT_BOARD" \
"The board for which the image was built." b "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 \ DEFINE_boolean unmount $FLAGS_FALSE \
"Unmount previously mounted dir." u "Unmount previously mounted dir." u
DEFINE_string from "/dev/sdc" \ DEFINE_string from "/dev/sdc" \
@ -45,9 +47,11 @@ function unmount_image() {
# Don't die on error to force cleanup # Don't die on error to force cleanup
set +e set +e
# Reset symlinks in /usr/local. # Reset symlinks in /usr/local.
if mount | grep "${FLAGS_rootfs_mountpt} (rw,bind)"; then
setup_symlinks_on_root "/usr/local" "/var" \ setup_symlinks_on_root "/usr/local" "/var" \
"${FLAGS_stateful_mountpt}" "${FLAGS_stateful_mountpt}"
fix_broken_symlinks "${FLAGS_rootfs_mountpt}" fix_broken_symlinks "${FLAGS_rootfs_mountpt}"
fi
sudo umount "${FLAGS_rootfs_mountpt}/usr/local" sudo umount "${FLAGS_rootfs_mountpt}/usr/local"
sudo umount "${FLAGS_rootfs_mountpt}/var" sudo umount "${FLAGS_rootfs_mountpt}/var"
if [[ -n "${FLAGS_esp_mountpt}" ]]; then if [[ -n "${FLAGS_esp_mountpt}" ]]; then
@ -59,10 +63,13 @@ function unmount_image() {
} }
function get_usb_partitions() { function get_usb_partitions() {
sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" local ro_flag=""
sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" [ ${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 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 fi
} }
@ -71,19 +78,22 @@ function get_gpt_partitions() {
# Mount the rootfs partition using a loopback device. # Mount the rootfs partition using a loopback device.
local offset=$(partoffset "${FLAGS_from}/${filename}" 3) local offset=$(partoffset "${FLAGS_from}/${filename}" 3)
sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ local ro_flag=""
"${FLAGS_rootfs_mountpt}" [ ${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. # Mount the stateful partition using a loopback device.
offset=$(partoffset "${FLAGS_from}/${filename}" 1) offset=$(partoffset "${FLAGS_from}/${filename}" 1)
sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
"${FLAGS_stateful_mountpt}" "${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}"
# Mount the stateful partition using a loopback device. # Mount the stateful partition using a loopback device.
if [[ -n "${FLAGS_esp_mountpt}" ]]; then if [[ -n "${FLAGS_esp_mountpt}" ]]; then
offset=$(partoffset "${FLAGS_from}/${filename}" 12) offset=$(partoffset "${FLAGS_from}/${filename}" 12)
sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
"${FLAGS_esp_mountpt}" "${FLAGS_from}/${filename}" "${FLAGS_esp_mountpt}"
fi fi
} }
@ -108,8 +118,11 @@ function mount_image() {
sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \
"${FLAGS_rootfs_mountpt}/usr/local" "${FLAGS_rootfs_mountpt}/usr/local"
# Setup symlinks in /usr/local so you can emerge packages into /usr/local. # Setup symlinks in /usr/local so you can emerge packages into /usr/local.
if [ ${FLAGS_read_only} -eq ${FLAGS_FALSE} ]; then
setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
"${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
fi
echo "Image specified by ${FLAGS_from} mounted at"\ echo "Image specified by ${FLAGS_from} mounted at"\
"${FLAGS_rootfs_mountpt} successfully." "${FLAGS_rootfs_mountpt} successfully."
} }