118

I have two partitions that I want to mount on startup:

/dev/sda3   /mnt/devel  ext4    defaults    0   2
/dev/sda2   /mnt/excess ntfs    defaults    0   2

The ext4 partition mounts fine (owned by me, writable only by me), but the NTFS mounts owned by root with R\W permission for all.

How to fix this?

drwxr-xr-x  7 amanda amanda 4096 2012-03-14 19:07 devel
drwxrwxrwx  1 root   root   4096 2012-03-14 22:38 excess
1
  • 1
    The options "noatime" or "relatime" is available and recommended for permanent ntfs mounting (see man mount.ntfs). I had some hdd busy-ness problems with ext3/4 and ntfs too!
    – user259044
    Mar 17, 2014 at 4:13

8 Answers 8

143

Permissions for ntfs and vfat file systems must be set with the dmask, fmask and umask options. dmask controls permissions for directories, fmask controls permissions for files, and umask controls both. Since these options set masks, they should be the complement of the permissions you want. For example, rwx for the owner and rx for others is 022 rather than 755.

To set the owner, use the uid and gid options for user and group, respectively. You can find your UID with the command id -u. To find your GID, use id -g. These values are both usually 1000.

A common set of mount options for ntfs is uid=1000,gid=1000,dmask=027,fmask=137. This sets you as the owner of the drive, and sets the permissions to drwxr-x---.

Here are examples of a working /etc/fstab

UUID=EEA2B69CA2B668AB        /WIN_C     ntfs-3g   defaults,nls=utf8,umask=000,dmask=027,fmask=137,uid=1000,gid=1000,windows_names 0 0 
UUID=65AEC0E830EA0497        /WIN_D     ntfs-3g   rw 0 0
  • To get the UUID for your partition, you can use ls -l /dev/disk/by-uuid/ or lsblk -f | grep -v loop or gnome-disks

  • If you get no visible error after rebooting and partitions stay readonly or you get an error similar to:

    Error mounting /dev/sda6 at /media/WindowsDrive: 
    Command-line `mount -t "ntfs" -o "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000,dmask=0077,fmask=0177" "/dev/sda6" "/media/rolindroy/Media Center"' exited with non-zero exit status 14: The disk contains an unclean file system (0, 0). 
    Metadata kept in Windows cache, refused to mount. 
    Failed to mount '/dev/sda6': Operation not permitted The NTFS partition is in an unsafe state. 
    Please resume and shutdown Windows fully (no hibernation or fast restarting), or mount the volume read-only with the 'ro' mount option

This is because Windows 8 and 10 offer a "Fast Startup" option that depends on a "non-complete" shutdown. You can disable fast startup by following these steps under "Power Options".

UUID=01D9318DD8A39810  /run/media/$user/Win11   ntfs-3g uid=$user,gid=$user,umask=0022 0 0
UUID=01D9317B8D647610  /run/media/$user/Storage ntfs-3g uid=$user,gid=$user,umask=0022 0 2

In the above example win11 will be mounted read-only, while Storage as read-write.

& they will be visible in file manager as drives Since they are mounted in folder /run/media/$user Also don't forget to replace $user with your username.

11
  • 4
    Could you possibly provide a more complete example showing those options used in a line from /etc/fstab
    – puk
    Nov 15, 2013 at 3:34
  • 3
    @puk, I have UUID=3030BD846F74E514 /media/iam/ntfspartition ntfs-3g uid=1000,gid=1000,dmask=022,fmask=133 0 0, as I've included at askubuntu.com/a/507326/221448 (where I also mention bind). Aug 5, 2014 at 19:58
  • 2
    @ScottF uid=0,gid=0
    – wjandrea
    Nov 13, 2017 at 0:37
  • 2
    This params worked for me: "defaults,rw,nls=utf8,umask=000,dmask=027,fmask=137,uid=1000,gid=1000,windows_names". After this, also run "sudo ntfsfix /dev/sdXX" to fix the partition. Oct 20, 2018 at 19:41
  • 5
    Is it better to set the file system type to ntfs or ntfs-3g? Apr 24, 2020 at 3:31
44

If you mount the ntfs partition with the permissions option, then chmod / chown will work

/dev/sda2   /mnt/excess ntfs-3g    permissions,locale=en_US.utf8    0   2

You can then

sudo chown your_user:your_user /mnt/excess

Easier then uid,dmask,fmask.

2
  • 1
    Any downside/side-effect to that sudo chown command? What exactly it does?
    – ReneSac
    Feb 25, 2015 at 0:08
  • 7
    The chown command changes the owner of the mount point (/mnt/excess) to the desired user. This step will have to be repeated each time the partition is mounted, in my experience (at least after every reboot) ... so, do the proper thing, set uid/gid/umask ... I always thought fmask and dmask were optional - like when you wanted different permissions for files and dirs.
    – thecarpy
    Apr 30, 2015 at 12:28
13

I had some trouble with this because when I reboot the disk name changes... (sda0 to sdb2)

I fixed the problem by mounting them by UUID in the fstab, you can view the UUID for your harddrives by entering: sudo blkid

Make a back-up of your fstab file:

sudo cp /etc/fstab /etc/fstab.orig

Make sure you tripple check the >>, if you place one > you overwrite your fstab!

sudo blkid >> /etc/fstab

If you still screwed up you can replace your fstab with the original:

sudo cp /etc/fstab.orig /etc/fstab

Next make a folder:

sudo mkdir /media/mydrivename

Configure the fstab:

sudo vim /etc/fstab

Don't forget to comment the output from the blkid with a '#' on the beginning of the lines!

Add this to the fstab file, you can find the UUID in the block on the bottom you inserted with the command above. media/mydrivename is where the partition should be mounted.

UUID=xxxxxxxxxxxxxxxxx   /media/mydrivename ntfs    permissions,locale=en_US.utf8    0   2

This is my fstab file:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=5d4940cf-5cf5-443a-be11-1f7e551962d1 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda1 during installation
UUID=84b7e5e9-08c3-4641-b28b-99e0255e604d none            swap    sw              0       0

# 500 GB Webserver harddisk from lr-serv-01
UUID=BA9A48D39A488E37 /media/hdd1 ntfs permissions,locale=en_US.utf8 0 2

# 2 TB Movie share harddisk from lr-serv-01
UUID=7EB09666B09624A5 /media/hdd2 ntfs permissions,locale-en_US.utf8 0 2

#/dev/sda1: UUID="10EC004DEC003010" TYPE="ntfs" 
#/dev/sda2: LABEL="system" UUID="88A4FE47A4FE3772" TYPE="ntfs" 
#/dev/sda3: LABEL="storage_01" UUID="BA9A48D39A488E37" TYPE="ntfs" 
#/dev/sdb1: LABEL="storage_02" UUID="7EB09666B09624A5" TYPE="ntfs" 
#/dev/sdc1: UUID="84b7e5e9-08c3-4641-b28b-99e0255e604d" TYPE="swap" 
#/dev/sdc2: UUID="5d4940cf-5cf5-443a-be11-1f7e551962d1" TYPE="ext4" 
#/dev/sdd1: LABEL="storage_spotnet" UUID="EC6E8F416E8F0394" TYPE="ntfs" 
#/dev/sdd2: LABEL="storage_backup_pcs" UUID="6C2699D026999BA0" TYPE="ntfs" 
#/dev/sdd5: LABEL="storage_series" UUID="7670ABF770ABBC6D" TYPE="ntfs" 
#/dev/sdd6: LABEL="storage_winmx" UUID="564AB81B4AB7F5B9" TYPE="ntfs" 

Reboot the system by typing:

sudo reboot

To check if the partition is mounted you can type df -k.

Give ownership to yourself:

sudo chown -R USERNAME:USERNAME /media/mydrivename

Did this on Ubuntu Server 14.04.01!

Hope this answer helps someone ;-)

5
  • 6
    While this sounds like generally solid advice, I would find it more elegant to simply copy the UUID from the output of sudo blkid instead of dumping the whole thing to /etc/fstab and transiently corrupt it. Another way would be to get the UUID from the properties dialogue of the partition in GParted. Oct 19, 2014 at 12:09
  • Well as I am doing this on my server I don't really see a way to copy it... All I have is a keyboard and bash.
    – rotgers
    Oct 19, 2014 at 13:46
  • Most terminal emulators allow you to copy things (assuming you're using remote access or a terminal emulator like screen or tmux instead of a raw virtual terminal). Oct 19, 2014 at 13:55
  • Bad assumption haha, I was not using a terminal emulator. However, I added some stuff to my answer for making a copy of the fstab file in case someone screws up. :)
    – rotgers
    Oct 19, 2014 at 13:59
  • I switched from using UUID to LABEL because for some reason the UUID's changed when I adjusted a partition but the label names didn't. Also I find it easier to see what's going on in fstab with a LABEL="some-name" than a UUID="long random string". Sep 13, 2016 at 16:02
9

You can use ntfs-config GUI utility to mount NTFS partitions in fstab.

Mount NTFS Windows Partition FSTAB

ntfs-3g driver is required to provide full read-write support for the NTFS partition and gksu to run NTFS Configuration GUI with root privileges.

sudo apt-get install ntfs-3g ntfs-config
sudo apt-get install gksu

Search for and open ‘NTFS Configuration Tool’ from the Unity Dash. In the window that appears select the partitions you want to configure. Here, I would prefer to have only my storage partition mounted. Just tick ‘Enable write support for internal device’.

NTFS-Config Utility will backup the original fstab file, so we can easily review the changes that were made by the application. To review the changes,

cat /etc/fstab-ntfs-config-save
cat /etc/fstab
0
7

I use the following that I find correctly gives me permissions upon mount (NTFS drive from a dual-boot system setup):

Edit /etc/fstab:

UUIDs can be found in /dev/disk/by-uuid/ (usually map to /dev/sd*)

Replace <your uuid> with your UUID

UUID=<your uuid> /mnt/e ntfs auto,users,uid=1000,gid=1000,dmask=027,fmask=137 0 0

6

Might not be a good solution , but you can always map user id to your own one , or the group id:

Just an example here , my user id was 1000

/dev/sda5 /mnt/excess ntfs defaults,uid=1000,rw 0 0

In that case , all files mounted owned by user ided 1000

2
  • 1
    That works, but with or with out the "rw" option, it still mounts with permissions drwxrwxrwx
    – Amanda
    Mar 17, 2012 at 14:10
  • This works for me. For the permissions, I added to fstab file_mode=0770,dir_mode=0770 Mar 1, 2016 at 11:22
5

Note that if you mount your ntfs drive using a label and wish to be able to change the permissions of directories or files on this drive then the following works well (edit the /etc/fstab e.g. sudo nano /etc/fstab and then add):

LABEL=Portable_HD_2TB      /media/mintbox2/Portable_HD_2TB ntfs    permissions,defaults        0       2

Whereas the below would NOT allow you to change permissions of directories or files:

LABEL=Portable_HD_2TB      /media/mintbox2/Portable_HD_2TB ntfs    defaults        0       2
0

Starting with Linux kernel version 5.15 (so Ubuntu 22.04 and newer, plus older LTS releases by way of HWE), a new NTFS implementation is available, called ntfs3. For the most part, just changing ntfs-3g to ntfs3 in fstab entries or mount commands seems to work fine. This one natively supports POSIX permissions without needing additional mount options, so the behaviour there is a bit different, even if the options work.

Setting up a test filesystem:

dd if=/dev/zero of=/tmp/foo bs=1M count=100
sudo losetup -f /tmp/foo
sudo mkntfs /dev/loop0

Then:

% mkdir ntfs-test
% sudo mount /dev/loop0 -t ntfs3 ntfs-test
% df -hT ntfs-test                   
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/loop0     ntfs3  100M  2.5M   98M   3% /home/muru/ntfs-test

Permissions in action:

% touch ntfs-test/{executable,not-executable}
% chmod uo+x ntfs-test/executable 
% ls -l ntfs-test 
total 0
-rwxr--r-x 1 muru muru 0 Jan 30 21:09 executable
-rw-r--r-- 1 muru muru 0 Jan 30 21:09 not-executable
% sudo chown nobody:gdm ntfs-test/not-executable
% ls -l ntfs-test 
total 0
-rwxr--r-x 1 muru   muru 0 Jan 30 21:09 executable
-rw-r--r-- 1 nobody gdm  0 Jan 30 21:09 not-executable

The fmask, dmask and umask options are still supported, but only affect newly created files. Existing files and directories from Windows seem to get a mode of r-x (no write) for everybody.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .