Commit e2510438 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Mount all local filesystems when deploying images

If the image has /home on a different partition than /, then
we'll need to have it mounted to inject files on a user's home
parent 0e707fe3
......@@ -369,6 +369,18 @@ get_unattend() {
echo "$exists"
umount_all() {
local target mpoints
# Unmount file systems mounted under directory `target'
mpoints="$({ awk "{ if (match(\$2, \"^$target\")) { print \$2 } }" < /proc/mounts; } | sort -rbd | uniq)"
for mpoint in $mpoints; do
umount $mpoint
cleanup() {
# if something fails here, it shouldn't call cleanup again...
trap - EXIT
......@@ -110,18 +110,19 @@ if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
log_error "Supported values for OSFAMILY property are: linux|windows"
# If something goes wrong with the tasks, try to umount the target
# file system in case it is left mounted...
trap '{ umount "$target"; }' ERR
# If something goes wrong with the tasks, try to umount the disk file
# systems that are still mounted.
trap '{ umount_all "$target"; }' ERR
# Redirect standard error to standard output,
# prepend a timestamp before each line of output.
echo "Execute all snf-image tasks...."
$RUN_PARTS -v --exit-on-error "@tasksdir@" 2>&1|
while IFS= read -r line; do
while read -r line; do
echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
# Reset the handler to its original value
trap report_error ERR
......@@ -47,6 +47,36 @@ fi
mount "$rootdev" "$SNF_IMAGE_TARGET" -o rw
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
exit 0
if [ ! -f "${SNF_IMAGE_TARGET}/etc/fstab" ]; then
log_error "/etc/fstab is missing from the root file system"
# Read the local partitions from fstab and get a sorted list:
#<mount_point> <device> <options>
fstab="$(grep -v ^\# "${SNF_IMAGE_TARGET}/etc/fstab" | awk '{ if (match($3, "ext[234]")) { print $2,$1,$4 } }' | sort -bd)"
# Mount non-root filesystems
while read line; do
read -ra entry <<< "$line"
# Skip root. It is already mounted
if [ "${entry[0]}" = "/" ]; then
if [[ ${entry[1]} =~ ^(LABEL|UUID)= ]]; then
entry[1]=$(findfs "${entry[1]}")
# I'm in doupt. Sould I mount the filesystems with the mount options
# found in the image's /etc/fstab or not?
mount "${entry[1]}" "${SNF_IMAGE_TARGET}${entry[0]}" # -o "${entry[2]}"
done <<< "$fstab"
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -31,10 +31,19 @@ trap task_cleanup EXIT
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
umount_all "$SNF_IMAGE_TARGET"
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
# Sleep for a second after umounting windows file systems just to be on
# the safe side. The ntfs driver is over fuse and umount with fuse is not
# synchronous. Since the helper VM gets killed using a sysrq call, there
# is a 0.0000000001% posibility that the altered data are not written back
# to the disk when the OS dies, unless you wait a little bit.
sleep 1
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment