function spawn_mounts() {
  FSTAB_CONTENT=$1
  # This method creates a custom 'fstab' file without modifying the system-wide one, and mounts all Mountpoints generated by it
  # At exit, clean up and unmount.

  PROJECT_ROOT=$(dirname "$(which "$0")")/../../..
  OUTPUT_DIR="$PROJECT_ROOT/out"
  SYSTEMD_MOUNT_DIR=/etc/systemd/system/
  UNIT_SOURCE_DIR=$OUTPUT_DIR/normal

  # systemd-fstab-generator takes 3 arguments, which are paths to put results in
  # It only actually puts anything in the first directory, but it appears standard to call these normal, early, and late.
  rm -rf "$OUTPUT_DIR"
  mkdir -p "$OUTPUT_DIR"/{normal,early,late}

  # systemd-fstab-generator takes two environment variables as input: 'SYSTEMD_FSTAB' and 'SYSTEMD_PROC_CMDLINE'
  # SYSTEMD_FSTAB is the path to the fstab file to use, if we don't want to use the system-wide one
  # SYSTEMD_PROC_CMDLINE is an alternative to the kernal's command line arguments.
  # We don't want the state of the kernal arguments to impact our generation, so we mock it out
  export SYSTEMD_FSTAB=$(mktemp)
  echo "$FSTAB_CONTENT" > "$SYSTEMD_FSTAB"
  export SYSTEMD_PROC_CMDLINE=""

  /usr/lib/systemd/system-generators/systemd-fstab-generator "$UNIT_SOURCE_DIR" "$OUTPUT_DIR/early" "$OUTPUT_DIR/late" || true
  # systemd-fstab-generator writes a bunch of .mount files (and other irrelevant files) to $UNIT_SOURCE_DIR.
  # Copy them to the actual systemd directory for unit/mount files.

  for unit in "$UNIT_SOURCE_DIR"/*.mount; do
    unit=$(basename $unit)
    sudo cp "$UNIT_SOURCE_DIR/$unit" "$SYSTEMD_MOUNT_DIR"
    echo -e "\nSystemd unit file $unit:"
    cat "$UNIT_SOURCE_DIR/$unit"

    sudo systemctl daemon-reload

    # Emit logs only if Mountpoint fails to start
    trap "sudo journalctl -u \"$unit\" --since \"$(date '+%Y-%m-%d %H:%M:%S')\" | cat; journalctl -xe" ERR
    sudo systemctl start "$unit"

    echo -e "\nStatus of systemd unit $unit:"
    sudo systemctl status "$unit" | cat
    trap - ERR
  done

  trap cleanup EXIT
}

function cleanup {
  rm "$SYSTEMD_FSTAB"
  for unit in "$UNIT_SOURCE_DIR"/*.mount; do
    sudo journalctl -u "$(basename "$unit")" --since "$(date '+%Y-%m-%d %H:%M:%S')" | cat
    sudo systemctl stop "$(basename "$unit")"
    sudo rm "$unit"
  done
  sudo systemctl daemon-reload
}
