NTFS-3g: preserve permissions, ignore uid/gid?

Asked by danmb on 2012-12-07

What NTFS mount options would preserve permissions, while giving ownership to a single user?

I want to back up my home folder to an extern NTFS HDD (via rsync, not tar!), but

mount -o permissions,uid=dan,gid=dan

is equivalent to chmod a+rwx both when creating new files, and when accessing old ones (apparently "-o permissions" is ignored with uid=/gid=), while

mount -o permissions

makes the owner to root:root for all files (rendering them unwritable for unprivileged users).

Mounting as a user does not work either (in Ubuntu):

"Either mount the volume as root, or rebuild NTFS-3G with integrated
FUSE support and make it setuid root. Please see more information at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged"

Any way to achieve this very reasonable goal?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu ntfs-3g Edit question
Assignee:
No assignee Edit question
Solved by:
danmb
Solved:
Last query:
Last reply:
Revision history for this message
danmb (danmbox) said :
#1

To clarify, I want to copy file from Linux to Windows (and sometimes restore them) -- I don't care about preserving Windows ACL's, as the drive will seldom (but not never) be used with Windows. I care about not losing Linux "rwx" permissions.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

Windows ACLs are not appreciated in Linux. The file system is proprietary to Microsoft and in no way published. NTFS-3G is a best effort attempt to give access to NTFS. You set the ACL at mount time and it will apply to all files and folders.

If the NTFS partition is an internal partition, I suggest you add it to /etc/fstab so that it not only automounts but you can also set the ACL and so forth as you wish.

Revision history for this message
N1ck 7h0m4d4k15 (nicktux) said :
#3

Hi ,

try the pysdm program. Is a good GUI program to manage the /etc/fstab and "play" with permissions.

Picture : http://i.stack.imgur.com/3SCHE.png

Also you can use ntfs-config program to enable write support , at NTFS filesystem

Picture : http://i.stack.imgur.com/efEF5.png

Install pysdm from terminal

sudo apt-get install pysdm

Install ntfs-config from terminal

sudo apt-get install ntfs-config

Thanks

Revision history for this message
danmb (danmbox) said :
#4

That's not what I asked for. I want Linux permissions (rwx for oug) to be preserved when copying files to NTFS, AND I want all users to appear owned by a certain (non-root) uid/gid.

NTFS-3g can already do BOTH things separately (setting uid/gid to non root AND preserving permissions). It seems that (due to bad design) NTFS-3g prevents you from achieving both simultaneously.

Permissions are preserved with "mount.ntfs-3g -o permissions", BUT in that case all files are owned by root.

If instead I use "mount -o permissions, uid=500,gid=500", then the owner is non-root, but all permissions are lost when copying to NTFS (and chmod is ignored).

Does this make it clearer?

Revision history for this message
danmb (danmbox) said :
#5

@NikTh: thanks, but pysdm didn't output anything better (it suggested uid=500,gid=500 WITHOUT the permissions option -- which sets all permissions to a+rwx and ingores chmod, just as WITH the permissions option). It seems that setting uid/gid silently disables the permissions option, for no apparent reason (other than bad design I presume).

Again, "-o permissions" with no uid/gid option preserves permissions (but leaves all files owned by root). It also prints

Using default user mapping

which makes me think that perhaps I should create some dummy user map to please ntfs-3g's logic.

ntfs-config doesn't help either as my device already has writing enabled.

Revision history for this message
N1ck 7h0m4d4k15 (nicktux) said :
#6

The program I suggested is nothing else , but a GUI program for /etc/fstab. It is not auto-fill the correct permissions.

This is not a problem with ntfs-3g or Linux , but with Microsoft's closed filesystem. NTFS does NOT support Linux-filesystems permissions.

You have to play in /etc/fstab , with uid , guid and umask to achieve your goal.

Please read these 2 tutorials
http://ubuntuforums.org/showthread.php?t=1604251
http://ubuntuforums.org/showthread.php?t=283131

Thanks

Revision history for this message
danmb (danmbox) said :
#7

A tutorial on fstab? Thanks, I have had Linux on the desktop for 18 years.

Read the man page for mount.ntfs-3g -- there is a permissions option:

       permissions
              Set standard permissions on created files and use standard access control. This option is set by
              default when a user mapping file is present.

I can achieve perfect permission preservation if I

mount -o permissions /dev/sdb1 /vol/exthd/

OR equivalently, in /etc/fstab (in case you don't know what the mount command does)

/dev/sdb1 /vol/exthd auto noauto,permissions 0 0

After mount-ing (in a terminal, not from a GUI) mount prints the following:

Using default user mapping

The remaining problem is that all files are owned by root in this case.

Unfortunately, as I wrote (and you don't seem to have read, or understood), once I add uid= and gid= mount options, mount silently ignores the "permissions" option. I think in its infinite wisdom NTFS-3g wants me to provide a usermap file to achieve my simple use case.

Thanks for trying to help anyway. I'm probably asking questions in the wrong forum, judging from the newbie-targeted replies I got.

Revision history for this message
N1ck 7h0m4d4k15 (nicktux) said :
#8

Well ,

instead of drawing conclusions about the Launchpad Answers Tracker (is not exactly a Forum) , try this command in terminal

mount -o uid= guid= umask=000 /dev/sdb1 /vol/exthd/

fill the uid= and guid= , with appropriate numbers.

Thanks

Revision history for this message
danmb (danmbox) said :
#9

That sets all permissions to a+rwx. First, here's how it (correctly) works with -o permissions:

root# mount -o permissions /dev/sdb1 /vol/exthd
Using default user mapping
root# touch /vol/exthd/x
root# ls -al /vol/exthd/x
-rw--w--w- 1 root root 0 Dec 8 00:29 /vol/exthd/x
root# chmod u+x /vol/exthd/x
root# ls -al /vol/exthd/x
-rwx-w--w- 1 root root 0 Dec 8 00:29 /vol/exthd/x
root# rm /vol/exthd/x

So chmod woks -- and so does cp:

root# ls -al /bin/bash
-rwxr-xr-x 1 root root 920788 Apr 3 2012 /bin/bash
root# cp -a /bin/bash /vol/exthd/
root# ls -al /vol/exthd/bash
-rwxr-xr-x 1 root root 920788 Apr 3 2012 /vol/exthd/bash
root# umount /vol/exthd

Now with your mount options (note, using gid= instead of gUid= as you wrote):

root# mount -o uid=500,gid=500,umask=000 /dev/sdb1 /vol/exthd/
root# touch /vol/exthd/x
root# ls -al /vol/exthd/x
-rwxrwxrwx 1 muresan muresan 0 Dec 8 00:29 /vol/exthd/x
root# chmod u-x /vol/exthd/x
root# ls -al /vol/exthd/x
-rwxrwxrwx 1 muresan muresan 0 Dec 8 00:29 /vol/exthd/x

So chmod is ignored and all permissions are fixed to rwx. If I try -o permissions,uid=500,gid=500,umask=000 it also doesn't work (because uid= and gid= seem to disable permissions)

Revision history for this message
N1ck 7h0m4d4k15 (nicktux) said :
#10

You have to try again with uid gid and umask.

Let me write the permissions of umask (in case you don't know)

umask Octal value permissions

0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions

The format is umask=UGO (UserGroupOthers)

So the umask=000 set permissions read,write,execute to everyone.

Another thing. Are you sure that your uid is 500 ?
Lets see

echo $UID

maybe is 1000 ? so the uid=500 should be uid=1000 and gid=1000 in order for you to take the ownership ?

An example of the correct command , could be

mount -o uid=1000,gid=1000,umask=077 /dev/sdb1 /vol/exthd

Thanks

Revision history for this message
danmb (danmbox) said :
#11

Have you actually read my previous shell log to the end? Because in the 3rd paragraph (out of 3) I tried your mount options with (umask=000), and shown you that chmod u-x is ignored in this case.

I showed you first what the correct behavior (with -o permissions) is (in the first 2 paragraphs). I guess you read just the beginning of the post and figured that I hadn't try your mount options.

No point in changing umask=000 to umask=077 (i.e. only the G and O parts of the permissions) since I've already shown you that the U part of the permission isn't being respected.

I've tried it regardless, and of course chmod u-x still doesn't work.

Also, I wonder why you would care about my UID (it is 500, I've kept it ever since my Redhat installation many years ago). The shell log I provided clearly shows a root prompt (i.e. all commands were executed as root). I could have used uid=10, 256 or whatever else and the point about chmod being ignored by NTFS-3g would STILL apply.

Revision history for this message
danmb (danmbox) said :
#12

NikTh, thanks for trying to help, but it looks like I'm not getting any information beyond what I've already known when posting the question. Perhaps I should have started with a shell log instead of assuming the problem is clear.

I've filed a LP bug report. I wish I could access the NTFS-3g support forums instead, but their hoster's captcha server seems to be broken (besides providing unreadable captchas).

Revision history for this message
danmb (danmbox) said :
#13

As per the linked bug, it is indeed impossible to use both -o permissions and -o uid/gid.

However, it turns out that using "-o permissions" alone preserves both the owner and the permissions. This works, unless the drive is accessed by Windows; Windows will create NTFS owners invisible to Linux, which will get mapped to root.