Code: Select all
#!/bin/bash
# Populate block devices
for i in /sys/block/*/dev /sys/block/*/*/dev
do
if [ -f $i ]
then
MAJOR=$(sed 's/:.*//' < $i)
MINOR=$(sed 's/.*://' < $i)
DEVNAME=$(echo $i | sed -e 's@/dev@@' -e 's@.*/@@')
mknod /dev/$DEVNAME b $MAJOR $MINOR
fi
done
# Populate char devices
for i in /sys/bus/*/devices/*/dev /sys/class/*/*/dev
do
if [ -f $i ]
then
MAJOR=$(sed 's/:.*//' < $i)
MINOR=$(sed 's/.*://' < $i)
DEVNAME=$(echo $i | sed -e 's@/dev@@' -e 's@.*/@@')
mknod /dev/$DEVNAME c $MAJOR $MINOR
fi
done
my reworking
Code: Select all
#!/bin/sh
IFS=":"
DEV=/dev
#char devices
for i in /sys/bus/*/devices/*/dev /sys/class/*/*/dev; do
read MAJOR MINOR < "$i" && i=${i%/dev} && NAME=${i##*/} && \
mknod "$DEV/$NAME" c $MAJOR $MINOR 2>/dev/null
done
#block devices
for i in /sys/block/*/dev /sys/block/*/*/dev; do
read MAJOR MINOR < "$i" && i=${i%/dev} && NAME=${i##*/} && \
mknod "$DEV/$NAME" b $MAJOR $MINOR 2>/dev/null
done
pretty good improvement, but ash reduces it to under 1 second
I then tried it with busybox built to:
1)prefer applets, 2)run as a standalone shell and 3)run nofork applets directly
This got it down to just over 1/4 second
but out of curiousity I took a look at mknod and found out that it is only listed as a noexec applet, so I modified include/applets.src.h to change mknode from NOEXEC to NOFORK and that reduced the execution time to just over 1/10th of a second
... great now I can quickly create my containerized $container/dev to use with lxc (which is why I didn't hardcode /dev btw) - kiss my ass udev/systemd - don't need your slow, bloated crap