skip to Main Content

I’m using Centos 8.0 and my kernel version:
4.18.0-147.5.1.x86_64

Backgroud:
The messages on my host not rotated for a long time,and when I use "logrotate -v -f" to force rotating messages, it shows "rename messages: Operation not permitted".So I try renaming the messages immediately.

-rw-------    1 root    15464299992 Jul 15 10:12 messages
-rw-------    1 root       11644353 Sep  7  2020 messages-20200907.gz
-rw-------    1 root        8834073 Sep 13  2020 messages-20200913.gz
renaming /var/log/messages to /var/log/messages-20210715
error: failed to rename /var/log/messages to /var/log/messages-20210715: Operation not permitted

Here is my operation and the terminal’s output:

[root@node-5 log]# mv messages messages-20210715
mv: cannot move ‘messages’ to ‘messages-20210715’: Operation not permitted
[root@node-5 ~]# whoami
root

I login as root,why do I still come across such problem? How can I solve this?

2

Answers


  1. Chosen as BEST ANSWER

    @DavidC.Rankin Thx for replying.Here is the ls -ald . for messages:

    [root@node-5 log]# ls -ald
    drwxr-xr-x. 30 root 8192 Jul 15 11:14 .
    

    So I don't think this may be a problem about permissions. I also used strace to follow the syscall:

    stat("messages2", 0x7fff6c37aae0)       = -1 ENOENT (No such file or directory)
    lstat("messages", {st_mode=S_IFREG|0600, st_size=15464637645, ...}) = 0
    lstat("messages2", 0x7fff6c37a790)      = -1 ENOENT (No such file or directory)
    renameat2(AT_FDCWD, "messages", AT_FDCWD, "messages2", 0) = -1 EPERM (Operation not permitted)
    

    Unfortunately,there are too many branches in function do_renameat2 so I haven't found the exact exit yet.


  2. The problem got solved:
    Show the file attributes with lsattr, it seems that messages got an attribute ‘a’,so it can’t be renamed.

    ---------------- ./maillog-20201004
    -----a---------- ./messages
    

    And with command chattr -a messages,messages can be renamed again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search