9 addimage_directory="${3}"
11 modprobe -q -b ${UNIONTYPE}
13 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
15 panic "${UNIONTYPE} not available."
18 # run-init can't deal with images in a subdir, but we're going to
19 # move all of these away before it runs anyway. No, we're not,
20 # put them in / since move-mounting them into / breaks mono and
25 # Let's just mount the read-only file systems first
28 if [ -z "${PLAIN_ROOT}" ]
30 # Read image names from ${MODULE}.module if it exists
31 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
33 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
35 image_string="${image_string} ${image_directory}/${IMAGE}"
37 elif [ -e "${image_directory}/${MODULE}.module" ]
39 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
41 image_string="${image_string} ${image_directory}/${IMAGE}"
44 # ${MODULE}.module does not exist, create a list of images
45 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
47 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
51 image_string="${image_string} ${IMAGE}"
56 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
58 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
60 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
64 image_string="${image_string} ${IMAGE}"
71 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
74 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
78 for image in ${image_string}
80 imagename=$(basename "${image}")
83 maybe_break live-realpremount
84 log_begin_msg "Running /scripts/live-realpremount"
85 run_scripts /scripts/live-realpremount
90 # it is a plain directory: do nothing
91 rootfslist="${image} ${rootfslist}"
92 elif [ -f "${image}" ]
94 if losetup --help 2>&1 | grep -q -- "-r\b"
96 backdev=$(get_backing_device "${image}" "-r")
98 backdev=$(get_backing_device "${image}")
100 fstype=$(get_fstype "${backdev}")
104 panic "Unknown file system type on ${backdev} (${image})"
108 fstype="${imagename##*.}"
109 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
113 mpoint="${croot}/${imagename}"
114 rootfslist="${mpoint} ${rootfslist}"
117 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
118 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
121 log_warning_msg "Could not find image '${image}'. Most likely it is listed in a .module file, perhaps by mistake."
125 # we have a plain root system
126 mkdir -p "${croot}/filesystem"
127 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
128 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
129 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
130 rootfslist="${croot}/filesystem ${rootfslist}"
132 mount -o bind ${croot}/filesystem $mountpoint
138 mkdir -p /live/overlay
139 mount -t tmpfs tmpfs /live/overlay
141 # Looking for persistence devices or files
142 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
145 if [ -z "${QUICKUSBMODULES}" ]
148 num_block=$(ls -l /sys/block | wc -l)
149 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
151 modprobe -q -b ${module}
157 # For some reason, udevsettle does not block in this scenario,
158 # so we sleep for a little while.
160 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
161 for timeout in 5 4 3 2 1
165 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
174 if [ -n "${PERSISTENCE_MEDIA}" ]
176 case "${PERSISTENCE_MEDIA}" in
178 whitelistdev="$(removable_dev)"
182 whitelistdev="$(removable_usb_dev)"
185 if [ -z "${whitelistdev}" ]
187 whitelistdev="ignore_all_devices"
191 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
193 overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label} ${old_custom_overlay_label}"
196 local overlay_devices
198 if [ "${whitelistdev}" != "ignore_all_devices" ]
200 for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
202 media="$(echo ${media} | tr ":" " ")"
205 ${old_root_overlay_label}=*)
207 fix_backwards_compatibility ${device} / union
208 overlay_devices="${overlay_devices} ${device}"
211 ${old_home_overlay_label}=*)
213 fix_backwards_compatibility ${device} /home bind
214 overlay_devices="${overlay_devices} ${device}"
217 ${custom_overlay_label}=*)
219 overlay_devices="${overlay_devices} ${device}"
222 ${old_custom_overlay_label}=*)
224 overlay_devices="${overlay_devices} ${device}"
229 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
231 # check if there are any nfs options
232 if echo ${NFS_COW} | grep -q ','
234 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
235 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
237 nfs_cow_opts="-o nolock"
241 if [ -n "${PERSISTENCE_READONLY}" ]
243 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
249 cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/")
252 panic "unable to determine mac address"
256 if [ -z "${cowdevice}" ]
260 cow_mountopt="rw,noatime,mode=755"
263 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
265 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
266 root_backing="/live/persistence/$(basename ${cowdevice})-root"
267 mkdir -p ${root_backing}
269 root_backing="/live/overlay"
272 if [ "${cow_fstype}" = "nfs" ]
275 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
276 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
277 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
279 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
280 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
283 rootfscount=$(echo ${rootfslist} |wc -w)
285 rootfs=${rootfslist%% }
287 if [ -n "${EXPOSED_ROOT}" ]
289 if [ ${rootfscount} -ne 1 ]
291 panic "only one RO file system supported with exposedroot: ${rootfslist}"
294 mount --bind ${rootfs} ${rootmnt} || \
295 panic "bind mount of ${rootfs} 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 for dir in ${cow_dirs}; do
308 unionmountpoint="${rootmnt}${dir}"
309 mkdir -p ${unionmountpoint}
310 cow_dir="/live/overlay${dir}"
311 rootfs_dir="${rootfs}${dir}"
313 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
315 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
317 do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
318 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
321 # Remove persistence depending on boot parameter
324 # Correct the permissions of /:
325 chmod 0755 "${rootmnt}"
327 # Correct the permission of /tmp:
328 if [ -d "${rootmnt}/tmp" ]
330 chmod 1777 "${rootmnt}"/tmp
334 for d in ${rootfslist}
336 live_rootfs="/live/rootfs/${d##*/}"
337 live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
338 mkdir -p "${live_rootfs}"
341 # do nothing # mount -o bind "${d}" "${live_rootfs}"
344 mount -o move "${d}" "${live_rootfs}"
349 # Adding custom persistence
350 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
353 custom_mounts="/tmp/custom_mounts.list"
354 rm -f ${custom_mounts}
356 # Gather information about custom mounts from devies detected as overlays
357 get_custom_mounts ${custom_mounts} ${overlay_devices}
359 [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
361 # Now we do the actual mounting (and symlinking)
364 used_overlays=$(activate_custom_mounts ${custom_mounts})
365 rm -f ${custom_mounts}
367 # Close unused overlays (e.g. due to missing $persistence_list)
368 for overlay in ${overlay_devices}
370 if echo ${used_overlays} | grep -qve "^\(.* \)\?${overlay}\( .*\)\?$"
372 close_persistence_media ${overlay}
377 # ensure that a potentially stray tmpfs gets removed
378 # otherways, initramfs-tools is unable to remove /live
380 umount /live/overlay > /dev/null 2>&1 || true