Solved chflags failed: "Operation not permitted"

Hello,

usually chflags clears the "Operation not permitted" error. But here, chflags itself fails to do its job:

# chflags noschg librt.so.1
chflags: librt.so.1: Operation not permitted


What can I try next?
 
  • I assume you're doing that as the root user, right?
  • What is your security level? sysctl kern.securelevel
  • Are you sure that the file system is mounted read+write (not read-only)? What file system is this (UFS, ZFS, …)?
  • What is the output of ls -lo librt.so.1?
 
Yes, I tried as root.
kern.securelevel = -1
UFS volume was mounted rw
ls -lo librt.so.1 showed that the schg flag was set.

Meanwhile, I was able to find a solution. I rebooted into single user mode and then was able to clear the schg file's flag.
 
But the question remains why you were unable to do that in normal mode (multi user). Actually there are only few things that could cause chflags fail with EPERM under such circumstances. Typically it is caused by a raised security level – this requires you to reboot into single user mode. Other possible causes are:
  • missing privileges (i.e. not running as root)
  • running within a jail
  • a MAC policy in effect, for example mac_bsdextended(4).
 
Back
Top