Prevent Lubuntu 17.10 from leaving an external HDD mounted incorrectly for other users

My family’s PC running Lubuntu 17.10 has an external USB HDD connected permanently. There are several user accounts on this machine, i.e. it is a single-seat, multi-user installation. If a user does not unmount this external HDD before logging out, it is still mounted with the privileges of the previous user when another user logs in. If the current user clicks on the media unmount symbol (⏏) in the PCManFM File Manager, LXDE prompts the user to enter the previous user’s password. So I wanted to configure the OS to unmount the external HDD when each user logs out or when another user selects ‘Switch User’. The way I did that was to use the LightDM display manager to unmount the external drive at the end of a session, as explained below. Then the Udisks daemon will mount the drive correctly for any user who either logs in or switches back to his/her session.

Lubuntu 17.10 as installed has an empty directory /etc/lightdm/lightdm.conf.d/ so I created two files in that directory:

$ ls -la /etc/lightdm/lightdm.conf.d/
total 16
drwxr-xr-x 2 root root 4096 Jan  1 06:18 .
drwxr-xr-x 4 root root 4096 Jan  1 05:11 ..
-rw-r--r-- 1 root root   89 Jan  1 06:18 10_lubuntu.conf
-rwxr-xr-x 1 root root   80 Jan  1 05:55
$ cat /etc/lightdm/lightdm.conf.d/10_lubuntu.conf
$ cat /etc/lightdm/lightdm.conf.d/ 
udisksctl unmount --block-device /dev/disk/by-uuid/C6576A087368B015

where ‘C6576A087368B015‘ is the UUID of the external USB HDD as found from the blkid command:

$ sudo blkid | grep "FREECOM HDD"
/dev/sdb1: LABEL="FREECOM HDD" UUID="C6576A087368B015" TYPE="ntfs" PARTUUID="0024db7f-32"

Don’t forget to make the Bash script executable. Then reboot to enable the functionality. From now on the external HDD will be correctly mounted for each user who logs in to his/her account.

Update (Monday, 9 July 2018): Since I wrote the above post I upgraded Lubuntu to 18.04 and I recently noticed the following problems resulting from the above-mentioned modifications:

A. The following error message in the LightDM log file /var/log/lightdm/lightdm.log:

[SeatDefaults] is now called [Seat:*], please update this configuration

So I changed the contents of the file /etc/lightdm/lightdm.conf.d/10_lubuntu.conf from:




B. The following error message in the LightDM log file /var/log/lightdm/lightdm.log when the USB external HDD happened to not be mounted at the time:

DEBUG: Launching process 8569: /etc/lightdm/lightdm.conf.d/
DEBUG: Process 8569 terminated with signal 11

So I changed the contents of my Bash script /etc/lightdm/lightdm.conf.d/ from:

udisksctl unmount --block-device /dev/disk/by-uuid/C6576A087368B015


STATUS=`mount | grep $(readlink -f /dev/disk/by-uuid/C6576A087368B015 )`
if [[ ! -z $STATUS ]]; then
    udisksctl unmount --block-device /dev/disk/by-uuid/C6576A087368B015
exit 0

About Fitzcarraldo
A Linux user with an interest in all things technical.

4 Responses to Prevent Lubuntu 17.10 from leaving an external HDD mounted incorrectly for other users

  1. Pingback: Getting the lock screen to work reliably when resuming from suspension in a single-seat, multi-user Lubuntu 18.04 installation | Fitzcarraldo's Blog

  2. Fitzcarraldo says:

    I ended up changing /etc/lightdm/lightdm.conf.d/ as shown below because I found that the USB HDD’s UUID changes if I unplug the USB HDD and plug it back in again, whereas the HDD’s Label (“FREECOM HDD”) does not change:

    DEVICE=`blkid | grep FREECOM | awk 'NR==1{print $1}'| awk '{$0=substr($0,1,length($0)-1); print $0}'`
    STATUS=`findmnt -lo label | grep FREECOM`
    if [[ ! -z "$STATUS" ]]; then
        udisksctl unmount --block-device $DEVICE 2>/dev/null
    exit 0
  3. Pingback: Moving from Lubuntu 18.04 to 20.10 | Fitzcarraldo's Blog

  4. Pingback: Prevent Lubuntu 22.04 (SDDM and LXQt) from leaving an external drive mounted incorrectly for other users | Fitzcarraldo's Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: