set_lsb_release.sh: Make it mount rootfs r/w only if necessary.

If we just want to read the current lsb-release, we shouldn't need to break rootfs verification.

Change-Id: I5ba6ddbd9f5801783a568b6806392184b683f628

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/3563001
diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh
index 37834dc..c4824c6 100755
--- a/scripts/image_signing/common.sh
+++ b/scripts/image_signing/common.sh
@@ -27,6 +27,16 @@
   sudo $GPT show -s -i $2 $1
 }
 
+# Mount a partition read-only from an image into a local directory
+# Args: IMAGE PARTNUM MOUNTDIRECTORY
+mount_image_partition_ro() {
+  local image=$1
+  local partnum=$2
+  local mount_dir=$3
+  local offset=$(partoffset "$image" "$partnum")
+  sudo mount -o loop,ro,offset=$((offset * 512)) "$image" "$mount_dir"
+}
+
 # Mount a partition from an image into a local directory
 # Args: IMAGE PARTNUM MOUNTDIRECTORY
 mount_image_partition() {
diff --git a/scripts/image_signing/set_lsb_release.sh b/scripts/image_signing/set_lsb_release.sh
index 3696bd2..9af0047 100755
--- a/scripts/image_signing/set_lsb_release.sh
+++ b/scripts/image_signing/set_lsb_release.sh
@@ -48,9 +48,11 @@
   fi
 
   local rootfs=$(mktemp -d)
-  mount_image_partition "$image" 3 "$rootfs"
+  mount_image_partition_ro "$image" 3 "$rootfs"
   trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT
   if [ -n "$key" ]; then
+    sudo umount -d "$rootfs"
+    mount_image_partition "$image" 3 "$rootfs"
     set_lsb_release_keyval "$rootfs" "$key" "$value"
     touch "$image"  # Updates the image modification time.
   fi