]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc-checkconfig.in
typofixes - https://github.com/vlajos/misspell_fixer
[mirror_lxc.git] / src / lxc / lxc-checkconfig.in
1 #!/bin/sh
2
3 # Allow environment variables to override grep and config
4 : ${CONFIG:=/proc/config.gz}
5 : ${GREP:=zgrep}
6 : ${MODNAME:=configs}
7
8 SETCOLOR_SUCCESS="printf \\033[1;32m"
9 SETCOLOR_FAILURE="printf \\033[1;31m"
10 SETCOLOR_WARNING="printf \\033[1;33m"
11 SETCOLOR_NORMAL="printf \\033[0;39m"
12
13 is_set() {
14 $GREP "$1=[y|m]" $CONFIG > /dev/null
15 return $?
16 }
17
18 is_enabled() {
19 mandatory=$2
20
21 is_set $1
22 RES=$?
23
24 if [ $RES -eq 0 ]; then
25 $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
26 else
27 if [ ! -z "$mandatory" -a "$mandatory" = yes ]; then
28 $SETCOLOR_FAILURE && echo "required" && $SETCOLOR_NORMAL
29 else
30 $SETCOLOR_WARNING && echo "missing" && $SETCOLOR_NORMAL
31 fi
32 fi
33 }
34
35 if [ ! -f $CONFIG ]; then
36 echo "Kernel configuration not found at $CONFIG; searching..."
37 KVER="`uname -r`"
38 HEADERS_CONFIG="/lib/modules/$KVER/build/.config"
39 BOOT_CONFIG="/boot/config-$KVER"
40 [ -f "${HEADERS_CONFIG}" ] && CONFIG=${HEADERS_CONFIG}
41 [ -f "${BOOT_CONFIG}" ] && CONFIG=${BOOT_CONFIG}
42 if [ ! -f "$CONFIG" ]; then
43 MODULEFILE=$(modinfo -k $KVER -n $MODNAME 2> /dev/null)
44 # don't want to modprobe, so give user a hint
45 # although scripts/extract-ikconfig could be used to extract contents without loading kernel module
46 # http://svn.pld-linux.org/trac/svn/browser/geninitrd/trunk/geninitrd?rev=12696#L327
47 fi
48 GREP=grep
49 if [ ! -f $CONFIG ]; then
50 echo "$(basename $0): unable to retrieve kernel configuration" >&2
51 echo >&2
52 if [ -f "$MODULEFILE" ]; then
53 echo "Try modprobe $MODNAME module, or" >&2
54 fi
55 echo "Try recompiling with IKCONFIG_PROC, installing the kernel headers," >&2
56 echo "or specifying the kernel configuration path with:" >&2
57 echo " CONFIG=<path> $(basename $0)" >&2
58 exit 1
59 else
60 echo "Kernel configuration found at $CONFIG"
61 fi
62 fi
63
64 echo "--- Namespaces ---"
65 echo -n "Namespaces: " && is_enabled CONFIG_NAMESPACES yes
66 echo -n "Utsname namespace: " && is_enabled CONFIG_UTS_NS
67 echo -n "Ipc namespace: " && is_enabled CONFIG_IPC_NS yes
68 echo -n "Pid namespace: " && is_enabled CONFIG_PID_NS yes
69 echo -n "User namespace: " && is_enabled CONFIG_USER_NS
70 echo -n "Network namespace: " && is_enabled CONFIG_NET_NS
71 echo -n "Multiple /dev/pts instances: " && is_enabled DEVPTS_MULTIPLE_INSTANCES
72 echo
73 echo "--- Control groups ---"
74
75 print_cgroups() {
76 # print all mountpoints for cgroup filesystems
77 awk '$1 !~ /#/ && $3 == mp { print $2; } ; END { exit(0); } ' "mp=$1" "$2" ;
78 }
79
80 CGROUP_MNT_PATH=`print_cgroups cgroup /proc/self/mounts | head -n 1`
81 KVER_MAJOR=$($GREP '^# Linux.*Kernel Configuration' $CONFIG | \
82 sed -r 's/.* ([0-9])\.[0-9]{1,2}\.[0-9]{1,3}.*/\1/')
83 if [ "$KVER_MAJOR" = "2" ]; then
84 KVER_MINOR=$($GREP '^# Linux.*Kernel Configuration' $CONFIG | \
85 sed -r 's/.* 2.6.([0-9]{2}).*/\1/')
86 else
87 KVER_MINOR=$($GREP '^# Linux.*Kernel Configuration' $CONFIG | \
88 sed -r 's/.* [0-9]\.([0-9]{1,3})\.[0-9]{1,3}.*/\1/')
89 fi
90
91 echo -n "Cgroup: " && is_enabled CONFIG_CGROUPS yes
92
93 if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then
94 echo -n "Cgroup clone_children flag: " &&
95 $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
96 else
97 echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes
98 fi
99 echo -n "Cgroup device: " && is_enabled CONFIG_CGROUP_DEVICE
100 echo -n "Cgroup sched: " && is_enabled CONFIG_CGROUP_SCHED
101 echo -n "Cgroup cpu account: " && is_enabled CONFIG_CGROUP_CPUACCT
102 echo -n "Cgroup memory controller: "
103 if [ $KVER_MAJOR -ge 3 -a $KVER_MINOR -ge 6 ]; then
104 is_enabled CONFIG_MEMCG
105 else
106 is_enabled CONFIG_CGROUP_MEM_RES_CTLR
107 fi
108 is_set CONFIG_SMP && echo -n "Cgroup cpuset: " && is_enabled CONFIG_CPUSETS
109 echo
110 echo "--- Misc ---"
111 echo -n "Veth pair device: " && is_enabled CONFIG_VETH
112 echo -n "Macvlan: " && is_enabled CONFIG_MACVLAN
113 echo -n "Vlan: " && is_enabled CONFIG_VLAN_8021Q
114 echo -n "File capabilities: " && \
115 ( [ "${KVER_MAJOR}" = 2 ] && [ ${KVER_MINOR} -lt 33 ] && \
116 is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) || \
117 ( ( [ "${KVER_MAJOR}" = "2" ] && [ ${KVER_MINOR} -gt 32 ] ) || \
118 [ ${KVER_MAJOR} -gt 2 ] && $SETCOLOR_SUCCESS && \
119 echo "enabled" && $SETCOLOR_NORMAL )
120
121 echo
122 echo "Note : Before booting a new kernel, you can check its configuration"
123 echo "usage : CONFIG=/path/to/config $0"
124 echo
125