USBMount not mounting problem

Problem

I had a portable harddisk connected using USB to my Raspberry Pi B+ Rev3 running Raspbian 9. The harddisk had two partitions: NTFS and ext4. I had usbmount installed and configured as described here. When Raspbian is booted up with the harddisk already plugged in, I could see using sudo fdisk -l that the ext4 partition was visible. So, usbmount should have automatically mounted this ext4 partition to /media/usb0, but it was not doing that.

I had verbose logging enabled for usbmount as described here. When I searched the system log I could see that usbmount was actually mounting the ext4 partition, but surprisingly it was not visible at /media/usb0:

$ cat /var/log/syslog | grep usbmount
980:May 18 11:42:28 my-pi usbmount[373]: /dev/sda2 contains filesystem type ext4
989:May 18 11:42:28 my-pi usbmount[373]: mountpoint /media/usb0 is available for /dev/sda2
991:May 18 11:42:28 my-pi usbmount[373]: executing command: mount -text4 -osync,noexec,nodev,noatime,nodiratime /dev/sda2 /media/usb0
1010:May 18 11:42:28 my-pi usbmount[373]: executing command: run-parts /etc/usbmount/mount.d
1013:May 18 11:42:28 my-pi usbmount[373]: usbmount execution finished

Solution

Turned out that systemd was the culprit. It was having a MountFlags=slave in its systemd-udevd.service file. So, the mount operation of usbmount was mounting into the namespace of systemd and not to the user.

To change this mount option, run this command:

$ sudo systemctl edit systemd-udevd

Add these lines to the file that is opened:

[Service]
MountFlags=shared

I found that this created the file /etc/systemd/system/systemd-udevd.service.d/override.conf with the above lines.

Restart systemd or your Pi:

$ sudo systemctl daemon-reload
$ sudo service systemd-udevd --full-restart

After the restart, I found that usbmount had automatically mounted my ext4 partition.

References:

Advertisements

How to find the init system used by Linux

init is the first process that is started by an Unix operating system. It has PID 1 and handles creation of all other processes and daemon processes required by the OS. It acts as the ancestor of all processes. There are many init systems that have been used in Linux distributions over the years. Some of the popular init systems are the classic System V init, upstart (Ubuntu used to use this) and systemd (popular right now for all Linux distros).

So, you are sitting at a Linux computer, do you know which init system it is using? There is no straightforward method to find this out.

Here are a few methods, one of which should work:

  • Check the init version, it should report the init system name too:
$ init --version
init (upstart 1.12.1)
Copyright (C) 2006-2014 Canonical Ltd., 2011 Scott James Remnant

This was on a Ubuntu 14.04 system. You can see that it uses upstart.

  • Sometimes the /sbin/init is a symbolic link to the actual init:
$ stat /sbin/init
  File: '/sbin/init' -> '/lib/systemd/systemd'

This was on a Ubuntu 16.04 system. You can see that it uses systemd.