2

I use Raspberry pi3+ as a small NAS (with Samba). I have to use a couple of HDDs in usb-sata cases with NTFS file system. Raspbian mounts them automatically on boot in /media/pi directory. I don't like this behavior: I'd like every particular drive to be mounted to a specific directory in /home/pi, and I have to manually unmount them from /media, than remount to, say, /home/pi/ntfsdv1 as well as chown /home/pi/ntfsdrv1 to pi user.

How do I make Raspbian: 1) Stop mounting usb drives to /media directory 2) Mount drives automatically on boot to the folders I deesire (fstab maybe?) 3) Automatically chown the content of the mounted drive to pi user (so I don't get problems with accessing root's files with smb) ?

  • I'd suggest running a script on boot that unmounts those drives, remounts them and runs chown. To get an idea of how to make a script run on startup, see raspberrypi.stackexchange.com/questions/8734/… This is preferrable to altering the default behavior because undoing it is as simple as removing your startup script. – user96931 Dec 10 '19 at 17:56
1
  1. To automount your USB drives to a directory of your choosing:

In accordance w/ man fstab:

The second field (fs_file). This field describes the mount point (target) for the filesystem. For swap partitions, this field should be specified as none. If the name of the mount point contains spaces these can be escaped as \040.

For example, to mount a drive w/ LABEL=PASSPORT2TB on /home/pi/mntPassport, a line similar to this in your /etc/fstab should work:

LABEL=PASSPORT2TB /home/pi/mntPassport ext4 rw,user,nofail 0 0

You'll need to change ext4 to NTFS, and of course using LABEL to id the drive is only one option... again, man fstab is your friend.

  1. WRT chown: You may find that pi automatically gets ownership, but if not:
sudo chown -R pi:pi /home/pi/mntPassport/YourFolderName  

Let us know how this works, or if you have questions. You may also wish to peruse this recipe on github.

  • fstab trick does the job, thank you! – Ivan Dec 8 '19 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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