51

I am trying to help a user solve an issue with a bootable USB drive, but there seems to be a file that's ownership cannot be edited. I thought it would have been possible with:

sudo chown users:username ldlinux.sys

But when that is executed it gives this error:

Operation not permitted

Is there a way to change the owner? If you want to see the thread chat that I was having with the OP, go here.

  • 4
    Maybe checking ACLs is an option? I commented on the original question and asked for the output of getfacl ldlinux.sys – Byte Commander Sep 17 '15 at 16:56
  • I think the USB is mounted read-only. Ask OP to check mount options via mount. – muru Sep 17 '15 at 17:30
  • AFAIK it is (users:username) not just the user – userDepth Sep 23 '16 at 19:27
52

Probably the file has the immutable flag set in its extended attributes:

user@user-X550CL ~/tmp % touch immutable
user@user-X550CL ~/tmp % sudo chown root:root immutable
[sudo] password for user:
user@user-X550CL ~/tmp % sudo chattr +i immutable
user@user-X550CL ~/tmp % lsattr immutable
----i--------e-- immutable
user@user-X550CL ~/tmp % sudo chown user:user immutable
chown: changing ownership of 'immutable': Operation not permitted

To fix this, just run sudo chattr -i file:

user@user-X550CL ~/tmp % sudo chattr -i immutable
user@user-X550CL ~/tmp % lsattr immutable
-------------e-- immutable
user@user-X550CL ~/tmp % sudo chown user:user immutable
user@user-X550CL ~/tmp % 
  • 2
    Thanks for the explanation. I forget it again and again. ;) – A.B. Sep 18 '15 at 5:27
  • 21
    I get: chattr: Inappropriate ioctl for device while reading flags on 64GB, while trying this on a usb thumb drive at /media/ – TenLeftFingers Jun 20 '16 at 15:02
  • 3
    For me, the "a" (Append only) flag was the problem. sudo chattr -a fileName solved the problem. – Jonathan Parent Lévesque Sep 20 '16 at 15:42
  • 3
    +1, but fails for some files (not just symlinks), even running as root sudo chattr -i returning chattr: Operation not supported while reading flags. – Brent Faust Oct 16 '17 at 16:35

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