# Mount and umount first to let the kernel handle
# the journal and orphaned inodes (much faster than e2fsck).
mount -o errors=remount-ro "$path" "$writable_mnt" || true
umount "$writable_mnt" || true
# Automatically fix errors
/sbin/e2fsck -va "$path" >> "$logfile" 2>&1 || true
echo "$(date '+%s'): end" >> "$logfile" || true
echo "initrd: mounting $writable_label partition" >/dev/kmsg || true
mount "$path" "$writable_mnt"
mkdir -p "${rootmnt}/writable"
mount --move "$writable_mnt" "${rootmnt}/writable"
# Prepare the fstab
fstab="${rootmnt}/etc/fstab"
writable_paths="${rootmnt}/etc/system-image/writable-paths"
# Add writable overlays
if [ -e "$writable_paths" ]; then
touch "${rootmnt}/run/image.fstab"
mount -o bind "${rootmnt}/run/image.fstab" "$fstab" || panic "Cannot bind mount fstab"
echo "# Auto-generated by $0" >> "$fstab"
echo "# DO NOT EDIT THIS FILE BY HAND - YOUR CHANGES WILL BE OVERWRITTEN" >> "$fstab"
echo "# (See writable-paths(5) for details)" >> "$fstab"
echo "/dev/root / rootfs defaults,ro 0 0" >> "$fstab"
handle_writable_paths "$writable_paths" "$fstab"
fi