LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Sometimes lxc-slackware breaks due to erroneously created ${DEV}/null file (https://www.linuxquestions.org/questions/slackware-14/sometimes-lxc-slackware-breaks-due-to-erroneously-created-%24%7Bdev%7D-null-file-4175664825/)

crts 11-24-2019 04:22 AM

Sometimes lxc-slackware breaks due to erroneously created ${DEV}/null file
 
Some packages may redirect stderr to /dev/null during container creation. When the script tries to execute
Code:

mknod -m 666 ${DEV}/null c 1 3
in the configuration stage it will abort with an error. This patch mitigates the problem.
Code:

--- lxc-slackware.org  2019-11-24 10:50:33.428626035 +0100
+++ lxc-slackware.mod  2019-11-24 11:02:37.717571177 +0100
@@ -90,6 +90,12 @@
 # http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
 DEV=$rootfs/dev
 mkdir -p ${DEV}
+
+# Some install scripts may have redirected stderr to
+# /dev/null and thus created a file named /dev/null.
+# It must be removed before attempting to create
+# the device /dev/null.
+[[ -e ${DEV}/null ]] && rm -rf ${DEV}/null
 mknod -m 666 ${DEV}/null c 1 3
 mknod -m 666 ${DEV}/zero c 1 5
 mknod -m 666 ${DEV}/random c 1 8

PS:
I am aware that the test '[[ -e ${DEV}/null ]]' is probably redundant and that I am overly cautious here.

volkerdi 11-24-2019 11:00 PM

Fixed, thanks.

crts 01-02-2020 01:41 PM

More issues came up which required some more modifications:

Code:

--- lxc-slackware.orig  2020-01-01 22:22:21.504770334 +0100
+++ lxc-slackware.new  2020-01-01 22:29:30.263410113 +0100
@@ -90,25 +90,48 @@
 # http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
 DEV=$rootfs/dev
 mkdir -p ${DEV}
+
+# some install scripts may redirect stderr to /dev/null
+# if /dev/null does not exist then this will lead to an error
+[[ -e ${DEV}/null ]] && rm -rf ${DEV}/null
 mknod -m 666 ${DEV}/null c 1 3
+[[ -e ${DEV}/zero ]] && rm -rf ${DEV}/zero
 mknod -m 666 ${DEV}/zero c 1 5
+[[ -e ${DEV}/random ]] && rm -rf ${DEV}/random
 mknod -m 666 ${DEV}/random c 1 8
+[[ -e ${DEV}/urandom ]] && rm -rf ${DEV}/urandom
 mknod -m 666 ${DEV}/urandom c 1 9
+[[ -e ${DEV}/pts ]] && rm -rf ${DEV}/pts
 mkdir -m 755 ${DEV}/pts
+[[ -e ${DEV}/shm ]] && rm -rf ${DEV}/shm
 mkdir -m 1777 ${DEV}/shm
+[[ -e ${DEV}/tty ]] && rm -rf ${DEV}/tty
 mknod -m 666 ${DEV}/tty c 5 0
+[[ -e ${DEV}/console ]] && rm -rf ${DEV}/console
 mknod -m 600 ${DEV}/console c 5 1
+[[ -e ${DEV}/tty0 ]] && rm -rf ${DEV}/tty0
 mknod -m 666 ${DEV}/tty0 c 4 0
+[[ -e ${DEV}/tty1 ]] && rm -rf ${DEV}/tty1
 mknod -m 666 ${DEV}/tty1 c 4 1
+[[ -e ${DEV}/tty2 ]] && rm -rf ${DEV}/tty2
 mknod -m 666 ${DEV}/tty2 c 4 2
+[[ -e ${DEV}/tty3 ]] && rm -rf ${DEV}/tty3
 mknod -m 666 ${DEV}/tty3 c 4 3
+[[ -e ${DEV}/tty4 ]] && rm -rf ${DEV}/tty4
 mknod -m 666 ${DEV}/tty4 c 4 4
+[[ -e ${DEV}/tty5 ]] && rm -rf ${DEV}/tty5
 mknod -m 666 ${DEV}/tty5 c 4 5
+[[ -e ${DEV}/full ]] && rm -rf ${DEV}/full
 mknod -m 666 ${DEV}/full c 1 7
+[[ -e ${DEV}/initctl ]] && rm -rf ${DEV}/initctl
 mknod -m 600 ${DEV}/initctl p
+[[ -e ${DEV}/loop0 ]] && rm -rf ${DEV}/loop0
 mknod -m 660 ${DEV}/loop0 b 7 0
+[[ -e ${DEV}/loop1 ]] && rm -rf ${DEV}/loop1
 mknod -m 660 ${DEV}/loop1 b 7 1
+[[ -e ${DEV}/ptmx ]] && rm -rf ${DEV}/ptmx
 ln -s pts/ptmx ${DEV}/ptmx
+[[ -e ${DEV}/fd ]] && rm -rf ${DEV}/fd
 ln -s /proc/self/fd ${DEV}/fd
 
 echo "Adding an etc/fstab that must be modified later with the"
@@ -123,11 +146,11 @@
 
 # Back up the existing init scripts and install the lxc versions:
 ( cd $rootfs/etc/rc.d
-  cp -a /usr/share/lxc/scripts/slackware/* .
-  chmod 755 *.lxc
-  for file in *.lxc ; do
-    cp -a $(basename $file .lxc) $(basename $file .lxc).orig
-    cp -a $file $(basename $file .lxc)
+  for file in /usr/share/lxc/scripts/slackware/*.lxc ; do
+    base=$(basename $file .lxc)
+    cp -a $base $base.orig
+    cp -a $file $base
+    chmod 755 $base
  done
 )

A few more files (e.g. dev/zero) were created by the install scripts causing errors when mknod or ln was called. As a precaution I changed the script to check and delete any file if it already exists.


Another issue was that originally the script would first copy all *.lxc files into /etc/rc.d and then erroneously assume that every file that has an *.lxc suffix is a replacement for another "regular" script. This, however, is not true for rc.lxc where .lxc is not a suffix indicating a replacement script. The original script would strip this suffix and then try to execute
Code:

cp rc rc.orig
The patch addresses this issue, too, by deriving the basenames from /usr/share/lxc/scripts/slackware instead of from within $rootfs/etc/rc.d after they are copied.


All times are GMT -5. The time now is 07:08 PM.