0

Is there a way to make a Raspberry Pi running Raspbian automount a USB drive formatted in NTFS with all the permissions to read and write whenever plugged in to the Raspberry Pi AND on boot if it's plugged in?

I've seen lots of different flakes of everything, but mostly what I found is people either need to only get it mounted on boot or automount on connect but not NTFS. Ironically when I start the xserver in Raspbian it mounts it all perfectly as I wish, however that's not an option for me, as I need it to also automount it and have all permissions when there is no GUI running.

So far I've tried installing the ntfs-3g, it allowed me to get the permissions, but it seems to only work when the disk gets mounted when the GUI is running.

And for mounting I installed now usbmount, but it seems to be deprecated and I haven't found a good guide how to use it with NTFS and have all permissions, is that even possible?

I heard there are

3
  • 6
    I suggest you research this without including the terms "raspberry pi" or "raspbian" in your searches and just use "linux", since that's the direction in which the solution lies. This is certainly possible via udev rules; there should be examples and Q&A's about this on our larger sibling site, Unix & Linux. Note the type of filesystem is irrelevant to the automounting issue, and the automounting issue and the permissions issue are separate. It is easier to research them that way than look for something that is going to solve all your problems together.
    – goldilocks
    Commented Sep 27, 2015 at 2:25
  • The really annoying thing for me is that the lxde GUI does auto mounting somehow without changing fstab etc.
    – PaulF8080
    Commented Apr 24, 2016 at 8:00
  • You can see if my code review examples apply at codereview.stackexchange.com/questions/134233/… - see if there's something you can use there. Uses udev and bash script - it's not set to mount on boot - but you can probably figure that out - might just be a matter of changing the rule # to a small number.
    – dbmitch
    Commented Jul 24, 2016 at 4:42

3 Answers 3

1
  1. Take a look at auto mount tools, maybe there's one that suits you. pmount is known to do a good job auto-mounting removable drives.

  2. Write a udev rule.

Something like:

 SUBSYSTEMS=="usb" KERNEL=="sd[a-z][1-9]" RUN+="/usr/bin/udisksctl mount -b /dev/%k --no-user-interaction"
1

Since Debian 8 is using systemd you might want to take a look at the current method to automatically mount devices on boot and as they get connected as well. While udev and fstab also work, they are the old way and not that easy to understand for beginners.

So here is how you automatically mount a device using systemd:

  1. Find out the UUID of that device. Run

    blkid /dev/sdXY
    

    for that, where X is a letter a-z and Y is a (usually single digit) number. If you don't know what your device is, unplug it, run ls /dev/sd*, then plug it in again and run ls /dev/sd* again. Compare the two outputs and you will see that some sdXY has been added. X stands for the physical drive and Y for the partition. On a Raspberry Pi that would usually be sda1.

  2. Create a systemd mount service file with

    sudo nano /lib/systemd/system/path-to-mountpoint.mount
    

    I'm not sure about the file naming. But I read there is a convention that the file name is the path to the mountpoint with / replaced by -. I don't remember if it was mandatory. The content should look like this:

    [Unit]
    Description=My Happy-Place
    
    [Mount]
    What=/dev/disk/by-uuid/[YOUR UUID HERE]
    Where=/path/to/mountpoint
    
    [Install]
    WantedBy=local-fs.target
    
  3. Tell systemd that there is a new file by calling

    sudo systemctl daemon-reload
    
  4. Enable the new systemd rule by calling

    sudo systemctl enable path-to-mountpoint.mount
    

That would be it. After a reboot your device will mount automatically. If you don't want to wait for a complete reboot you can start the service right away with

sudo systemctl start path-to-mountpoint.mount

and check the status of the service with

sudo systemctl status path-to-mountpoint.mount

To unmount your device you call the usual

sudo umount /path/to/mountpoint

Hopefully that is helpful and also other will start using the features of systemd. As Linux is very old now I know myself that there are plenty pages and tutorials that are not state of the art and some even outdated. So I try to fix that here for automatic mounting.

1
  • You can identify a plugged in device by running the command dmesg | tail.
    – mrkskwsnck
    Commented Jul 28, 2017 at 20:05
0

If you type cat /etc/fstab you will find something like the following.

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID=94dc6686-0eda-41ba-87f7-494d7e37f913       /mnt/PiData     ext4    defaults,noatime,noauto  0     0
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

I have added a line to mount a HD (in my case ext4 and I have specified noauto; I also identify the partition by UUID). You should add an entry for your HD. Look at man fstab for an explanation of the fields.

You will also need to manually create a directory to mount into. The GUI automatically mounts disks into /media/. You can use this or the more conventional /mnt.

I believe that if you are running the GUI, you should be able to list mounted disks with mount in a terminal for help.

1
  • Wouldn't this stop the boot sequence if the drive is missing? I'm not sure if nobootwait parameter is still supported, but perhaps it's worth a try. Commented Oct 25, 2016 at 15:08

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.