Skip to content

Commit

Permalink
Make union mounting more sensible and robust.
Browse files Browse the repository at this point in the history
...except that they're broken! But we're getting to that.
  • Loading branch information
Tails developers authored and daniel-baumann committed Apr 1, 2012
1 parent c86b5d4 commit bae59cf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
30 changes: 18 additions & 12 deletions scripts/live
Expand Up @@ -1485,7 +1485,8 @@ setup_unionfs ()
then
if [ -n "${PERSISTENT_READONLY}" ]
then
root_backing="/${rootmnt}/live/persistent/$(basename ${cowdevice})-root"
mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/cow"
root_backing="${rootmnt}/live/persistent/$(basename ${cowdevice})-root"
mkdir -p ${root_backing}
else
root_backing="/cow"
Expand All @@ -1505,6 +1506,7 @@ setup_unionfs ()

rofscount=$(echo ${rofslist} |wc -w)

# XXX: we now ensure that there can only be one read-only filesystem. Should this be inside the EXPOSED_ROOT if?
if [ ${rofscount} -ne 1 ]
then
panic "only one RO file system supported with exposedroot: ${rofslist}"
Expand Down Expand Up @@ -1532,21 +1534,25 @@ setup_unionfs ()
#panic "unionmount does not support subunions (${cow_dirs})."
fi

unionmountopts=""
unionmountpoint=""

for dir in ${cow_dirs}; do
unionrw="/cow${dir}"
unionro="${rofs}${dir}"
unionmountpoint="${rootmnt}${dir}"
mkdir -p ${unionrw}
mkdir -p ${unionmountpoint}
if [ "${UNIONTYPE}" = "unionmount" ]
then
# FIXME: handle PERSISTENT_READONLY
unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
mount_full $unionmountopts "${unionmountpoint}"
else
do_union ${root_backing} ${unionrw} ${unionro} ${unionmountpoint}
cow_dir="/cow${dir}"
rofs_dir="${rofs}${dir}"
mkdir -p ${cow_dir}
if [ -n "${PERSISTENT_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
then
#mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${cow_dir}"
do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
else
do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
fi
fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
done

Expand Down Expand Up @@ -1743,10 +1749,10 @@ setup_unionfs ()
dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
links_source="${dest}"
fi
unionrw="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
mkdir -p ${unionrw}
unionmountopts="noatime,${noxino_opt}dirs=${unionrw}=rw:${source}=${roopt}"
do_union ${root_backing} ${unionrw} ${source} ${dest}
cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
mkdir -p ${cow_dir}
# XXX: broken! will be fixed in the next few commits...
do_union ${dest} ${cow_dir} ${source}
fi

if [ -n "${opt_linkfiles}" ]
Expand Down
38 changes: 24 additions & 14 deletions scripts/live-helpers
Expand Up @@ -607,16 +607,16 @@ link_files ()
}

do_union () {
root_backing="${1}"
unionrw="${2}"
unionro="${3}"
unionmountpoint="${4}"
local unionmountpoint="${1}" # directory where the union is mounted
local unionrw="${2}" # branch where the union changes are stored
local unionro1="${3}" # first underlying read-only branch (optional)
local unionro2="${4}" # second underlying read-only branch (optional)

if [ "${UNIONTYPE}" = "aufs" ]
then
rw_opt="rw"
ro_opt="rr+wh"
noxino_opt="noxino,"
noxino_opt="noxino"
elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
then
rw_opt="RW"
Expand All @@ -628,28 +628,38 @@ do_union () {

case "${UNIONTYPE}" in
unionfs-fuse)
# FIXME: handle PERSISTENT_READONLY
unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}:${unionro}=${ro_opt}"
unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
if [ -n "${unionro1}" ]
then
unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
fi
if [ -n "${unionro2}" ]
then
unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
fi
( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
( mkdir -p /run/sendsigs.omit.d
pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
;;

overlayfs)
# FIXME: is PERSISTENT_READONLY possible? (overlayfs only handles two dirs, but perhaps they can be chained?)
unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
# XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
# XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
;;

*)
if [ -n "${PERSISTENT_READONLY}" ]
unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
if [ -n "${unionro1}" ]
then
mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${unionrw}"
unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=${rw_opt}:${root_backing}=${ro_opt}:${unionro}=${ro_opt}"
else
unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=${rw_opt}:${unionro}=${ro_opt}"
unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
fi
if [ -n "${unionro2}" ]
then
unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
fi
mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
;;
Expand Down

0 comments on commit bae59cf

Please sign in to comment.