I’ve recently run into an issue where during a recovery scenario it was necessary to relabel SELinux contexts on RHEL7.1. This is normally done by either placing an empty file at the root of the file system “touch /.autorelabel” or using the “fixfiles onboot” command; both of which I tried in this case. However in this case upon reboot the machine just hung at “Reached Target initrd Default Target” with no sign of even attempting to relabel the filesystem. Doing a bit of troubleshooting isolated the issue to SELinux as adding the “enforcing=0” parameter to GRUB allowed the machine to boot without issue. I tried quite a few different things including setting SELinux to “Permissive” in /etc/selinux/config and then back again, as well as a failed attempt to use “fixfiles restore /” and “restorecon -Rv /” which I’m assuming failed because SELinux was in permissive mode. Until today I’ve never seen a machine that won’t respect the “touch /.autorelabel” nuclear option.
Ok, here’s the fix that I found, odd as it is:
1. Modify GRUB to include “enforcing=0” to allow the OS to boot this first time without SELinux
2. Once inside the OS make sure that /etc/selinux/config is set to enforcing
3. Change the default runlevel from graphical to multi-user (think runlevel 3) with “systemctl set-default multi-user.target”
4. Reboot without modifying GRUB so that selinux is properly enabled on this boot
On the next reboot oddly enough the system recognized that a relabel had been ordered and proceeded as it should have the whole time. After another reboot and setting the default target back to graphical “systemctl set-default graphical.target” and another reboot as a sanity check it’s working as expected again. Very odd problem and I must admit a very odd solution….