7 addimage_directory="${3}"
10 aufs|unionfs|overlayfs)
11 modprobe -q -b ${UNIONTYPE}
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
15 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
16 echo "This might be really slow."
18 UNIONTYPE="unionfs-fuse"
23 if [ "${UNIONTYPE}" = unionfs-fuse ]
28 # run-init can't deal with images in a subdir, but we're going to
29 # move all of these away before it runs anyway. No, we're not,
30 # put them in / since move-mounting them into / breaks mono and
35 # Let's just mount the read-only file systems first
38 if [ -z "${PLAIN_ROOT}" ]
40 # Read image names from ${MODULE}.module if it exists
41 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
43 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
45 image_string="${image_string} ${image_directory}/${IMAGE}"
47 elif [ -e "${image_directory}/${MODULE}.module" ]
49 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
51 image_string="${image_string} ${image_directory}/${IMAGE}"
54 # ${MODULE}.module does not exist, create a list of images
55 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
57 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
61 image_string="${image_string} ${IMAGE}"
66 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
68 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
70 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
74 image_string="${image_string} ${IMAGE}"
81 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
84 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
88 for image in ${image_string}
90 imagename=$(basename "${image}")
93 maybe_break live-realpremount
94 log_begin_msg "Running /scripts/live-realpremount"
95 run_scripts /scripts/live-realpremount
100 # it is a plain directory: do nothing
101 rofslist="${image} ${rofslist}"
102 elif [ -f "${image}" ]
104 if losetup --help 2>&1 | grep -q -- "-r\b"
106 backdev=$(get_backing_device "${image}" "-r")
108 backdev=$(get_backing_device "${image}")
110 fstype=$(get_fstype "${backdev}")
112 if [ "${fstype}" = "unknown" ]
114 panic "Unknown file system type on ${backdev} (${image})"
117 if [ -z "${fstype}" ]
119 fstype="${imagename##*.}"
120 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
123 if [ "${UNIONTYPE}" != "unionmount" ]
125 mpoint="${croot}/${imagename}"
126 rofslist="${mpoint} ${rofslist}"
129 rofslist="${rootmnt} ${rofslist}"
132 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
133 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
138 # we have a plain root system
139 mkdir -p "${croot}/filesystem"
140 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
141 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
142 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
143 rofslist="${croot}/filesystem ${rofslist}"
145 mount -o bind ${croot}/filesystem $mountpoint
152 mount -t tmpfs tmpfs /live
153 mkdir -p /live/overlay
155 # Looking for persistence devices or files
156 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
159 if [ -z "${QUICKUSBMODULES}" ]
162 num_block=$(ls -l /sys/block | wc -l)
163 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
165 modprobe -q -b ${module}
171 # For some reason, udevsettle does not block in this scenario,
172 # so we sleep for a little while.
174 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
175 for timeout in 5 4 3 2 1
179 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
186 case "${PERSISTENCE_MEDIA}" in
188 whitelistdev="$(removable_dev)"
191 whitelistdev="$(removable_usb_dev)"
198 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
200 overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
203 if is_in_comma_sep_list snapshot ${PERSISTENCE_METHOD}
205 snapshots="${root_snapshot_label} ${home_snapshot_label}"
208 local root_snapdata=""
209 local home_snapdata=""
210 local overlay_devices=""
211 for media in $(find_persistence_media "${overlays}" "${snapshots}" "${whitelistdev}")
213 media="$(echo ${media} | tr ":" " ")"
215 ${root_snapshot_label}=*|${old_root_snapshot_label}=*)
216 if [ -z "${root_snapdata}" ]
218 root_snapdata="${media#*=}"
221 ${home_snapshot_label}=*)
222 # This second type should be removed when snapshot will get smarter,
223 # hence when "/etc/live-snapshot*list" will be supported also by
224 # ext2|ext3|ext4|jffs2 snapshot types.
225 if [ -z "${home_snapdata}" ]
227 home_snapdata="${media#*=}"
230 ${old_root_overlay_label}=*)
232 fix_backwards_compatibility ${device} / union
233 overlay_devices="${overlay_devices} ${device}"
235 ${old_home_overlay_label}=*)
237 fix_backwards_compatibility ${device} /home bind
238 overlay_devices="${overlay_devices} ${device}"
240 ${custom_overlay_label}=*)
242 overlay_devices="${overlay_devices} ${device}"
246 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
248 # check if there are any nfs options
249 if echo ${NFS_COW}|grep -q ','
251 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
252 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
254 nfs_cow_opts="-o nolock"
258 if [ -n "${PERSISTENCE_READONLY}" ]
260 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
266 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
269 panic "unable to determine mac address"
273 if [ -z "${cowdevice}" ]
277 cow_mountopt="rw,noatime,mode=755"
280 if [ "${UNIONTYPE}" != "unionmount" ]
282 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
284 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
285 root_backing="/live/persistence/$(basename ${cowdevice})-root"
286 mkdir -p ${root_backing}
288 root_backing="/live/overlay"
291 if [ "${cow_fstype}" = "nfs" ]
294 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
295 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
296 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
298 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
299 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
303 rofscount=$(echo ${rofslist} |wc -w)
307 if [ -n "${EXPOSED_ROOT}" ]
309 if [ ${rofscount} -ne 1 ]
311 panic "only one RO file system supported with exposedroot: ${rofslist}"
314 mount --bind ${rofs} ${rootmnt} || \
315 panic "bind mount of ${rofs} failed"
317 if [ -z "${SKIP_UNION_MOUNTS}" ]
319 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
327 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
329 true # FIXME: Maybe it does, I don't really know.
330 #panic "unionmount does not support subunions (${cow_dirs})."
333 for dir in ${cow_dirs}; do
334 unionmountpoint="${rootmnt}${dir}"
335 mkdir -p ${unionmountpoint}
336 if [ "${UNIONTYPE}" = "unionmount" ]
338 # FIXME: handle PERSISTENCE_READONLY
339 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
340 mount_full $unionmountopts "${unionmountpoint}"
342 cow_dir="/live/overlay${dir}"
343 rofs_dir="${rofs}${dir}"
345 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
347 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
349 do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
351 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
354 # Correct the permissions of /:
355 chmod 0755 "${rootmnt}"
358 # SHOWMOUNTS is necessary for custom mounts with the union option
359 # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
360 if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1)
362 # XXX: is the for loop really necessary? rofslist can only contain one item (see above XXX about EXPOSEDROOT) and this is also assumed elsewhere above (see use of $rofs above).
365 live_rofs="/live/rofs/${d##*/}"
366 live_rofs_list="${live_rofs_list} ${live_rofs}"
367 mkdir -p "${live_rofs}"
370 # do nothing # mount -o bind "${d}" "${live_rofs}"
373 case "${UNIONTYPE}" in
375 mount -o bind "${d}" "${live_rofs}"
378 mount -o move "${d}" "${live_rofs}"
386 # Adding custom persistence
387 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
389 local custom_mounts="/tmp/custom_mounts.list"
390 rm -rf ${custom_mounts} 2> /dev/null
392 # Gather information about custom mounts from devies detected as overlays
393 get_custom_mounts ${custom_mounts} ${overlay_devices}
395 [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence"
397 # Now we do the actual mounting (and symlinking)
398 local used_overlays=""
399 used_overlays=$(activate_custom_mounts ${custom_mounts})
402 # Close unused overlays (e.g. due to missing $persistence_list)
403 for overlay in ${overlay_devices}
405 if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
407 close_persistence_media ${overlay}
411 # Look for other snapshots to copy in
412 [ -n "${root_snapdata}" ] && try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
413 # This second type should be removed when snapshot grow smarter
414 [ -n "${home_snapdata}" ] && try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
417 mkdir -p "${rootmnt}/live"
418 mount -o move /live "${rootmnt}/live" >/dev/null 2>&1 || mount -o bind /live "${rootmnt}/live" || log_warning_msg "Unable to move or bind /live to ${rootmnt}/live"
420 # shows cow fs on /overlay for use by live-snapshot
421 mkdir -p "${rootmnt}/live/overlay"
422 mount -o move /live/overlay "${rootmnt}/live/overlay" >/dev/null 2>&1 || mount -o bind /overlay "${rootmnt}/live/overlay" || log_warning_msg "Unable to move or bind /overlay to ${rootmnt}/live/overlay"