Unable to Change NTFS Ownership [SOLVED — see rene's answer]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Unable to Change NTFS Ownership [SOLVED — see rene's answer]

Post by WadeWayne »

Image
/mnt/sda3/ is my NTFS Windows 10 partition. (I've dual-booted Windows 10 and Linux Mint 19.3.)




Image
I've edited /etc/fstab to auto-mount my Windows 10 partition on start-up.



Now let me get to the "Unable to Change NTFS Ownership" part.
I want to change the ownership of the file named DELETE.

Image
As you can see in the screenshot, sudo chown -v wadewayne:wadewayne DELETE outputs that it successfully changed the ownership from root to wadewayne, but ls -al ouputs that it is still owned by root.

:( PLEASE HELP!!!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
User avatar
all41
Level 19
Level 19
Posts: 9473
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Unable to Change NTFS Ownership

Post by all41 »

NTFS does not recognise ownership and permissions.
But since the mountpoint is created by root then root is the owner of the mountpoint.
Change like this:
sudo chown -R wadewayne:wadewayne /mnt/sda3
Everything in life was difficult before it became easy.
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

all41 wrote: Mon Apr 12, 2021 10:09 am Change like this:
sudo chown -R wadewayne:wadewayne /mnt/sda3
:( Didn't work.
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

WadeWayne wrote: Mon Apr 12, 2021 9:27 am I want to change the ownership of the file named DELETE.
NTFS doesn't support ownership and/or permissions (not at a normal, basic level at least) even though those concepts are fundamental to the POSIX filesystem framework that UNIX systems use. So as to be able to still fit NTFS into said framework Linux simply "fakes" ownership and permissions: when you mount the filesystem as root, by default all files and directories on it will appear as themselves owned by root and with some given default set of permissions. You can adjust either on a per-mount basis by supplying the options e.g. uid=wadewayne,gid=wadewayne and fmask=133,dmask=022 at mount time. See man mount.ntfs-3g. What you can not do is have actual per-file/directory ownership and/or permissions on NTFS. For that you will need to use a filesystem that in fact supports those concepts.

I.e., practically, mount with those given uid=,gid= parameters or just delete with sudo.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

I had by the way planned to in the follow-up lessen my own claim of NTFS not supporting ownership/permission concepts a bit again (but not originally go into any detail since the above is still very much the idea here) but if there is no follow-up...

Note from the advised manpage that you can get NTFS ownership/permission functional via e.g. user mapping but that this is to be considered the fringe case: useful for professional systems in a mixed UNIX/Windows environment but for a home user with also on Windows no knowledge nor use of filesystem permissions beyond Windows defaults, besides the point. Said point being NTFS having no support for the basic, POSIX-style multiuser credentials that UNIX systems use...
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

rene wrote: Mon Apr 12, 2021 1:39 pm You can adjust either on a per-mount basis by supplying the options e.g. uid=wadewayne,gid=wadewayne and fmask=133,dmask=022 at mount time. See man mount.ntfs-3g.
:arrow: Screenshot of my /etc/fstab contents:
Image

:arrow: Texts from the screenshot:

Code: Select all

wadewayne@Cheetah:~$ cat /etc/fstab 
# /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/sda7 during installation
UUID=540bdf00-1b26-4390-9232-ed41e4161a2c /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=4415-FB09  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0

#Windows 10 OS partition
UUID=9EB6973BB697133F    /mnt/sda3 ntfs defaults  0     2

Should I replace defaults with uid=wadewayne,gid=wadewayne and fmask=133,dmask=022? :D

:?: And what do "fmask=133,dmask=022" mean?
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

WadeWayne wrote: Tue Apr 13, 2021 5:50 am Should I replace defaults with uid=wadewayne,gid=wadewayne [ ... ]
Iff you want files and directories on that NTFS filesystem to appear and by treated by Linux as being owned by wadewayne:wadewayne, yes.
WadeWayne wrote: Tue Apr 13, 2021 5:50 am [ ... ] and fmask=133,dmask=022? :D
If you don't care for the standard all-access permissions that are set by default, yes. If nothing else has an ls -l not scream at you so much visually...

As the mentioned man page details, fmask and dmask together are a more focussed version of umask and determine which permissions are not present on respectively files and directories. On Linux permission 644 for files (rw-r--r--) and 755 (rwxr-xr-x) for directories are "the most normal"; the suggested 133 resp. 022 are their octal complements. Feel free to not have these options or adjust them to liking but the suggested values have things behave more or less sanely even on NTFS.

Code: Select all

UUID=9EB6973BB697133F	/mnt/sda3	ntfs-3g	noexec,uid=wadewayne,gid=wadewayne,fmask=133,dmask=022
Note; I tend to use type ntfs-3g instead of plain ntfs due to historically latter being a read-only kernel-based filesystem driver, former the same NTFS-3G userspace FUSE filesystem driver as today --- even though these days and on Ubuntu/Mint ntfs is in fact a mere alias for ntfs-3g. It's still sightly too soon in the context of Linux as a whole to not at least be aware of that historic difference.

The noexec parameter makes it so that execute permissions on files are actually ignored anyway (and certainly makes for a reason to then also as a matter of consistency set the fmask as per above). Why you'd want it is as a poor man's security measure: it disallows blindly executing in Linux something e.g. downloaded in Windows. Take it out if you don't care for it --- and if indeed you don't, perhaps have the fmask be e.g. 755 as well, of course.
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

rene wrote: Tue Apr 13, 2021 6:26 am If you want files and directories on that NTFS filesystem to appear and by treated by Linux as being owned by wadewayne:wadewayne, yes.
It worked! wadewayne owns the NTFS partition now.

:arrow: Here's my updated /etc/fstab:

Code: Select all

wadewayne@Cheetah:~$ cat /etc/fstab 
# /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/sda7 during installation
UUID=540bdf00-1b26-4390-9232-ed41e4161a2c /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=4415-FB09  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0

# Windows 10 OS partition
UUID=9EB6973BB697133F    /mnt/sda3 ntfs defaults,uid=1001,gid=1001  0     2
:?: Is it OK? Should I remove or add anything?


THANKS SO MUCH FOR YOUR HELP, rene!!!
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

WadeWayne wrote: Tue Apr 13, 2021 6:37 am

Code: Select all

# Windows 10 OS partition
UUID=9EB6973BB697133F    /mnt/sda3 ntfs defaults,uid=1001,gid=1001  0     2
:?: Is it OK? Should I remove or add anything?
I've replaced UUID=9EB6973BB697133F /mnt/sda3 ntfs defaults,uid=1001,gid=1001 0 2 with your code (UUID=9EB6973BB697133F /mnt/sda3 ntfs-3g noexec,uid=wadewayne,gid=wadewayne,fmask=133,dmask=022). :)
Last edited by WadeWayne on Tue Apr 13, 2021 6:59 am, edited 1 time in total.
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

Your version is fine, as long as you are happy with it. Differences with the fstab line that I pasted as a suggestion are:

1. You use uid=1001,gid=1001, i.e., numerically, whereas I would use simply uid=wadewayne,gid=wadewayne, i.e., by name.
2. You don't use the suggested and explained fmask and dmask. That means now everything on the partition appears to have full permissions, including execute, which, well, I can't personally stand visually at the very least.
3. You don't use the suggested noexec. Fine if the explanation didn't jive with you...
4. You do use the 0 2 "freq" and "passno" fields. I'd suggest neither for NTFS, i..e., have them be 0 0, and in that case you may as well leave them both out entirely. The "passno" field is probably functional even for NTFS-3G though, so again, fine.

[EDIT] Actually, no there doesn't seem to be a useable fsck.ntfs by default at least on 19.3, so I'd definitely have that 2 be 0, and again, might as well leave both out entirely then. Also:

5. You still use type ntfs over my suggestion of explicitly ntfs-3g. Okay, okay, if you're not into history...
Last edited by rene on Tue Apr 13, 2021 7:04 am, edited 2 times in total.
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

rene wrote: Tue Apr 13, 2021 6:57 am 3. You don't use the suggested noexec. Fine if the explanation didn't jive with you...
:D I updated the /etc/fstab with your code.
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

Edited in something as to that value 2 and added a point 5 while you were writing. But all well otherwise.
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

WadeWayne wrote: Tue Apr 13, 2021 7:01 am
rene wrote: Tue Apr 13, 2021 6:57 am 3. You don't use the suggested noexec. Fine if the explanation didn't jive with you...
:D I updated the /etc/fstab with your code.

Code: Select all

wadewayne@Cheetah:~$ cat /etc/fstab 
# /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/sda7 during installation
UUID=540bdf00-1b26-4390-9232-ed41e4161a2c /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=4415-FB09  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0



# Windows 10 OS partition
#(myShittyCode) UUID=9EB6973BB697133F    /mnt/sda3 ntfs defaults,uid=1001,gid=1001  0     2 
UUID=9EB6973BB697133F /mnt/sda3 ntfs-3g noexec,uid=wadewayne,gid=wadewayne,fmask=133,dmask=022
Last edited by WadeWayne on Tue Apr 13, 2021 7:20 am, edited 1 time in total.
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Unable to Change NTFS Ownership

Post by rene »

I'd call it perfect. If you are happy with the result, it is.
WadeWayne
Level 2
Level 2
Posts: 94
Joined: Sat Mar 21, 2020 10:08 am
Location: Kepler-438b

Re: Unable to Change NTFS Ownership

Post by WadeWayne »

rene wrote: Tue Apr 13, 2021 7:06 am I'd call it perfect. If you are happy with the result, it is.
I'm VERY happy!
It's perfect!!! :D

THANKS ONCE AGAIN, rene!!! <3
Image
Distro: Linux Mint 19.3
DE: Cinnamon 4.4.8
Locked

Return to “Scripts & Bash”