10

As the title suggests, I am having issues on the new raspberry pi 4 with buster and USBMOUNT. Well, it's not working. At 3b+ there was a similar issue, you had to edit a file and change MountFlags from slave to shared. Well there isn't a MountFlags setting in the systemd-udevd.service file, but no matter what, I added it but still not working. Any ideas or an alternative to usbmount for a headless setup, keeping in mind that not always the usb stick is mounted and ofcourse it's not always the same stick with the same label all the time.

My dmesg:

I plug the stick somewhere here
[   41.511528] usb 1-1.2: new high-speed USB device number 8 using xhci_hcd
[   41.647482] usb 1-1.2: New USB device found, idVendor=26bd, idProduct=9917, bcdDevice= 1.00
[   41.647497] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   41.647509] usb 1-1.2: Product: SecureLock
[   41.647521] usb 1-1.2: Manufacturer:
[   41.647532] usb 1-1.2: SerialNumber: 0700413066DDE445
[   41.649386] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[   41.661890] scsi host0: usb-storage 1-1.2:1.0
[   42.733384] scsi 0:0:0:0: Direct-Access              SecureLock       PMAP PQ: 0 ANSI: 4
[   42.734206] sd 0:0:0:0: Attached scsi generic sg0 type 0
[   43.843400] sd 0:0:0:0: [sda] 15124992 512-byte logical blocks: (7.74 GB/7.21 GiB)
[   43.843621] sd 0:0:0:0: [sda] Write Protect is off
[   43.843636] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
[   43.843866] sd 0:0:0:0: [sda] No Caching mode page found
[   43.843879] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   43.866878]  sda: sda1

and my df -h

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.0G  1.4G  1.5G  48% /
devtmpfs        334M     0  334M   0% /dev
tmpfs           463M     0  463M   0% /dev/shm
tmpfs           463M  6.3M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           463M     0  463M   0% /sys/fs/cgroup
tmpfs           100M  8.0K  100M   1% /var/log
tmpfs            30M     0   30M   0% /var/tmp
tmpfs           100M  4.0K  100M   1% /tmp
tmpfs            20M  956K   20M   5% /run/samba
tmpfs            20M  1.3M   19M   7% /var/cache/samba
tmpfs            30M     0   30M   0% /tmp/mqueue
/dev/mmcblk0p1  253M   40M  213M  16% /boot
/dev/mmcblk0p3  438M  4.6M  406M   2% /home
tmpfs            93M     0   93M   0% /run/user/0

Finally, my fdisk -l

Device         Boot   Start     End Sectors  Size Id Type
/dev/mmcblk0p1         8192  532480  524289  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       540672 6832127 6291456    3G 83 Linux
/dev/mmcblk0p3      6832128 7774207  942080  460M 83 Linux


Disk /dev/sda: 7.2 GiB, 7743995904 bytes, 15124992 sectors
Disk model: SecureLock
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7fb5e9d8

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8064 15124991 15116928  7.2G  c W95 FAT32 (LBA)

This setup is working on a raspberry pi 2, pi 3b (jessie), pi 3b+ (stretch)

6 Answers 6

20

I faced the same issue with Raspberry Pi 4 and Raspbian Buster, the solution for me was to modify the following file:

/lib/systemd/system/systemd-udevd.service

You will see a line like this (I call this Before):

PrivateMounts=yes

Change this line to this (I call this After):

PrivateMounts=no

Then I rebooted and it was OK ;)

1
  • At RPi 3B there is no PrivateMounts param.
    – KyluAce
    Commented Nov 22, 2022 at 9:44
16

Because Raspbian is based on Debian, I suggest you to create a permanent system-specific configuration file according to the definitions as given in Debian's policies (see https://www.debian.org/doc/debian-policy/ch-files.html#configuration-files).

Buster has a solid configuration for systemd and udev placed in the package's library files at /lib/systemd/system/systemd-udevd.service. But as opposed to Greg's anwser this is not the place to change the configuration. It's very likely, that the changes you did, will be silently overwritten by an upgrade of the system's packages done by the packet manager. Only files in /etc/systemd/system are meant to be a system-specific configuration change done by an operator and not by a package (for further explanation see https://unix.stackexchange.com/a/458252/85199).

Therefor if you want to make usbmount work again, the already given configuration syntax is right. But you should place it like this.

Create a configuration container directory /etc/systemd/system/systemd-udevd.service.d.

sudo mkdir /etc/systemd/system/systemd-udevd.service.d

Create an own confugration file (that will overwrite the package configuration). Change 00-my-custom-mountflags as you wish.

sudo nano -w /etc/systemd/system/systemd-udevd.service.d/00-my-custom-mountflags.conf

Enter the following configuration, which disables private mounts.

[Service]
PrivateMounts=no

Restart systemd and udev subprocesses (or simply reboot).

sudo systemctl daemon-reexec
sudo service systemd-udevd restart

This way usbmount will work again like expected, your configuration file is persisted and not silently replaced by an apt upgrade.

I've done it this way for Pi 4 B with Raspbian Buster and can confirm that it works.

1
  • 6
    I agree that this is the correct workflow. As an alternative to your 'sudo nano' step, I used instead the command 'systemctl edit systemd-udevd'. This opens file '/etc/systemd/system/systemd-udevd.service.d/override.conf' in a VI editor. I added the '[Service] ...' section as you described, saved the changes, and restarted the systemd and udev subprocesses as described. Worked great. Commented Mar 10, 2020 at 23:14
2

Please use Greg's solution. I don't know if mods wish to remove this

SO.... I am currently using pmount. Removed USBMOUNT and installed it using the instructions here: https://raspberrypi.stackexchange.com/a/66324/68240 "thanks to the original author btw"

The only extra was that I had to

sudo chmod +x /usr/local/bin/cpmount

Since it was not working at the beginning and before the chmod, I created the mounting folders my self. So I am not sure if you actually need to do that. I also edited the script and changed the folder numbering and finally I removed the --sync setting.

Hope this helps someone, it looks like USBMOUNT is not being developed any more.

Oh oh forgot to mention. I did this before creating the script and right after I installed pmount, so I again I am not sure if it is actually required. Should be though.

sudo pico /etc/pmount.allow

and add there the devices you allow pmount to use /dev/sda1 /dev/sda2 and so on...

1
  • 1
    usbmount is exactly the kind of script that your custom-written cpmount is, packaged together with the udev rule. While it's old, I don't see how a self-written solution is any better. Commented Feb 27, 2020 at 12:57
2

I have a Raspberry Pi 4, running Buster, and I successfully installed usbmount following the instructions at ...

https://www.linuxuprising.com/2019/04/automatically-mount-usb-drives-on.html

which in summary says:

sudo apt install git
git clone https://github.com/rbrito/usbmount
sudo apt install debhelper build-essential
cd usbmount
dpkg-buildpackage -us -uc -b

The only change I made was after all those commands and BEFORE installing the .deb file I did this:

sudo apt install lockfile-progs

and then installed like this

cd ..     # back to where you were
sudo dpkg -i usbmount_0.0.24_all.deb 
4
  • 2
    Please don't write answers that can only be understood by following a link.
    – Ingo
    Commented Feb 28, 2020 at 11:23
  • Sorry if I offended. I was trying to help other people in my situation.
    – Andrew Kay
    Commented Feb 29, 2020 at 12:04
  • 1
    I have now fixed it up to include a summary of the remote link.
    – Andrew Kay
    Commented Feb 29, 2020 at 12:10
  • 3
    +1, well done (according to our policies) :-)
    – Ingo
    Commented Mar 1, 2020 at 13:13
2

I'm using a Raspberry Pi 4 headless with Raspberry Pi OS lite (Debian 10.7). I didn't try too hard making usbmount work, but this alternative works well:

  1. Install udevil: sudo apt install udevil
  2. Create a systemd service file: sudo nano /etc/systemd/system/devmon.service and write the following:
[Unit]
Description=Automounting usb drives.
After=network.target

[Service]
Type=simple
User=pi
Restart=on-abort
ExecStart=/usr/bin/devmon

[Install]
WantedBy=multi-user.target
  1. Enable the service: sudo systemctl enable devmon.service
  2. Start the service: sudo systemctl start devmon.service

You can now plug in your USB thumb drive and check that it is mounted using lsblk (it should be mounted in /media/pi/)

1
  • +1, I didn't know about udevil, though looking at its github page I see it's kind of abandoned: last code change from 2015, unfixed issues dated 2014-2020. Commented Feb 6, 2021 at 13:29
2

The best solution I found for this was https://github.com/Ferk/udev-media-automount based on the recommendation in https://wiki.archlinux.org/title/Udev#Mounting_drives_in_rules

git clone https://github.com/Ferk/udev-media-automount.git
cd udev-media-automount
sudo make install

It will automount usb drives under /media with a $LABEL.$TYPE mount point

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 22, 2022 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.