github.com/robertojrojas/docker@v1.9.1/contrib/check-config.sh (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  # bits of this were adapted from lxc-checkconfig
     5  # see also https://github.com/lxc/lxc/blob/lxc-1.0.2/src/lxc/lxc-checkconfig.in
     6  
     7  possibleConfigs=(
     8  	'/proc/config.gz'
     9  	"/boot/config-$(uname -r)"
    10  	"/usr/src/linux-$(uname -r)/.config"
    11  	'/usr/src/linux/.config'
    12  )
    13  
    14  if [ $# -gt 0 ]; then
    15  	CONFIG="$1"
    16  else
    17  	: ${CONFIG:="${possibleConfigs[0]}"}
    18  fi
    19  
    20  if ! command -v zgrep &> /dev/null; then
    21  	zgrep() {
    22  		zcat "$2" | grep "$1"
    23  	}
    24  fi
    25  
    26  kernelVersion="$(uname -r)"
    27  kernelMajor="${kernelVersion%%.*}"
    28  kernelMinor="${kernelVersion#$kernelMajor.}"
    29  kernelMinor="${kernelMinor%%.*}"
    30  
    31  is_set() {
    32  	zgrep "CONFIG_$1=[y|m]" "$CONFIG" > /dev/null
    33  }
    34  is_set_in_kernel() {
    35  	zgrep "CONFIG_$1=y" "$CONFIG" > /dev/null
    36  }
    37  is_set_as_module() {
    38  	zgrep "CONFIG_$1=m" "$CONFIG" > /dev/null
    39  }
    40  
    41  # see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
    42  declare -A colors=(
    43  	[black]=30
    44  	[red]=31
    45  	[green]=32
    46  	[yellow]=33
    47  	[blue]=34
    48  	[magenta]=35
    49  	[cyan]=36
    50  	[white]=37
    51  )
    52  color() {
    53  	color=()
    54  	if [ "$1" = 'bold' ]; then
    55  		color+=( '1' )
    56  		shift
    57  	fi
    58  	if [ $# -gt 0 ] && [ "${colors[$1]}" ]; then
    59  		color+=( "${colors[$1]}" )
    60  	fi
    61  	local IFS=';'
    62  	echo -en '\033['"${color[*]}"m
    63  }
    64  wrap_color() {
    65  	text="$1"
    66  	shift
    67  	color "$@"
    68  	echo -n "$text"
    69  	color reset
    70  	echo
    71  }
    72  
    73  wrap_good() {
    74  	echo "$(wrap_color "$1" white): $(wrap_color "$2" green)"
    75  }
    76  wrap_bad() {
    77  	echo "$(wrap_color "$1" bold): $(wrap_color "$2" bold red)"
    78  }
    79  wrap_warning() {
    80  	wrap_color >&2 "$*" red
    81  }
    82  
    83  check_flag() {
    84  	if is_set_in_kernel "$1"; then
    85  		wrap_good "CONFIG_$1" 'enabled'
    86  	elif is_set_as_module "$1"; then
    87  		wrap_good "CONFIG_$1" 'enabled (as module)'
    88  	else
    89  		wrap_bad "CONFIG_$1" 'missing'
    90  	fi
    91  }
    92  
    93  check_flags() {
    94  	for flag in "$@"; do
    95  		echo "- $(check_flag "$flag")"
    96  	done
    97  }
    98  
    99  check_command() {
   100  	if command -v "$1" >/dev/null 2>&1; then
   101  		wrap_good "$1 command" 'available'
   102  	else
   103  		wrap_bad "$1 command" 'missing'
   104  	fi
   105  }
   106  
   107  check_device() {
   108  	if [ -c "$1" ]; then
   109  		wrap_good "$1" 'present'
   110  	else
   111  		wrap_bad "$1" 'missing'
   112  	fi
   113  }
   114  
   115  if [ ! -e "$CONFIG" ]; then
   116  	wrap_warning "warning: $CONFIG does not exist, searching other paths for kernel config ..."
   117  	for tryConfig in "${possibleConfigs[@]}"; do
   118  		if [ -e "$tryConfig" ]; then
   119  			CONFIG="$tryConfig"
   120  			break
   121  		fi
   122  	done
   123  	if [ ! -e "$CONFIG" ]; then
   124  		wrap_warning "error: cannot find kernel config"
   125  		wrap_warning "  try running this script again, specifying the kernel config:"
   126  		wrap_warning "    CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
   127  		exit 1
   128  	fi
   129  fi
   130  
   131  wrap_color "info: reading kernel config from $CONFIG ..." white
   132  echo
   133  
   134  echo 'Generally Necessary:'
   135  
   136  echo -n '- '
   137  cgroupSubsystemDir="$(awk '/[, ](cpu|cpuacct|cpuset|devices|freezer|memory)[, ]/ && $3 == "cgroup" { print $2 }' /proc/mounts | head -n1)"
   138  cgroupDir="$(dirname "$cgroupSubsystemDir")"
   139  if [ -d "$cgroupDir/cpu" -o -d "$cgroupDir/cpuacct" -o -d "$cgroupDir/cpuset" -o -d "$cgroupDir/devices" -o -d "$cgroupDir/freezer" -o -d "$cgroupDir/memory" ]; then
   140  	echo "$(wrap_good 'cgroup hierarchy' 'properly mounted') [$cgroupDir]"
   141  else
   142  	if [ "$cgroupSubsystemDir" ]; then
   143  		echo "$(wrap_bad 'cgroup hierarchy' 'single mountpoint!') [$cgroupSubsystemDir]"
   144  	else
   145  		echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')"
   146  	fi
   147  	echo "    $(wrap_color '(see https://github.com/tianon/cgroupfs-mount)' yellow)"
   148  fi
   149  
   150  if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
   151  	echo -n '- '
   152  	if command -v apparmor_parser &> /dev/null; then
   153  		echo "$(wrap_good 'apparmor' 'enabled and tools installed')"
   154  	else
   155  		echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')"
   156  		echo -n '    '
   157  		if command -v apt-get &> /dev/null; then
   158  			echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')"
   159  		elif command -v yum &> /dev/null; then
   160  			echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')"
   161  		else
   162  			echo "$(wrap_color '(look for an "apparmor" package for your distribution)')"
   163  		fi
   164  	fi
   165  fi
   166  
   167  flags=(
   168  	NAMESPACES {NET,PID,IPC,UTS}_NS
   169  	DEVPTS_MULTIPLE_INSTANCES
   170  	CGROUPS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED CPUSETS MEMCG
   171  	MACVLAN VETH BRIDGE BRIDGE_NETFILTER
   172  	NF_NAT_IPV4 IP_NF_FILTER IP_NF_TARGET_MASQUERADE
   173  	NETFILTER_XT_MATCH_{ADDRTYPE,CONNTRACK}
   174  	NF_NAT NF_NAT_NEEDED
   175  
   176  	# required for bind-mounting /dev/mqueue into containers
   177  	POSIX_MQUEUE
   178  )
   179  check_flags "${flags[@]}"
   180  echo
   181  
   182  echo 'Optional Features:'
   183  {
   184  	check_flags USER_NS
   185  }
   186  {
   187  	check_flags MEMCG_KMEM MEMCG_SWAP MEMCG_SWAP_ENABLED
   188  	if  is_set MEMCG_SWAP && ! is_set MEMCG_SWAP_ENABLED; then
   189  		echo "    $(wrap_color '(note that cgroup swap accounting is not enabled in your kernel config, you can enable it by setting boot option "swapaccount=1")' bold black)"
   190  	fi
   191  }
   192  
   193  if [ "$kernelMajor" -lt 3 ] || [ "$kernelMajor" -eq 3 -a "$kernelMinor" -le 18 ]; then
   194  	check_flags RESOURCE_COUNTERS
   195  fi
   196  
   197  if [ "$kernelMajor" -lt 3 ] || [ "$kernelMajor" -eq 3 -a "$kernelMinor" -le 13 ]; then
   198  	netprio=NETPRIO_CGROUP
   199  else
   200  	netprio=CGROUP_NET_PRIO
   201  fi
   202  
   203  flags=(
   204  	BLK_CGROUP IOSCHED_CFQ BLK_DEV_THROTTLING
   205  	CGROUP_PERF
   206  	CGROUP_HUGETLB
   207  	NET_CLS_CGROUP $netprio
   208  	CFS_BANDWIDTH FAIR_GROUP_SCHED RT_GROUP_SCHED
   209  )
   210  check_flags "${flags[@]}"
   211  
   212  check_flags EXT3_FS EXT3_FS_XATTR EXT3_FS_POSIX_ACL EXT3_FS_SECURITY
   213  if ! is_set EXT3_FS || ! is_set EXT3_FS_XATTR || ! is_set EXT3_FS_POSIX_ACL || ! is_set EXT3_FS_SECURITY; then
   214  	echo "    $(wrap_color '(enable these ext3 configs if you are using ext3 as backing filesystem)' bold black)"
   215  fi
   216  
   217  check_flags EXT4_FS EXT4_FS_POSIX_ACL EXT4_FS_SECURITY
   218  if ! is_set EXT4_FS || ! is_set EXT4_FS_POSIX_ACL || ! is_set EXT4_FS_SECURITY; then
   219  	echo "    $(wrap_color 'enable these ext4 configs if you are using ext4 as backing filesystem' bold black)"
   220  fi
   221  
   222  echo '- Storage Drivers:'
   223  {
   224  	echo '- "'$(wrap_color 'aufs' blue)'":'
   225  	check_flags AUFS_FS | sed 's/^/  /'
   226  	if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then
   227  		echo "    $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)"
   228  	fi
   229  
   230  	echo '- "'$(wrap_color 'btrfs' blue)'":'
   231  	check_flags BTRFS_FS | sed 's/^/  /'
   232  
   233  	echo '- "'$(wrap_color 'devicemapper' blue)'":'
   234  	check_flags BLK_DEV_DM DM_THIN_PROVISIONING | sed 's/^/  /'
   235  
   236  	echo '- "'$(wrap_color 'overlay' blue)'":'
   237  	check_flags OVERLAY_FS | sed 's/^/  /'
   238  
   239  	echo '- "'$(wrap_color 'zfs' blue)'":'
   240  	echo "  - $(check_device /dev/zfs)"
   241  	echo "  - $(check_command zfs)"
   242  	echo "  - $(check_command zpool)"
   243  } | sed 's/^/  /'
   244  echo
   245