Ubuntu – Cannot write to NTFS data partition possibly because of lack of permissions

18.04fstabmountntfspermissions

I have Ubuntu 18.04 installed on a SSD with a larger separate HDD with 1 partition that contains Windows 10 and another NTFS partition that I use for storing all sorts of data. I have added the NTFS data partition to mount at startup using the Disks Utility in Ubuntu, it auto mounts just fine but only has read access. I would like to have this partition also have write access from Ubuntu. But I cant figure out how. (Fast Startup in Windows 10 is disabled)

Heres my fstab file (The last entry, dev/sdb4, is the NTFS data partition):

# /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/sda3 during installation
UUID=0e4a3e97-171f-4c96-9260-e2eb217f4302 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda2 during installation
#UUID=1022-A48D  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda1 during installation
UUID=c59f57b3-26c6-4fb1-82ae-29e676a973b1 none            swap    sw              0       0
UUID=1022-A48D  /boot/efi   vfat    defaults    0   1
/dev/sdb4 /mnt/sdb4 auto defaults,x-gvfs-show 0 0

These are the permissions for this partition

permissions for partition

Also please explain how this drive can be added to the Favorites (the side bar which shows the running apps or apps that you have marked as favorite) in 18.04?

Best Answer

By default, unless the partition being mounted is an ext2/3/4 partition or a partition that can handle UNIX style permissions (such as Mac HFS/HFS+ partitions), the drive gets mounted as root:root for user/group ownership by default. exFAT/FAT/FAT32/NTFS do not support UNIX style permissions, so you can't use these types of permissions.

As such, you have to set permissions at mount to what you need them to be. There're a lot of different options that you could set, but we'll borrow some from my other answer on how to mount NTFS so it can be read by any user but adapt it for your user only.

First, we need to get some information. You will need to run the id command, in the terminal. This will give us some information we will need when we construct the mount points, namely your uid and gid. Below is the example of such output from my own laptop, though yours will probably differ substantially:

$ id
uid=1000(teward) gid=1000(teward) groups=1000(teward),4(adm),6(disk),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare),132(sbuild),137(lxd),140(wireshark),998(pgadmin4)

Of relevance in this specific instance is the uid and gid values, which in my case are 1000 for both. Yours might differ, but we'll need to keep these values handly.

Next, let's restructure your /etc/fstab line. Your system has done auto for detecting the external disk, which is fine, but there's a small issue with this - this relies on the OS being able to determine the type of file system on disk. So we'll replace that with ntfs.

This makes the following the beginning of your /etc/fstab line:

/dev/sdb4 /mnt/sdb4 ntfs

The key part of what you need to do now, though is adjust the options for mounting. defaults is a good start point but not what you need. Ideally, you should have the following additional options in your options:

 locale=en_US.utf8,windows_names,umask=7000,uid=UID,gid=GID

Note that you need to replace UID and GID in the uid= and gid= lines with the numeric uid and gid values we got earlier from id.

Because you might wonder what these options do, let me pull my explanation with some edits from my other answer:

  • locale=en_US.utf8 - enforces the US English locale with UTF8
  • windows_names - enforces that Windows name restrictions are in place for new files in the partition.
  • umask=7007 - Basically, inverse chmod. Define what permissions are not permitted for files. Essentially, I don't prohibit anything read/write/execute here except for 'other users' than yourself, so all files on the mounted location get, effectively, read, write, and execute privileges for your user. I don't want any of the special bits set (setuid, setgid, sticky), so I have to eliminate them from the first octet - since the numeric sum of those is a '7' and i'm prohibiting those permissions, I put a leading 7.
  • uid=1000, gid=1000 - Have the partition mounted into that folder with user and group ownership of UID (User ID) and GID (Group ID) of 1000 (this is my user's user and group, teward, on the Ubuntu system).

Adding these to the options line will allow your external device to be compliant with your Windows dual boot with file naming, and also enforce UTF8. It'll also set permissions properly, so that your user only can have read/write on the partition. This makes your /etc/fstab line this:

/dev/sdb4 /mnt/sdb4 auto defaults,x-gvfs-show,locale=en_US.utf8,windows_names,umask=7000,uid=UID,gid=GID 0 0

We don't need to do anything with the last two zeroes, that's OK to leave there. Just make sure you updated the GID and UID values to the actual values.

Then, use sudo umount /dev/sdb4 && sudo mount /dev/sdb4 to unmount and remount the partition with the new options. You should then have read/write privileges on the entire disk now.