common: make sure /etc/mtab is correct before mounting anything

If mtab ever gets replaced by a regular file all sorts of things break.
This commit is contained in:
Michael Marineau 2014-12-03 13:33:50 -08:00
parent bfd3747f60
commit 729f9da872
4 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -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/'
}

View File

@ -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}"

View File

@ -209,6 +209,8 @@ setup_env() {
fi
done
fix_mtab "${FLAGS_chroot}"
debug "Mounting chroot environment."
MOUNT_CACHE=$(echo $(awk '{print $2}' /proc/mounts))