This is more for my own notes than anything else, but to properly mount NTFS or vfat (i.e. FAT16/FAT32) partitions in Linux, first find the UUID of the drive using:
ls -l /dev/disk/by-uuid
r3dux@r3d-laptop:~$ ls -l /dev/disk/by-uuid total 0 lrwxrwxrwx 1 root root 10 Jul 14 08:40 3f55aec7-b4be-4b51-bce7-ce32ec661eba -> ../../sda2 lrwxrwxrwx 1 root root 10 Jul 14 09:46 669A58CD9A589B7F -> ../../sdb3 lrwxrwxrwx 1 root root 10 Jul 14 08:40 bb15a473-2531-441a-a9d9-a6bbef705a57 -> ../../sda1 lrwxrwxrwx 1 root root 10 Jul 14 08:40 C2B2D3AEB2D3A567 -> ../../sdb2 lrwxrwxrwx 1 root root 10 Jul 14 08:40 c5364a36-80ee-495f-9379-982a2c0397ea -> ../../sda3 lrwxrwxrwx 1 root root 10 Jul 14 08:40 EA26C54026C50E8F -> ../../sdb1
To mount NTFS or vfat partitions properly, you need to specify dmask (directory mask) and fmask (file mask) values, which as you might expect are the MASKS of the values you want to use (i.e. the octal compliments). Yeah, I’m not sure why it’s done this way either, but to calculate the mask value just subtract the value you want from 7.
As long as you know the following you should be just fine:
- Read is 4,
- Write is 2, and
- Execute is 1.
- If you want to mount the drive with 777 permissions (owner, group and other all r+w+x), then the mask of that is 000 – i.e. 7-7 = 0 for read, write and execute
- If you want to mount the drive with 751 permissions (owner r+w+x, group r+x, other x), then the mask is 026 – i.e. 7 – 7 = 0, 7 – 5 = 2, 7 – 1 = 6)
So once you’ve identified your partition, you can add the following to your /etc/fstab file to have it mount automatically on boot:
UUID=<YOUR-UUID-HERE> <DIRECTORY-TO-MOUNT-AT> ntfs uid=<YOUR-UID>,gid=<YOUR-GID>,dmask=<YOUR-DMASK>,fmask=<YOUR-FMASK> 0 0
So if I want to automatically mount my sdb3 partition at boot (which I know is formatted as ntfs) at /media/DATA with 755 permissions (owner r, group r+X, other r+x, i.e. 022 mask), I could use:
UUID=669A58CD9A589B7F /media/DATA ntfs uid=r3dux,gid=r3dux,dmask=022,fmask=022 0 0
For the user ID (uid) or group ID (gid) values, you can use the numerical or actual values, i.e. uid=r3dux,gid=r3dux is fine, as is uid=1000,gid=1000 etc.
The first user account and group ID for any user on a Linux system are generally 1000.
If you’re not sure of your uid or gid values, just enter id in a terminal and it’ll tell you:
r3dux@r3d-laptop:~$ id uid=1000(r3dux) gid=1000(r3dux) groups=1000(r3dux),4(adm),20(dialout),24(cdrom),25(floppy),26(tape),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(netdev),111(fuse),113(lpadmin),116(powerdev),117(scanner),125(vboxusers)
Happy NTFS & vfat automouting ;-)