Auto Mount an NTFS USB Drive on Raspberry Pi

From Geekworm Wiki
Jump to navigation Jump to search

This article is from https://techwiztime.com/guide/auto-mount-ntfs-usb-drive-raspberry-pi/

Auto mounting an NTFS USB Hard Drive on a Raspberry Pi isn’t that difficult when you know how. In this guide, I’ll be using Raspbian Stretch Lite through the command line interface, but you could do this via the terminal in Raspbian Stretch desktop as well.

Let’s get started!

 Hardware List

 Software List

  • Latest Raspbian Stretch Lite Image

From the Command Line, we need to first make sure Raspbian is completely up to date and install the neccesary package to make NTFS work which is called NTFS-3G. Once that’s done, we will do a quick reboot to make sure everything sticks in place.

sudo apt update
sudo apt upgrade
sudo apt install ntfs-3g -y
reboot

Next we need to create a directory on the Raspberry Pi that will act as the mount point for the USB Hard Drive. To keep it organised, we will create this in the directory mnt and we will call the folder usbhdd to keep it simple.

sudo mkdir /mnt/usbhdd

Now that we have the folder ready, we need to figure out what the hard drive partition is that we want to mount. To do this, we need to check out fdisk and see which partition is the one we want to mount. It should be the last in the long list. This could be sda2, sda1 or even sdb2 so look at the size and whichever is bigger should be the correct one. Mine shows 1.8T as the biggest partion so I know that sda1 is the one that I want.

sudo fdisk -l

Now we know our device partition, we need to get what is know as the Partition ID. This will let us mount the USB Hard Drive even if the device changes from sda1 to say sdb1. It has happened to me before and caused my whole Raspberry Pi to fail at boot up so this step is important. You should see a section called PARTUUID=”000xxxxx-00″ on the device line. My particular one was 770bcbdc-01 and that’s what you would need to write down.

sudo blkid

With our Partition ID, we can now add some information to the FSTAB so our drive will automatically boot each time, but first we want to figure out the ID of our current logged in user. This will be important I promise. It will probably be uid=1000 and gid=1000. We need to take note of both the uid and the gid numbers.

id

FSTAB is our next step. Here we need to add the information we have gathered so far and before we reboot, we are going to test that it worked so we don’t cause the raspberry pi to fail at boot up. So the following string needs to be inserted on a new line under the exisiting ones, replacing the following with your details. PARTUUID, Mount Point, GID and UID.

This opens the FSTAB so we can edit it with the auto mounting information.

sudo nano /etc/fstab

This is the code you need to put into the file. Once you are done, press Control X then Y then ENTER to save the file.

PARTUUID=770bcbdc-01 /mnt/usbhdd ntfs auto,exec,rw,user,dmask=002,fmask=113,uid=1000,gid=1000 0 0

Broken down a little, here’s what that all means

file system - PARTUUID=770bcbdc-01 - This is the partition id for in my case /dev/sda1
mount point - /mnt/usbhdd - This is the folder we created for mounting the USB Hard Drive
type - ntfs - This is the format the hard drive is in. It could be HFS+ for Apple, EXT4 for Linux of FAT32 for DOS
options - auto,exec,rw,user,dmask=002,fmask=113,uid=1000,gid=1000 - Long Story short, this gives all the permissions
dump - 0 - This means we don't want to create a dump
pass - 0 - This means we don't want to do a file system check everytime

With the file now saved, we need to check that there’s no errors in the file before we reboot. To do that, we need to try and mount the partition from the FSTAB file.

sudo mount -a

If no errors come up, then we can check that the device is mounted correctly

sudo df -h

If you see your device in the list, then we are safe to do a reboot of the Raspberry Pi.

reboot

Once we are rebooted, log in to the raspberry pi and check you USB Hard Drive has mounted by going to that folder.

cd /mnt/usbhdd

And then we can check what’s in the folder by listing it’s contents

ls -la

And that’s it ladies and gentlemen. You should now have your Raspberry Pi setup to auto mount an NTFS formatted USB Hard Drive every time it reboots. Leave a comment down below if you have a problem and someone here or in the community should be able to help.



Add your comment
Geekworm Wiki welcomes all comments. If you do not want to be anonymous, register or log in. It is free.


Anonymous user #5

6 months ago
Score 0++
Cheers for creating this excellent, straight-forward article. I wish I had permission to register but apparently I don't, so I'm posting this anon. Thanks!

Anonymous user #4

15 months ago
Score 0++
good manual, tnxalot

Anonymous user #3

17 months ago
Score 0++
Well done,thanks

Walker

17 months ago
Score 0++
You're welcome, thank you for your order

Anonymous user #2

42 months ago
Score 0++
Worked for me. Thank you!

Anonymous user #1

47 months ago
Score 0++
it does not work

Xiali

47 months ago
Score 0++
Hi dear ,could you please let us know which shopping platform you bought this product on?And please let us konw the details about your hardware and software,we will try our best to help you to fix this out

Breton22 49

55 months ago
Score 0++

Hello.

Can I use this procedure with 1 Raspberry PI 4B and 1 HDD 3.5 WD + X835?

Cindy

55 months ago
Score 0++

Hi,

Yes, you can do a test.