From 729f9da8729df04fc4a20898c7b794047b97daed Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 3 Dec 2014 13:33:50 -0800 Subject: [PATCH] common: make sure /etc/mtab is correct before mounting anything If mtab ever gets replaced by a regular file all sorts of things break. --- build_image | 2 ++ common.sh | 7 +++++++ image_to_vm.sh | 2 ++ sdk_lib/enter_chroot.sh | 2 ++ 4 files changed, 13 insertions(+) diff --git a/build_image b/build_image index e5891f9ed2..a64261d11a 100755 --- a/build_image +++ b/build_image @@ -149,6 +149,8 @@ users: EOF fi +fix_mtab + if [[ "${DEV_IMAGE}" -eq 1 ]]; then create_dev_image ${COREOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group} if [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then diff --git a/common.sh b/common.sh index 2550069620..573b309a95 100644 --- a/common.sh +++ b/common.sh @@ -601,6 +601,13 @@ is_mounted() { fi } +fix_mtab() { + local root="$1" mounts="../proc/self/mounts" + if [[ "$(readlink "${root}/etc/mtab")" != "${mounts}" ]]; then + sudo ln -sf "${mounts}" "${root}/etc/mtab" + fi +} + get_git_id() { git var GIT_COMMITTER_IDENT | sed -e 's/^.*<\(\S\+\)>.*$/\1/' } diff --git a/image_to_vm.sh b/image_to_vm.sh index 162aded577..cb8341f6fd 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -103,6 +103,8 @@ fi # Make sure things are cleaned up on failure trap vm_cleanup EXIT +fix_mtab + # Setup new (raw) image, possibly resizing filesystems setup_disk_image "${FLAGS_disk_layout}" diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index a31855cc67..036d6d3255 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -209,6 +209,8 @@ setup_env() { fi done + fix_mtab "${FLAGS_chroot}" + debug "Mounting chroot environment." MOUNT_CACHE=$(echo $(awk '{print $2}' /proc/mounts))