9 addimage_directory="${3}"
12 aufs|unionfs|overlayfs)
13 modprobe -q -b ${UNIONTYPE}
15 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
17 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
18 echo "This might be really slow."
20 UNIONTYPE="unionfs-fuse"
25 if [ "${UNIONTYPE}" = unionfs-fuse ]
30 # run-init can't deal with images in a subdir, but we're going to
31 # move all of these away before it runs anyway. No, we're not,
32 # put them in / since move-mounting them into / breaks mono and
37 # Let's just mount the read-only file systems first
40 if [ -z "${PLAIN_ROOT}" ]
42 # Read image names from ${MODULE}.module if it exists
43 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
45 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
47 image_string="${image_string} ${image_directory}/${IMAGE}"
49 elif [ -e "${image_directory}/${MODULE}.module" ]
51 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
53 image_string="${image_string} ${image_directory}/${IMAGE}"
56 # ${MODULE}.module does not exist, create a list of images
57 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
59 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
63 image_string="${image_string} ${IMAGE}"
68 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
70 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
72 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
76 image_string="${image_string} ${IMAGE}"
83 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
86 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
90 for image in ${image_string}
92 imagename=$(basename "${image}")
95 maybe_break live-realpremount
96 log_begin_msg "Running /scripts/live-realpremount"
97 run_scripts /scripts/live-realpremount
102 # it is a plain directory: do nothing
103 rofslist="${image} ${rofslist}"
104 elif [ -f "${image}" ]
106 if losetup --help 2>&1 | grep -q -- "-r\b"
108 backdev=$(get_backing_device "${image}" "-r")
110 backdev=$(get_backing_device "${image}")
112 fstype=$(get_fstype "${backdev}")
114 if [ "${fstype}" = "unknown" ]
116 panic "Unknown file system type on ${backdev} (${image})"
119 if [ -z "${fstype}" ]
121 fstype="${imagename##*.}"
122 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
125 if [ "${UNIONTYPE}" != "unionmount" ]
127 mpoint="${croot}/${imagename}"
128 rofslist="${mpoint} ${rofslist}"
131 rofslist="${rootmnt} ${rofslist}"
134 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
135 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
140 # we have a plain root system
141 mkdir -p "${croot}/filesystem"
142 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
143 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
144 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
145 rofslist="${croot}/filesystem ${rofslist}"
147 mount -o bind ${croot}/filesystem $mountpoint
154 mount -t tmpfs tmpfs /live
155 mkdir -p /live/overlay
157 # Looking for persistence devices or files
158 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
161 if [ -z "${QUICKUSBMODULES}" ]
164 num_block=$(ls -l /sys/block | wc -l)
165 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
167 modprobe -q -b ${module}
173 # For some reason, udevsettle does not block in this scenario,
174 # so we sleep for a little while.
176 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
177 for timeout in 5 4 3 2 1
181 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
188 case "${PERSISTENCE_MEDIA}" in
190 whitelistdev="$(removable_dev)"
193 whitelistdev="$(removable_usb_dev)"
200 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
202 overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
205 local overlay_devices=""
206 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
208 media="$(echo ${media} | tr ":" " ")"
210 ${old_root_overlay_label}=*)
212 fix_backwards_compatibility ${device} / union
213 overlay_devices="${overlay_devices} ${device}"
215 ${old_home_overlay_label}=*)
217 fix_backwards_compatibility ${device} /home bind
218 overlay_devices="${overlay_devices} ${device}"
220 ${custom_overlay_label}=*)
222 overlay_devices="${overlay_devices} ${device}"
226 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
228 # check if there are any nfs options
229 if echo ${NFS_COW}|grep -q ','
231 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
232 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
234 nfs_cow_opts="-o nolock"
238 if [ -n "${PERSISTENCE_READONLY}" ]
240 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
246 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
249 panic "unable to determine mac address"
253 if [ -z "${cowdevice}" ]
257 cow_mountopt="rw,noatime,mode=755"
260 if [ "${UNIONTYPE}" != "unionmount" ]
262 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
264 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
265 root_backing="/live/persistence/$(basename ${cowdevice})-root"
266 mkdir -p ${root_backing}
268 root_backing="/live/overlay"
271 if [ "${cow_fstype}" = "nfs" ]
274 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
275 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
276 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
278 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
279 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
283 rofscount=$(echo ${rofslist} |wc -w)
287 if [ -n "${EXPOSED_ROOT}" ]
289 if [ ${rofscount} -ne 1 ]
291 panic "only one RO file system supported with exposedroot: ${rofslist}"
294 mount --bind ${rofs} ${rootmnt} || \
295 panic "bind mount of ${rofs} failed"
297 if [ -z "${SKIP_UNION_MOUNTS}" ]
299 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
307 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
309 true # FIXME: Maybe it does, I don't really know.
310 #panic "unionmount does not support subunions (${cow_dirs})."
313 for dir in ${cow_dirs}; do
314 unionmountpoint="${rootmnt}${dir}"
315 mkdir -p ${unionmountpoint}
316 if [ "${UNIONTYPE}" = "unionmount" ]
318 # FIXME: handle PERSISTENCE_READONLY
319 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
320 mount_full $unionmountopts "${unionmountpoint}"
322 cow_dir="/live/overlay${dir}"
323 rofs_dir="${rofs}${dir}"
325 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
327 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
329 do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
331 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
334 # Correct the permissions of /:
335 chmod 0755 "${rootmnt}"
338 # SHOWMOUNTS is necessary for custom mounts with the union option
339 # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
340 if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1)
342 # 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).
345 live_rofs="/live/rofs/${d##*/}"
346 live_rofs_list="${live_rofs_list} ${live_rofs}"
347 mkdir -p "${live_rofs}"
350 # do nothing # mount -o bind "${d}" "${live_rofs}"
353 case "${UNIONTYPE}" in
355 mount -o bind "${d}" "${live_rofs}"
358 mount -o move "${d}" "${live_rofs}"
366 # Adding custom persistence
367 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
369 local custom_mounts="/tmp/custom_mounts.list"
370 rm -rf ${custom_mounts} 2> /dev/null
372 # Gather information about custom mounts from devies detected as overlays
373 get_custom_mounts ${custom_mounts} ${overlay_devices}
375 [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence"
377 # Now we do the actual mounting (and symlinking)
378 local used_overlays=""
379 used_overlays=$(activate_custom_mounts ${custom_mounts})
382 # Close unused overlays (e.g. due to missing $persistence_list)
383 for overlay in ${overlay_devices}
385 if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
387 close_persistence_media ${overlay}
392 mkdir -p "${rootmnt}/live"
393 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"
395 # shows cow fs on /overlay (FIXME: do we still need/want this? probably yes)
396 mkdir -p "${rootmnt}/live/overlay"
397 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"