Bobcares

restorecond: Will not restore a file with more than one hard link

by | Mar 25, 2021

Stuck with restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory? We can help you.

Restore SELinux Context (restorecon) is a command that will reset the SELinux security context for files and directories to its default values. However, it only resets the type attribute of SELinux context.

Here at Bobcres, we often handle similar errors as apart of our Server Management Services. Today let’s see how our Support Engineers fix this issue for our customers.

When do we get ‘restorecond: Will not restore a file with more than one hard link’  in our logs

The Z (uppercase Z) option in the following command will display the SELinux context for a particular file.

# ls -lZ index.html
-rw-rw-r--. centos centos unconfined_u:object_r:user_home_t:s0 index.html

While using the restorecon command, it is not necessary to know the correct original security context for the file. Since restorecond is a daemon that watches for file creation and then sets the default SELinux file context it will figure that out automatically.

The following example will restore the security context of index.html to the proper value.

Here we have reset the type portion of the SELinux context to “httpd_sys_content_t” which is the correct type. Now, apache will be able to serve this file without any error.

# restorecon index.html
# ls -lZ index.html
-rw-rw-r--. centos centos unconfined_u:object_r:httpd_sys_content_t:s0 index.html

At times when we configure restorecond in the system we may end up with the following error message in /var/log/messages in SELinux enabled CentOS or RHEL server:

Mar 21 13:58:43 server restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory
Mar 21 16:14:51 server restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory
Mar 22 13:32:23 server restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory

Cause for this Error

This error occurs due to additional hard link to /etc/resolv.conf file. Under CentOS/RHEL/Fedora, the file /etc/sysconfig/networking/profiles/default/resolv.conf is hard linked with /etc/resolv.conf.

How to fix ‘restorecond: Will not restore a file with more than one hard link’

We can fix this error by resetting the hard link.

To find all hard links, enter the following command:

find / -xdev -samefile /etc/resolv.conf

Sample outputs:

/etc/sysconfig/networking/profiles/default/resolv.conf

This can also be done using the following commands:

# ls -i /etc/resolv.conf

45383698 /etc/resolv.conf

# find /etc/ -inum 45383698

/etc/sysconfig/networking/profiles/default/resolv.conf
/etc/resolv.conf

# lsof | grep /etc/resolv.conf

Alternatively, we can use the following commands:

# rm /etc/sysconfig/networking/profiles/default/resolv.conf
# restorecon /etc/resolv.conf
# ln /etc/resolv.conf /etc/sysconfig/networking/profiles/default/resolv.conf

[Need Assistance? We are available 24*7]

Conclusion

In short, we saw how our Support Engineers fix this ‘restorecond: Will not restore a file with more than one hard link ‘ error for our cutomers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.