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?
Asked
Active
Viewed 1.1k times
10
-
make a `uses_namespace` script that just tries to use a specified namespace and returns true/false ? Good luck. – shellter Aug 29 '16 at 21:11
3 Answers
10
You could check if your current process' /proc/[pid]/ns/
directory has a file called user
:
ls /proc/self/ns

njam
- 1,233
- 14
- 16
8
There are two places you can check to see if your kernel supports user namespaces:
/boot/config-*
. (find out which one you are actually using withuname -a
)/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.

harm
- 10,045
- 10
- 36
- 41
1
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

Ivan Hristov
- 3,046
- 2
- 25
- 23
-
1Note that here the usage of `sudo`, `cat` and `awk` is superfluous. Instead, you could do something like this: `if grep -q 'CONFIG_USER_NS=y' /boot/config-$(uname -r); then echo "You have support for User Namespaces"; else echo "Sorry, you don't have support for User Namespaces"; fi` – Tachi Jul 11 '22 at 13:47