Are you facing restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory?
This guide will 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 Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix Linux related errors.
In this context, we shall look into how to fix Ubuntu errors.
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
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.
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
This article covers Tips to fix 'restorecond: Will not restore a file with more than one hard link' error.
To fix this problem type 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