reinis
Posts: 19
Joined: Fri Mar 11, 2016 12:34 pm

USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Feb 09, 2018 6:40 pm

Hi all,

I have a Raspberry PI 2 running the newest version of Raspbian Stretch Lite in Command Line environment. Out of the box my external USB hard/flash drives are not auto-mounted when plugged into the Raspberry Pi.

The ultimate goal is to have any USB drive to auto-mounting when plugged into the Raspberry PI 2. If it is not possible to achieve this for all drives, then as a worst case scenario I would be ok to auto-mount specific HDDs by specifying their UUIDs.

I have been looking into this for hours, but I could not find a solid and simple solution online. I would truly appreciate if someone could please post a working solution in here. Moreover, below you can see the output of my sudo blkid. In this case I want the USB hdd assigned to /dev/sda1 to be auto-mounted when I plug it into my Raspberry pi 2.

Code: Select all

pi@raspberrypi:~ $ sudo blkid
/dev/mmcblk0p1: LABEL="boot" UUID="CDD4-B453" TYPE="vfat" PARTUUID="896c5641-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2" TYPE="ext4" PARTUUID="896c5641-02"
/dev/mmcblk0: PTUUID="896c5641" PTTYPE="dos"
/dev/sda1: UUID="93ddc2e0-48e1-457c-9d59-f6a34596e6e1" TYPE="ext4" PARTLABEL="SSD-120GB" PARTUUID="9eea6391-2399-4983-889c-d5a651c73952"
PS I find it very inconvenient that such functionality is not built into Raspbian out of the box for the Command Line environment (I know that auto-mount works when in desktop environment).

Thank you!

Best regards,
Reinis
Last edited by reinis on Sat Feb 10, 2018 6:46 am, edited 1 time in total.

User avatar
thagrol
Posts: 8900
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB HDD Auto Mount - Raspbian Stretch

Sat Feb 10, 2018 12:11 am

reinis wrote:
Fri Feb 09, 2018 6:40 pm

PS I find it very inconvenient that such functionality is not built into Raspbian out of the box for the Command Line environment (I know that auto-mount works when in desktop environment).
Functionality is there it just takes a little setting up. First thing to do is read up on fstab and mount. Try:

Code: Select all

man fstab
man mount
then

Code: Select all

cat /etc/fstab

Taking your current /dev/sda1 as an example, you'd do something like this:
  1. Create a mount point:

    Code: Select all

    sudo mkdir /media/SSD-120GB
  2. Backup your existing /etc/fstab e.g.:

    Code: Select all

    sudoi cp /etc/fstab /etc/fstab.bak
  3. Open /etc/fstab in your favourite text editor e.g.:

    Code: Select all

    sudo nano /etc/fstab
  4. Add a line similar to this, tweaking mount options and mount point as required:

    Code: Select all

    UUID=93ddc2e0-48e1-457c-9d59-f6a34596e6e1 /media/SSD-120GB ext4 defaults,nofail 0 0
    Use UUID rather than the device node (/dev/sda1) as the device node can change across reboots especially if drives are added or removed.
    Include "nofail" in the mount options to prevent the Pi hanging if it is booted without the drive attached.
  5. Save and close /etc/fstab
  6. Connect the HDD and reboot
Repeat for as many drives/partitions as you need but be aware that they each need their own mount point.

The above method won't automount if you hot plug a drive but the easy way around that is either

Code: Select all

sudo mount /path/to/mount-point
or

Code: Select all

sudo mount -a
It might be possible to mount a hot plugged drive with systemd and/or udev but I' don't know enough to help you with that. Disconnecting a USB drive without first unmounting it is definitely not a good idea.

Edit:
A quick google for "udev mount" returned this: https://www.axllent.org/docs/view/auto- ... b-storage/ No idea if it actually wokrs though.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

reinis
Posts: 19
Joined: Fri Mar 11, 2016 12:34 pm

Re: USB HDD Auto Mount - Raspbian Stretch

Sat Feb 10, 2018 6:45 am

Thanks a lot for the input. The problem is that I tried fstab 10x times but it did not work for me. I tried it with UUID and LABEL - still would not mount the drive on boot. It returns exit code error 32. A quick google search show why - it seems that raspberry pi 2 simply does not manage to detect the usb drive before fstab is executed. You can read about it [ur=viewtopic.php?f=28&t=99491l]here[/url] and here.

The good news is that I found a very simple alternative (at least in terms of installation, not sure about how "native" the solution is) - a package called usbmount. I can confirm that with usbmount I can auto-mount on boot and hot-plug any USB device in Raspbian Stretch Lite on my Raspberry Pi 2!

Installation steps of usbmount:

1. Install the package:

Code: Select all

sudo apt-get install usbmount
2. Make sure it works in Stretch by changing MountFlags=slave to MountFlags=shared here:

Code: Select all

sudo nano /lib/systemd/system/systemd-udevd.service
3. Reboot and it works!

Best,
Reinis

spectre-nz
Posts: 2
Joined: Sat Nov 25, 2017 9:43 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Sat Apr 07, 2018 4:22 am

Great thanks!
Worked for me on a Pi 3 Model B+ after it stopped recognising USB drives.

yuvarajoo
Posts: 2
Joined: Sat Apr 28, 2018 12:35 pm

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Sun Apr 29, 2018 6:22 am

Thanks. It solved for me as well... :D
Anyway maybe anyone have native solution can advise as well...

donbrew
Posts: 87
Joined: Sun Sep 04, 2016 2:32 pm

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Sun Jun 17, 2018 8:56 pm

The problem with using fstab is it won't boot if the drive is not plugged in first. The system gets stuck looking for it.

My bet is you forgot the 0 0 at the end of the fstab line.

usbmount seems to be the native fix on Lite. A lot of packages need to be installed, like samba, nfs, ntfs-3g etc.

User avatar
thagrol
Posts: 8900
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Sun Jun 17, 2018 10:22 pm

donbrew wrote:
Sun Jun 17, 2018 8:56 pm
The problem with using fstab is it won't boot if the drive is not plugged in first. The system gets stuck looking for it.
There's an easy fix for that: add "nofail" to the mount options in your fstab entry.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

DaveL17
Posts: 1
Joined: Sat Jan 26, 2019 7:44 pm

Re: USB HDD Auto Mount - Raspbian Stretch

Sat Jan 26, 2019 7:50 pm

thagrol wrote:
Sat Feb 10, 2018 12:11 am
[*]Backup your existing /etc/fstab e.g.:

Code: Select all

sudoi cp /etc/fstab /etc/fstab.bak
Small typo in the instructions above. `sudoi` should be `sudo`.

Cheers,
Dave

lekso
Posts: 1
Joined: Wed Mar 20, 2019 11:20 pm

Re: USB HDD Auto Mount - Raspbian Stretch

Wed Mar 20, 2019 11:29 pm

reinis wrote:
Sat Feb 10, 2018 6:45 am
Thanks a lot for the input. The problem is that I tried fstab 10x times but it did not work for me. I tried it with UUID and LABEL - still would not mount the drive on boot. It returns exit code error 32. A quick google search show why - it seems that raspberry pi 2 simply does not manage to detect the usb drive before fstab is executed. You can read about it [ur=viewtopic.php?f=28&t=99491l]here[/url] and here.

The good news is that I found a very simple alternative (at least in terms of installation, not sure about how "native" the solution is) - a package called usbmount. I can confirm that with usbmount I can auto-mount on boot and hot-plug any USB device in Raspbian Stretch Lite on my Raspberry Pi 2!

Installation steps of usbmount:

1. Install the package:

Code: Select all

sudo apt-get install usbmount
2. Make sure it works in Stretch by changing MountFlags=slave to MountFlags=shared here:

Code: Select all

sudo nano /lib/systemd/system/systemd-udevd.service
3. Reboot and it works!

Best,
Reinis
This solution not only solved my usb self-loading issues, but also the automatic start of my VNC server. Thank you!

Oh!Lee
Posts: 14
Joined: Fri Jun 10, 2016 8:58 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Thu Mar 21, 2019 9:17 am

spectre-nz wrote:
Sat Apr 07, 2018 4:22 am
Great thanks!
Worked for me on a Pi 3 Model B+ after it stopped recognising USB drives.
Does NOT work for me on my Pi 3 Model B+ :?
followed the instructions, but when I want to copy a file
the error occurs "cp: cannot create regular file '/media/usb/test.bla': Permission denied".

Any idea?

Oh!Lee
Posts: 14
Joined: Fri Jun 10, 2016 8:58 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Mar 22, 2019 1:26 pm

Problem indentified:
On my systemin /etc/usbmount/usbmount.conf the variable FS_MOUNTOPTIONS was not set.

I changed it to
FS_MOUNTOPTIONS="-fstype=vfat,gid=users,dmask=0007,fmask=0117"
and it works perfectly now!

Beric_
Posts: 10
Joined: Mon May 29, 2017 7:14 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Thu Jun 13, 2019 7:54 am

Hello,

Im having the same problem. I just install a new image of Raspian Strech. These are the steps that I followed:

Code: Select all

sudo apt-get update

sudo apt-get install usbmount

apt-get install 3g ntfs

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

MountFlags=slave to MountFlags=shared
In this point, doesnt work. I followed the instructions of this post and try this:

Code: Select all

FS_MOUNTOPTIONS="-fstype=vfat,gid=users,dmask=0007,fmask=0117"
And This

Code: Select all

FS_MOUNTOPTIONS="-fstype=auto,gid=users,dmask=0007,fmask=0117"

But stil doesnt work.

How can i active debug to usbmount ? Is there another log hat can help me?


Best regards !

User avatar
thagrol
Posts: 8900
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Thu Jun 13, 2019 11:12 am

Beric_ wrote:
Thu Jun 13, 2019 7:54 am

Code: Select all

apt-get install 3g ntfs
Was that an error in transcription or was that what you actually tried?

As written, it would have failed as 1. it wasn't run as root, 2. you asked it to install the wrong things, and 3. there are no packages named "3g" or "ntfs"

Try this instead:

Code: Select all

sudo apt-get install ntfs-3g
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Beric_
Posts: 10
Joined: Mon May 29, 2017 7:14 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Thu Jun 13, 2019 11:30 am

It was a writing error, i installed ntfs-3g correctly.

Beric_
Posts: 10
Joined: Mon May 29, 2017 7:14 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Mon Jun 17, 2019 6:38 am

So, no more help ?

Beric_
Posts: 10
Joined: Mon May 29, 2017 7:14 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 6:44 am

Thanks, Rapberry official forum.

It has been a pleasure

User avatar
davidcoton
Posts: 6962
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 8:40 am

Although this is an official forum, the contributors are all volunteers. No-one owes you an answer, and it is of course impossible for anyone to tell you when everyone is out of answers.

It is also unhelpful to hijack a thread marked "[Solved]", and sarcasm does not help.
Location: 345th cell on the right of the 210th row of L2 cache

Beric_
Posts: 10
Joined: Mon May 29, 2017 7:14 am

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 8:55 am

hijack ?

I wrote in this thread to comment that I had tried the proposed solutions, to not open another thread unnecesary. The usual use of a forum if you know what i mean...

If you do not "owe me" an answer do not come to write this [mod deleted expletive]

User avatar
rpdom
Posts: 21536
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 9:35 am

There's no need to be nasty!

No one "owes" you an answer. If we can answer, we will.
Unreadable squiggle

User avatar
thagrol
Posts: 8900
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 9:36 am

While I don't have to justify my actions in not responding further, particularly to someone who comes across as a whiny kid, I will do so.

I gave no further help as I have none to offer. I don't use usbmount.

Well no more advise except the obvious:
  • Read the documentation for usbmount
  • unmount the drives and restart the daemon (or the pi). Config file changes almost certainly won't be picked up without this.
Your attitude isn't going to do you any favours. Folks are going to be reluctant to help you out with any future problems you may have. And watch the language, there are kids on here.

As an aside, whatever happend to basic courtesy?Few folks bother with "please" and fewer still thank those who try to help.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14841
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: USB Auto mount - Raspbian Stretch Lite [Solved]

Fri Jun 21, 2019 9:50 am

This thread deserves locking....

Return to “Troubleshooting”