[lxc-devel] [PATCH 3/3] lxc-busybox: if in userns, don't try to mknod

Serge Hallyn serge at mail.hallyn.com
Wed Oct 23 01:02:59 UTC 2013


From: Serge Hallyn <serge.hallyn at ubuntu.com>

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 templates/lxc-busybox.in | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/templates/lxc-busybox.in b/templates/lxc-busybox.in
index cbdaaf3..7aa4130 100644
--- a/templates/lxc-busybox.in
+++ b/templates/lxc-busybox.in
@@ -20,6 +20,17 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+am_in_userns() {
+    [ -e /proc/self/uid_map ] || { echo no; return; }
+    [ "$(wc -l /proc/self/uid_map | awk '{ print $1 }')" -eq 1 ] || { echo yes; return; }
+    line=$(awk '{ print $1 " " $2 " " $3 }' /proc/self/uid_map)
+    [ "$line" = "0 0 4294967295" ] && { echo no; return; }
+    echo yes
+}
+
+in_userns=0
+[ $(am_in_userns) = "yes" ] && in_userns=1
+
 install_busybox()
 {
     rootfs=$1
@@ -55,19 +66,26 @@ $rootfs/usr/lib64"
     pushd $rootfs/dev > /dev/null || return 1
 
     # minimal devices needed for busybox
-    mknod tty c 5 0       || res=1
-    mknod console c 5 1   || res=1
-    chmod 666 tty console || res=1
-    mknod tty0 c 4 0      || res=1
-    mknod tty1 c 4 0      || res=1
-    mknod tty5 c 4 0      || res=1
-    chmod 666 tty0        || res=1
-    mknod ram0 b 1 0      || res=1
-    chmod 600 ram0        || res=1
-    mknod null c 1 3      || res=1
-    chmod 666 null        || res=1
-    mknod urandom c 1 9   || res=1
-    chmod 666 urandom     || res=1
+    if [ $in_userns -eq 1 ]; then
+        for dev in tty console tty0 tty1 tty5 ram0 null urandom; do
+            touch $rootfs/dev/$dev
+            echo "/dev/$dev dev/$dev    none bind 0 0" >> $path/fstab
+        done
+    else
+        mknod tty c 5 0       || res=1
+        mknod console c 5 1   || res=1
+        chmod 666 tty console || res=1
+        mknod tty0 c 4 0      || res=1
+        mknod tty1 c 4 0      || res=1
+        mknod tty5 c 4 0      || res=1
+        chmod 666 tty0        || res=1
+        mknod ram0 b 1 0      || res=1
+        chmod 600 ram0        || res=1
+        mknod null c 1 3      || res=1
+        chmod 666 null        || res=1
+        mknod urandom c 1 9   || res=1
+        chmod 666 urandom     || res=1
+    fi
 
     popd > /dev/null
 
-- 
1.8.1.2





More information about the lxc-devel mailing list