- if [ -n "${opt_linkfiles}" ]
- then
- links_source="${source}"
- links_dest="${dest}"
- elif [ -n "${opt_union}" ]
- then
- do_union ${dest} ${source} ${rofs_dest_backing}
- else
- mount --bind "${source}" "${dest}"
- fi
- else
- if [ -n "${opt_linkfiles}" ]
- then
- links_dest="${dest}"
- dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
- links_source="${dest}"
- fi
+ link_files ${source} ${dest} ${rootmnt}
+ elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ mkdir -p /live/persistence
+ local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
+ chown_ref ${source} ${links_source}
+ chmod_ref ${source} ${links_source}
+ # We put the cow dir in the below strange place to
+ # make it absolutely certain that the link source
+ # has its own directory and isn't nested with some
+ # other custom mount (if so that mount's files would
+ # be linked, causing breakage.
+ local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
+ mkdir -p ${cow_dir}
+ chown_ref "${source}" "${cow_dir}"
+ chmod_ref "${source}" "${cow_dir}"
+ do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing}
+ link_files ${links_source} ${dest} ${rootmnt}
+ elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
+ then
+ do_union ${dest} ${source} ${rofs_dest_backing}
+ elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
+ then
+ mount --bind "${source}" "${dest}"
+ elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ # bind-mount and union mount are handled the same
+ # in read-only mode, but note that rofs_dest_backing
+ # is non-empty (and necessary) only for unions