/usr/bin/chcon: failed to create security context: : Invalid argument

The Problem

During boot, a message related to SELinux appeared in the console log as shown below:

/usr/bin/chcon: failed to create security context: : Invalid argument

The Solution

To reflect the SELinux target policy, the target directory that stores the compiled SELinux policy must exist under the /etc/selinux directory. For the “targeted” directory that stores compiled SELinux policies, the selinux-policy and selinux-policy-targeted RPM packages must be installed. The following message means that SELinux can not find the ’target/’ directory where the SELinux policy is stored.

Aug 7 14:18:33 kernel: dracut: Loading SELinux policy
Aug 7 14:18:33 kernel: dracut: SELinux: Could not open policy file <= /etc/selinux/targeted/policy/policy.26: No such file or directory <<<<<<<<<<<<<<< There is no selinux policy target file in /etc/selinux directory
Aug 7 14:18:33 kernel: dracut: Switching root
Aug 7 14:18:33 kernel: udev: starting version 147

If the selinux-policy and selinux-policy-targeted packages are not installed, the “targeted/” directory is not created in /etc/selinux/ where the SELinux policy information is stored.

1. To determine which RPM package would supply the necessary files, do this:

# yum provides /etc/selinux/targeted/policy

2. This should return at least one RPM package name. Install the RPM packages as indicated:

# yum install selinux-policy-targeted

3. You need to also install “selinux-policy” as a prerequisite.

# yum install selinux-policy

4. Reboot to verify the solution.

# shutdown -r now