67

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

sudo chown user:user ldlinux.sys

When that is executed, however, terminal gives this error:

Operation not permitted

The extended chat I had with the user can be found here.

4
  • 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, 2015 at 16:56
  • I think the USB is mounted read-only. Ask OP to check mount options via mount.
    – muru
    Sep 17, 2015 at 17:30
  • AFAIK it is (users:username) not just the user
    – userDepth
    Sep 23, 2016 at 19:27
  • users:username ?? it is user:group
    – gaoithe
    Mar 25, 2020 at 17:03

1 Answer 1

67

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 % 
7
  • 3
    Thanks for the explanation. I forget it again and again. ;)
    – A.B.
    Sep 18, 2015 at 5:27
  • 35
    I get: chattr: Inappropriate ioctl for device while reading flags on 64GB, while trying this on a usb thumb drive at /media/ Jun 20, 2016 at 15:02
  • 3
    For me, the "a" (Append only) flag was the problem. sudo chattr -a fileName solved the problem. Sep 20, 2016 at 15:42
  • 7
    +1, but fails for some files (not just symlinks), even running as root sudo chattr -i returning chattr: Operation not supported while reading flags. Oct 16, 2017 at 16:35
  • My USB has msdos filesystem. Found this: unix.stackexchange.com/questions/552121/… so I went ahead and reformatted as ext4 per askubuntu.com/questions/149984/… Oct 25, 2020 at 19:39

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