# 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
# Request bootloader partition be mounted
boot_partition=$(findfs LABEL="system-boot" 2>/dev/null || :)
if [ -n "$boot_partition" ]; then
# determine bootloader type
grubdir="/boot/grub"
ubootdir="/boot/uboot"
# Since the boot partition is not required to actually boot
# the image, request the init system handle it (fsck+mount).
if [ -d "${rootmnt}/${grubdir}" ] && [ -e "${rootmnt}/usr/sbin/grub-install" ]; then
bootdir="$grubdir"
efidir="/boot/efi"
efibinddir="${efidir}/EFI/ubuntu/grub"
if [ -d "${rootmnt}/${efidir}" ]; then
echo "$boot_partition $efidir auto sync 0 2" >> "$fstab"
echo "$efibinddir $bootdir none bind 0 0" >> "$fstab"
fi
else
bootdir="$ubootdir"
echo "$boot_partition $bootdir auto sync 0 2" >> "$fstab"
fi
fi