80

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.

5
  • 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
  • Check your id. This error can appear if your user by some reason was assigned to another group. In normal situation id should look like this uid=1000(username) gid=1000(username) groups=1000(username). You can check and change it in /etc/passwd file as well.
    – Dzintars
    Dec 23, 2022 at 15:08

1 Answer 1

76

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 % 
6
  • 39
    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
  • 13
    +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
  • 1
    You get the Operation not supported error when trying to mount a Windows filesystem (exFat/NTFS) with incorrect mount options. You can either reformat your drive to ext4, or simply change the mount options with this answer: askubuntu.com/a/956072/612853
    – AvahW
    Aug 16, 2021 at 9:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .