Mounting NTFS to Raspberry Pi 3

I made a previous post regarding mounting a usb flash drive to a raspberry pi and the issues involved in this task.

If you’ve initialised from new or cannibalised a HDD from a wounded device running windows then it wont be fully compatible with a Linux file system and the chmod command will not work.

Linux permission system (for reference) uses a binary system, so if you want read/write you add 4 (read) and 2 (write) = 6 (read/write).

6 (4+2)read,write5 (4+1)read,execute4read3 (2+1)write,execute2write1execute

Numeric Id Permissions
7 (4+2+1) read,write,execute

These numeric values are then assigned to the ‘owner’ ‘group’ and ‘world’ users of the Linux system.
A common setting would be 755 or rwxr-xr-x (for readability purposes, rwx | r-x | r-x) which corresponds to,

Number User Permissions
7 owner read,write,execute rwx
5 group read,execute r-x
5 world read,execute r-x

Some code snippets to chmod with Linux files,

#to change a directory to rwx for the owner and r-x for all others
sudo chmod 755 /your-directory-name

#to change a file to rw- for the owner and r-- for all others
sudo chmod 644 /your-file-name

#use -R to set recursive permissions, chmod the parent and its contents get the same rules
sudo chmod -R 644 /your-parent-location #be careful with this though

If you read any forum on chmod and or permissions the key rule that gets repeated over and over is never use 777 as a directory permission

Now the fun bit, mounting your drive to the pi in a usable way. From my experience of this you have 2 options,

In both of the following the examples /dev/sda2 is my external hdd and /mnt/media is the location to mount the drive.

1, mount the drive using the following,

/dev/sda2    /mnt/media    ntfs    auto,users,rw,uid=pi,gui=pi,umask=022    0    0

I have used this method and the drive will mount but only with read permissions. Even though the line above suggests it’ll have read/write and we included the umask option.
This option is fine if you can manage your files by removing the drive and hooking it into a windows machine, copy/create/delete files then re mount to the pi.

2, mounting with the following method will provide read/write permissions however I have read there is a performance issue which you might need to investigate further.

Install ntfs-3g

#run an update
sudo apt-get update

#install ntfs-3g
sudo apt-get install ntfs-3g

Now edit the fstab

sudo nano /etc/fstab

#add this line at the end of the file
/dev/sda2    /mnt/media    ntfs-3g    uid=pi,gid=pi,dmask=0022,fmask0033    0     0

Here I used ‘pi’ as the uid (user id) and gid (group id) but you can also do the following

#type this into the terminal and it'll display the id data

then use the numeric id values in place of ‘pi’ this is normally 1000.

To further explain, the line in the fstab is made up as follows,
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]

#this is the external drive location (device)

#this is the mount point

#this is the file type
ntfs or ntfs-3g

#this is the options section

#these basically tell the system not to back-up/scan the files on boot (dump & pass)
0    0

Now that useful table earlier with the Linux permissions listed in it, well if you edit the fstab as shown above you need to pop in some permissions. This is done using, fmask (files), dmask (directories) and umask (all).

This is a bit confusing, if you set


then you are setting permissions of 755 to the directories on the device. Basically select the permission you want then set the dmask, fmask, umask to equal the difference from your permissions and 777 (remember that 777 is not seven hundred and seven!)

Permission wanted is 755,
Difference to 777 is 022,

dmask=0022 (i’m not clued up to the extra ‘0’ at the start)

So there we are, its not straight forward and can be daunting for new users of Linux. Once you get passed the different file system types using ntfs-3g its not so complicated but make sure,

Don’t use 777 unless you know what you are doing!


One thought on “Mounting NTFS to Raspberry Pi 3

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s