mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 07:01:13 +02:00
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:
parent
e86529b046
commit
e7f1a2b6bb
@ -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.
|
||||
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.
|
||||
|
||||
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."
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user