9 addimage_directory="${3}"
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
15 panic "${UNIONTYPE} not available."
18 modprobe -q -b ${UNIONTYPE}
22 # run-init can't deal with images in a subdir, but we're going to
23 # move all of these away before it runs anyway. No, we're not,
24 # put them in / since move-mounting them into / breaks mono and
29 # Let's just mount the read-only file systems first
32 if [ -z "${PLAIN_ROOT}" ]
34 # Read image names from ${MODULE}.module if it exists
35 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
37 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
39 image_string="${image_string} ${image_directory}/${IMAGE}"
41 elif [ -e "${image_directory}/${MODULE}.module" ]
43 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
45 image_string="${image_string} ${image_directory}/${IMAGE}"
48 # ${MODULE}.module does not exist, create a list of images
49 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
51 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
55 image_string="${image_string} ${IMAGE}"
60 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
62 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
64 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
68 image_string="${image_string} ${IMAGE}"
75 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
78 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
82 for image in ${image_string}
84 imagename=$(basename "${image}")
87 maybe_break live-realpremount
88 log_begin_msg "Running /scripts/live-realpremount"
89 run_scripts /scripts/live-realpremount
94 # it is a plain directory: do nothing
95 rootfslist="${image} ${rootfslist}"
96 elif [ -f "${image}" ]
98 if losetup --help 2>&1 | grep -q -- "-r\b"
100 backdev=$(get_backing_device "${image}" "-r")
102 backdev=$(get_backing_device "${image}")
104 fstype=$(get_fstype "${backdev}")
108 panic "Unknown file system type on ${backdev} (${image})"
112 fstype="${imagename##*.}"
113 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
117 mpoint="${croot}/${imagename}"
118 rootfslist="${mpoint} ${rootfslist}"
121 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
122 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
127 # we have a plain root system
128 mkdir -p "${croot}/filesystem"
129 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
130 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
131 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
132 rootfslist="${croot}/filesystem ${rootfslist}"
134 mount -o bind ${croot}/filesystem $mountpoint
140 mkdir -p /live/overlay
141 mount -t tmpfs tmpfs /live/overlay
143 # Looking for persistence devices or files
144 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
147 if [ -z "${QUICKUSBMODULES}" ]
150 num_block=$(ls -l /sys/block | wc -l)
151 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
153 modprobe -q -b ${module}
159 # For some reason, udevsettle does not block in this scenario,
160 # so we sleep for a little while.
162 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
163 for timeout in 5 4 3 2 1
167 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
176 if [ -n "${PERSISTENCE_MEDIA}" ]
178 case "${PERSISTENCE_MEDIA}" in
180 whitelistdev="$(removable_dev)"
184 whitelistdev="$(removable_usb_dev)"
187 if [ -z "${whitelistdev}" ]
189 whitelistdev="ignore_all_devices"
193 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
195 overlays="${custom_overlay_label}"
198 local overlay_devices
200 if [ "${whitelistdev}" != "ignore_all_devices" ]
202 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
204 media="$(echo ${media} | tr ":" " ")"
207 ${custom_overlay_label}=*)
209 overlay_devices="${overlay_devices} ${device}"
214 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
216 # check if there are any nfs options
217 if echo ${NFS_COW} | grep -q ','
219 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
220 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
222 nfs_cow_opts="-o nolock"
226 if [ -n "${PERSISTENCE_READONLY}" ]
228 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
234 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
237 panic "unable to determine mac address"
241 if [ -z "${cowdevice}" ]
245 cow_mountopt="rw,noatime,mode=755"
248 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
250 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
251 root_backing="/live/persistence/$(basename ${cowdevice})-root"
252 mkdir -p ${root_backing}
254 root_backing="/live/overlay"
257 if [ "${cow_fstype}" = "nfs" ]
260 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
261 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
262 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
264 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
265 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
268 rootfscount=$(echo ${rootfslist} |wc -w)
270 rootfs=${rootfslist%% }
272 if [ -n "${EXPOSED_ROOT}" ]
274 if [ ${rootfscount} -ne 1 ]
276 panic "only one RO file system supported with exposedroot: ${rootfslist}"
279 mount --bind ${rootfs} ${rootmnt} || \
280 panic "bind mount of ${rootfs} failed"
282 if [ -z "${SKIP_UNION_MOUNTS}" ]
284 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
292 for dir in ${cow_dirs}; do
293 unionmountpoint="${rootmnt}${dir}"
294 mkdir -p ${unionmountpoint}
295 cow_dir="/live/overlay${dir}"
296 rootfs_dir="${rootfs}${dir}"
298 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
300 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
302 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
303 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
306 # Correct the permissions of /:
307 chmod 0755 "${rootmnt}"
309 # Correct the permission of /tmp:
310 if [ -d "${rootmnt}/tmp" ]
312 chmod 1777 "${rootmnt}"/tmp
316 for d in ${rootfslist}
318 live_rootfs="/live/rootfs/${d##*/}"
319 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
320 mkdir -p "${live_rootfs}"
323 # do nothing # mount -o bind "${d}" "${live_rootfs}"
326 mount -o move "${d}" "${live_rootfs}"
331 # Adding custom persistence
332 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
335 custom_mounts="/tmp/custom_mounts.list"
336 rm -f ${custom_mounts}
338 # Gather information about custom mounts from devies detected as overlays
339 get_custom_mounts ${custom_mounts} ${overlay_devices}
341 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
343 # Now we do the actual mounting (and symlinking)
346 used_overlays=$(activate_custom_mounts ${custom_mounts})
347 rm -f ${custom_mounts}
349 # Close unused overlays (e.g. due to missing $persistence_list)
350 for overlay in ${overlay_devices}
352 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
354 close_persistence_media ${overlay}
359 # ensure that a potentially stray tmpfs gets removed
360 # otherways, initramfs-tools is unable to remove /live
362 umount /live/overlay > /dev/null 2>&1 || true