简体   繁体   中英

How to check if Linux user namespaces are supported by current OS kernel

After doing some reading, I found that Linux user namespaces are generally supported in Linux versions >= 3.8. However, there's a possibility that user namespaces are disabled on a given OS, making the check for kernel versions unreliable. Is there a robust way to check if the current OS I'm using supports user namespaces and has it available to use?

There are two places you can check to see if your kernel supports user namespaces:

  1. /boot/config-* . (find out which one you are actually using with uname -a )
  2. /proc/config.gz .

In both files look for CONFIG_USER_NS . If it reads CONFIG_USER_NS=y you're golden. If not, well, you're about to compile a new kernel.

您可以检查当前进程' /proc/[pid]/ns/目录是否有一个名为user的文件:

ls /proc/self/ns

Provided you are running bash (you can check by running echo $0 , expected result is -bash ). Then you can run the following one liner:

if [[ `sudo cat /boot/config-$(uname -a | awk '{print $3}') |grep '^CONFIG_USER_NS'` == "CONFIG_USER_NS=y" ]]; then echo "You have support for User Namespaces"; else echo "Sorry, you don't have support for User Namespaces"; fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM