How can I access an external NTFS hard drive?

I try to access an external hard drive with an ntfs filesystem from NixOS.

Is it correct that I have to create a mounting point? Where do you usually create a mounting point?

sudo mkdir -p /media/b/TDrive
sudo chmod a+rwx /media{,/b,{/TDrive}}
sudo chown -R b:users /media

and everything looks good:

$ ls -ld /media/b/TDrive
drwxrwxrwx 2 b users 4096 Oct 21 11:42 /media/b/TDrive

But when I mount the external hdd, the permission and ownership change.

$ sudo mount /dev/sdb1 /media/b/TDrive
$ ls -ld /media/b/TDrive/
dr-x------ 1 root root 4096 Oct 18 15:02 /media/b/TDrive/
$ cd /media/b/TDrive/
bash: cd: /media/b/TDrive/: Permission denied

What can I do?

The above problem doesn’t happen on another computer running Ubuntu.

1 Like

You might want to check the mount options for your FS. I remember there was uid and gid options for ntfs.

1 Like

I think everything you were trying to do was right, and probably the only piece missing is to enable NTFS support in your NixOS configuration (see the NTFS topic in the NixOS wiki). Also, it’s probably easier to use udiskctl for the whole mount/unmount dance (the Arch wiki is very comprehensive about this topic as well).

This is what I did just now to make my external NTFS drive work:
… and thank you for the inadvertent reminder, because I’ve been putting to set this up for almost a year now

  1. Add the line

    boot.supportedFilesystems = [ "ntfs" ];

    to your /etc/nixos/configuration.nix.

  2. Issue

    sudo nixos-rebuild switch
  3. Look up the device name after plugging in the drive with lsblk -f

    $ lsblk -f
    NAME                 FSTYPE      FSVER    LABEL   UUID                                   FSAVAIL FSUSE% MOUNTPOINT
    ├─sda1               vfat        FAT32    boot    B76B-5E4E                               950.1M     7% /boot
    └─sda2               crypto_LUKS 2                da9f2329-e45f-4302-b77a-76f47a3e8f52
      └─luksroot         LVM2_member LVM2 001         3dvt1U-SFAS-U748-XE8k-Bee4-aDsl-wO3Riq
        ├─nixos--vg-swap swap        1        swap    5f759738-c391-45c9-909c-c4b7e598d9ab                  [SWAP]
        └─nixos--vg-root ext4        1.0      nixos   5fca3daa-c09b-4c69-ae09-930885391516     49.2G    77% /
    └─sdc1               ext4        1.0      florist 7c3cdb62-f004-404f-b884-9aab75e2e302    127.6G    67% /run/media/toraritte/florist
    └─sdd1               ntfs                 syzygy  074A09192B639D32
  4. Mounted it with

    udisksctl mount -b /dev/sdd1

Filesystems are usually mounted and then the user metadata of the filesystem is applied, though NTFS userdata can not be transfered to the linux model, therefore it assumes everything is owned by root and and usually RO.

If you want to use mount you have to also specify uid and gid options as well as a third option that works similar to a umask.

Personally I consider not using NTFS (permanent mounts) or just using udisks2 (temporary mounts) the best options.

1 Like

If you’re sharing files between NTFS in windows and Linux, I would recommend using ntfsusermap so windows isn’t confused by access rights, otherwise you can use uid and gid (as others have said) and in combination with umask.