Ubuntu 18 delay before login screen after resume

After upgrading my laptop to Ubuntu 18 (or was it 16?), after a suspend/resume, the lock screen would appear promptly, but there was a delay of about a minute after hitting Enter before the login prompt appeared. This delay was due to CIFS mounts being restored. In prior versions of Ubuntu, the mounts would sometimes be restored and sometimes not, but it didn’t wait for that before the login screen. With Ubuntu 18, it waits for the mounts before the login screen appears.  While it’s nice to be sure the mounts are always restored, the delay is a sub-optimal user experience.  The solution is to use autofs, which only mounts file systems when they are accessed.  Here’s how that is done on my Thinkpad T560 with CIFS (Samba) mounts to a Synology DS411+II.

After installing autofs, unmount the mounts in /etc/fstab that you want to have managed by autofs.  Then edit /etc/fstab and comment them out.  Edit /etc/auto.master and add an entry for each directory that will contain mounts.  For example, to add mounts in /mnt:

/mnt /etc/auto.mnt

Keep in mind the contents of the directory being managed by autofs (/mnt in this example) will not be accessible once autofs makes mounts there.  The directory contents will not be deleted, you just won’t see them again until the mount is removed.

Create the mount configuration for each mounted directory.  In our example above that would be /etc/auto.mnt:

ds411p2-public-music -fstype=cifs,vers=1.0,rw,suid,gid=ds411p2,credentials=/etc/ds411p2pwd ://ds411p2.local/music

The format of this file is similar to /etc/fstab but not the same.  For comparison, here’s that entry as it was in /etc/fstab:

//ds411p2.local/music /mnt/ds411p2-public-music cifs vers=1.0,rw,suid,gid=ds411p2,credentials=/etc/ds411p2pwd 0 0

So to create the entry in /etc/auto.mnt from /etc/fstab:

  • The first field, the mountpoint, is the second field from /etc/fstab, but change it from an absolute path to one relative to the mount directory specified in /etc/auto.master.
  • The second field is a combination of fstab’s third and fourth fields, the file system type and mount options, except file system type is prefixed with -fstype=. The other mount options follow, separated by commas, the same as in fstab.
  • The third field, the server directory, is the same as first field in fstab except it’s prefixed with :.
  • The last two fields from fstab (dump and fsck options) aren’t used.