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