From 04c4f736f56932dd503d4be6567b5fda3510e141 Mon Sep 17 00:00:00 2001 From: Michael Krebs Date: Fri, 7 Sep 2012 18:31:46 -0700 Subject: [PATCH] cros_sdk: Allow additional chroot mounts via .local_mounts file This change was coopted from http://codereview.chromium.org/5331009/, originally written by hungte@. And the coopted commit message: It would be helpful if we could share some directories inside/outside the chroot (e.g. editor configuration or the default Downloads directory). This CL reads .local_mounts (just like .default_boards) from the "src/scripts" folder, and mounts the directories whenever you do cros_sdk. For safety concern, and to prevent the developer from accidentally deleting their mounted files, the mounts are made read-only. .local_mounts has a very simple syntax: mount_path or source_path(outside chroot) destination_path(inside chroot) or # comments. Examples: /usr/share/vim/google /home/XXX/Downloads /outside BUG=chromium-os:34561 TEST=Manually: 1. Create ~/trunk/src/scripts/.local_mounts with following content: # comment here /usr/share/vim/google # test /home/XXX/Downloads /outside 2. cros_sdk 3. ls -l /usr/share/vim/google/ # ensure dir is mounted correctly ls -l /outside/ # ensure dir is mounted correctly 4. exit 5. mount | grep chroot # ensure nothing is left Change-Id: I6f3400a436a825e8cdfcb18b788afe96ebba6757 Reviewed-on: https://gerrit.chromium.org/gerrit/33585 Tested-by: Michael Krebs Reviewed-by: Mike Frysinger Commit-Ready: Michael Krebs --- .gitignore | 1 + sdk_lib/enter_chroot.sh | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index af5de19c11..cf694dcf24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # User files /.chromeos_dev /.default_board +/.local_mounts /shared_user_passwd.txt # Generated files diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 619529d2ab..bed09a01d8 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -123,11 +123,13 @@ queue_mount() { # Already mounted! ;; *) - MOUNT_QUEUE+=( - "mkdir -p '${mounted_path}'" - # The args are left unquoted on purpose. - "mount ${mount_args} '${source}' '${mounted_path}'" - ) + MOUNT_QUEUE+=( "mkdir -p '${mounted_path}'" ) + # The args are left unquoted on purpose. + if [[ -n ${source} ]]; then + MOUNT_QUEUE+=( "mount ${mount_args} '${source}' '${mounted_path}'" ) + else + MOUNT_QUEUE+=( "mount ${mount_args} '${mounted_path}'" ) + fi ;; esac } @@ -390,6 +392,27 @@ setup_env() { queue_mount "$DEPOT_TOOLS" --bind "$INNER_DEPOT_TOOLS_ROOT" fi + # Mount additional directories as specified in .local_mounts file. + local local_mounts="${FLAGS_trunk}/src/scripts/.local_mounts" + if [[ -f ${local_mounts} ]]; then + info "Mounting local folders (read-only for safety concern)" + # format: mount_source + # or mount_source mount_point + # or # comments + local mount_source mount_point + while read mount_source mount_point; do + if [[ -z ${mount_source} ]]; then + continue + fi + # if only source is assigned, use source as mount point. + : ${mount_point:=${mount_source}} + debug " mounting ${mount_source} on ${mount_point}" + queue_mount "${mount_source}" "--bind" "${mount_point}" + # --bind can't initially be read-only so we have to do it via remount. + queue_mount "" "-o remount,ro" "${mount_point}" + done < <(sed -e 's:#.*::' "${local_mounts}") + fi + process_mounts CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root" || :)"