89

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.

David
  • 3,485
  • 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
  • users:username ?? it is user:group – gaoithe Mar 25 '20 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 '22 at 15:08

1 Answers1

78

The file might have the immutable flag (i) set in its extended attributes:

% stat -c '%04a %U %G' ldlinux.sys
0644 root root
% lsattr ldlinux.sys
----i----------------- ldlinux.sys
% sudo chown dev: ldlinux.sys
chown: changing ownership of 'ldlinux.sys': Operation not permitted

If that's the case, run:

sudo chattr -i ldlinux.sys
% sudo chattr -i ldlinux.sys
% lsattr ldlinux.sys
---------------------- ldlinux.sys
% sudo chown dev: ldlinux.sys
%
kos
  • 41,378
  • 42
    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
  • 16
    +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
  • My USB has msdos filesystem. Found this: https://unix.stackexchange.com/questions/552121/chattr-inappropriate-ioctl-for-device-while-reading-flags so I went ahead and reformatted as ext4 per https://askubuntu.com/questions/149984/formatting-usb-flash-memory-for-ubuntu-ext4 – harperville Oct 25 '20 at 19:39
  • 2
    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: https://askubuntu.com/a/956072/612853 – AvahW Aug 16 '21 at 09:28
  • Thanks kos, this solved it for me just now.. But, man chattr doesn't even list -i as an option! So, thanks again. – linstar Dec 30 '21 at 02:44