13

I am running a dual boot of Windows and Debian on my Laptop. I use Linux mostly but from time to time I need to access my files in my Windows partition. My Windows partition is mounted as follows at startup.

>cat /etc/fstab |grep Win7
LABEL=Windows7_OS /mnt/Win7 auto nosuid,nodev,nofail,x-gvfs-show 0 0

Basically every file in the Windows partition is owned by root:root and has a 777 permission. Then whenever I mv a file to my working (Linux) partition, I have a 777 file under my partition, owned by me (while cp in terminal will give a 755 file but if done via gnome will save the file with a 777 permission).

Is this the best practice to mount a partition? Or should I mount it such that instead of root, I am the owner of all files/dirs and somehow be able to set all dirs to 755 and files to 644 when the mount happens at boot? If so, how can it be done?

  • 2
    minor tidbit (uooc...) : grep Win7 /etc/fstab – Olivier Dulac Nov 22 '17 at 12:46
17

You can use fmask and dmask mount options* to change the permission mapping on an ntfs filesystem.

To make files appear rw-r--r-- (644) and directories rwxr-xr-x (755) use fmask=0133,dmask=0022. You can combine this with uid= and gid= options to select the file owner and group if you need write access for your user.

* fmask and dmask seem to work for the kernel (read-only) driver as well, even that they are not documented in mount man page. They are documented options for ntfs-3g.

  • My default umask is 0022 already. But when I mv a file using terminal from Win7 to my home the file is still 777. – albertma789 Nov 22 '17 at 9:56
  • 2
    The fmask and dmask in the answer are mount options. When you change them in fstab and remount the filesystem the files/directories in your Windows filesystem will appear with 644/755 permissions instead of 777/777. – sebasth Nov 22 '17 at 10:05
  • 5
    LABEL=Windows7_OS /media/Win7 auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=Windows,uid=1000,gid=1000,fmask=0133,dmask=0022 0 0 works like a charm. Exactly what I needed! – albertma789 Nov 22 '17 at 13:41
  • Is it possible to set up such defaults for specific filesystems (FAT32/NTFS) rather than specific drives? It'd be nice to have this available when using flash drives and other removable media. – JAB Nov 22 '17 at 15:42
  • 1
7

First of all this is not how you should use /mnt. That is for doing administrative tasks on a file system temporarily not every system boot.

Because the windows partition makes no part of the running of the Linux system it makes sense to mount it under /media. You may also want to consider mounting it under root / as /Windows to avoid any confusion about /media being for removable media.

As for permissions I would use a group called windows

groupadd -g 1001 Windows

and give it the permissions you want with options like:

gid=1001,umask=022

If you want to use cp and maintain permissions between separate file systems use cp with the -p or -a flag.

  • My default umask is 0022 already. But when I mv a file using terminal from Win7 to my home the file is still 777. Mount to /media instead is great suggestion! – albertma789 Nov 22 '17 at 10:02
  • When copying files between file systems the default permissions for that file system is used unless you preserve them. Refer to my updated answer. – jdwolf Nov 22 '17 at 10:36
  • While I agree /mnt is not optimal for the mount point, /media is for removable media (e.g., dvds and USB drives). I am not sure there is a good answer where the mount is supposed to happen: unix.stackexchange.com/questions/29134/… – StrongBad Nov 22 '17 at 14:31
  • @StrongBad The Filesystem Hierarchy Standard is not so standard especially on directories since old Unix ones. For example the FHS 2.3 doesn't reflect the current practices of /run. Look at the FHS 3.0 refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s11.html which further indicates not to use /mnt for this but its rational is much clearer than "technically windows isn't removable media" It's also worth noting that there's nothing wrong with mounting your own directory on / root. – jdwolf Nov 22 '17 at 21:32
4

Using the mount options uid, gid, fmask and dmask you can make the entire NTFS filesystem accessible to your regular user account and/or one group. But that is all-or-nothing: as far as the NTFS filesystem is concerned it's like running as full Administrator all the time in Windows, or like doing everything as root in Linux. The ntfs-3g NTFS filesystem driver can do better than that.

If you're using ntfs-3g, you can use the ntfsusermap command to create a user mapping file for your NTFS filesystem(s). The command will help you in identifying the Windows usernames and their corresponding Windows SIDs and associating them to Linux user and group IDs.

In this way, you can associate the SID of your Windows user account to your Linux UID. That way, once you mount the NTFS filesystem with the user mapping file in place at <NTFS filesystem root>/.NTFS-3G/UserMapping, you can use your regular Linux user account to access the NTFS filesystem exactly as your Windows user account would be able to access. For things you would need Administrator permissions in Windows, you'll still need root in Linux.

This way, you'll get convenient access to your files on the Windows partition, but are still protected from messing up your \Windows directory by a mistyped command, unless you're running as root.

You might also want to use the windows_names mount option on the NTFS partitions to prevent you from accidentally creating files with names that Windows cannot access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.