blob: 6231790e795bb5ea7a87ffb951b121d6bcea7700 [file] [log] [blame]
xf.li86118912025-03-19 20:07:27 -07001#!/bin/sh
2
3/usr/sbin/selinuxenabled 2>/dev/null || exit 0
4
5CHCON=/usr/bin/chcon
6MATCHPATHCON=/usr/sbin/matchpathcon
7RESTORECON=/sbin/restorecon
8SECON=/usr/bin/secon
9SETENFORCE=/usr/sbin/setenforce
10
11for i in ${CHCON} ${MATCHPATHCON} ${RESTORECON} ${SECON} ${SETENFORCE}; do
12 test -x $i && continue
13 echo "$i is missing in the system."
14 echo "Please add \"selinux=0\" in the kernel command line to disable SELinux."
15 exit 1
16done
17
18check_rootfs()
19{
20 ${CHCON} `${MATCHPATHCON} -n /` / >/dev/null 2>&1 && return 0
21 echo ""
22 echo "* SELinux requires the root '/' filesystem support extended"
23 echo " filesystem attributes (XATTRs). It does not appear that this"
24 echo " filesystem has extended attribute support or it is not enabled."
25 echo ""
26 echo " - To continue using SELinux you will need to enable extended"
27 echo " attribute support on the root device."
28 echo ""
29 echo " - To disable SELinux, please add \"selinux=0\" in the kernel"
30 echo " command line."
31 echo ""
32 echo "* Halting the system now."
33 /sbin/shutdown -f -h now
34}
35
36# Contents will be added to selinux-init.sh to support relabelling with sysvinit
37# If first booting, the security context type of init would be
38# "kernel_t", and the whole file system should be relabeled.
39if [ "`${SECON} -t --pid 1`" = "kernel_t" ]; then
40 echo "Checking SELinux security contexts:"
41 check_rootfs
42 echo " * First booting, filesystem will be relabeled..."
43 test -x /etc/init.d/auditd && /etc/init.d/auditd start
44 ${SETENFORCE} 0
45 ${RESTORECON} -RF /
46 ${RESTORECON} -F /
47 echo " * Relabel done, rebooting the system."
48 /sbin/reboot
49fi
50
51exit 0