Skip to contentSkip to conversation

updated init script

DISCUSSION Marco d'Itri 2 participants 2 messages Feb 21, 2004 – Feb 22, 2004

lore
Share & tools
lore
#0 lore raw

I'm attaching the new init script I wrote for the debian package[1], in the hope it will be useful to other distributions (again, please do not just distribute it with the package, it will do not good to debian users).

I introduced a new config file which lists symlinks, directories and devices which cannot be created by udev (a notable example being /dev/ppp and probably the tun/tap devices).

The script will also bind-mount the old /dev somewhere else, to allow MAKEDEV to still update it. (I think this will be needed at least until udev will continue to be an optional component of the distribution.)

[1] which is currently waiting to be approved by the ftpmasters before entering the distribution, FYI.

Signature · 2 lines
ciao, |
Marco | [4698 pryzWZsHITiM6]

#!/bin/sh -e

PATH="/sbin:/bin"

UDEV=/sbin/udev

. /etc/udev/udev.conf

[ -x $UDEV ] || exit 0

case "$(uname -r)" in
2.[012345].*)
echo "udev requires a 2.6.x kernel, not started." exit 0
;;
esac

export UDEV_NO_SLEEP=1
export ACTION DEVPATH

##############################################################################
# FIXME see README.Debian
mount_sysfs() {
[ -d /sys ] || mkdir /sys
[ -d /sys/class ] || mount -t sysfs sysfs: /sys
[ -d /proc/1 ] || mount -n /proc
}

# FIXME see README.Debian
umount_proc() {
umount -n /proc
}

mount_ramfs() {
if grep -E -q "^none /u?dev ramfs" /proc/mounts; then
return 0
fi

  mkdir -p /etc/udev/.dev
  mount --bind /dev /etc/udev/.dev

echo -n "Mounting ramfs over $udev_root..."
mount -n -t ramfs none $udev_root
echo "done."
}

# We must manually create /dev/null because the shell needs it for "&". # If we were using initramfs the kernel would create it for us. create_dev_null() {
[ -c $udev_root/null ] || mknod --mode=666 $udev_root/null c 1 3
}

synthesize_events() {

  # add tty devices and all other device classes
  for i in /sys/class/*; do
    [ -d "$i" ] || continue
    for j in $i/*; do
      [ -f "$j/dev" ] || continue
      DEVPATH=${j#/sys}
      class=${DEVPATH#/class/}
      class=${class%/*}
#      echo -n " $DEVPATH($class)"
      $UDEV $class || echo -n " failed: $DEVPATH"
    done
  done
  # add block devices and their partitions
  for i in /sys/block/*; do
    [ -d "$i" ] || continue
    DEVPATH=${i#/sys}
#    echo -n " $DEVPATH"
    $UDEV block || echo -n " failed: $DEVPATH"
    for j in $i/*; do
      [ -f "$j/dev" ] || continue
      DEVPATH=${j#/sys}
#      echo -n " $DEVPATH"
      $UDEV block || echo -n " failed: $DEVPATH"
    done
  done

return 0
}

make_extra_nodes () {
grep '^[^#]' /etc/udev/links.conf | \
while read type name arg1; do

    [ "$type" -a "$name" \
      -a ! -e "$udev_root/$name" -a ! -L "$udev_root/$name" ] || continue
    case "$type" in
    L)
      ln -s $arg1 $udev_root/$name
      ;;
    D)
      mkdir -p $udev_root/$name
      ;;
    M)
      cd /dev
      /sbin/MAKEDEV $name
      ;;
    *)
      echo "unparseable line ($type $name $arg1)"
      ;;
    esac

done
}

##############################################################################
case "$1" in
start)
mount_sysfs
mount_ramfs
create_dev_null
# We want to start udevd ourselves if it isn't already running. # This lets udevd run at a sane nice level...
udevd &
ACTION=add
echo -n "Creating initial udev device nodes..." synthesize_events
make_extra_nodes
umount_proc
echo "done."
;;
stop)

#    ACTION=remove
#    echo -n "Removing udev device nodes..."
#    synthesize_events
#    echo "done."
#   XXX users are not supposed to run this
    killall udevd
    umount /etc/udev/.dev
    umount /dev
    ;;

restart|force-reload)
echo -n "Creating again udev device nodes..." ACTION=add
synthesize_events
make_extra_nodes
echo "done."
;;
*)
echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}" exit 1
;;
esac

exit 0

# This file contains a list of symbolic links and directories which need

# to be created in /dev/.

L fd /proc/self/fd
L stdin /proc/self/fd/0
L stdout /proc/self/fd/1
L stderr /proc/self/fd/2
L core /proc/kcore
L sndstat /proc/asound/oss/sndstat
L MAKEDEV /sbin/MAKEDEV-wrapper

D pts
D shm

# I know, this is ugly, but I do not have a better solution. M ppp

#!/bin/sh -e

# make /dev/MAKEDEV operate on the real /dev
# credits for this hack goes to ElectricElf

if [ "pwd" = /dev -a -d /etc/udev/.dev ]; then
cd /etc/udev/.dev
fi

exec /sbin/MAKEDEV "$*"

#1 lore raw
Quoted 3 lines · Marco d'Itri

I'm attaching the new init script I wrote for the debian package[1], in the hope it will be useful to other distributions (again, please do not just distribute it with the package, it will do not good to debian users).

I'm wondering why you think these scripts won't be useful for debian users?

I added a patch against your script, so that admins can decide whether they want to use udev or not. Kinda what Debian currently does with devfs.

Signature · 2 lines
John L. Fjellstad
web: http://www.fjellstad.org/          Quis custodiet ipsos custodes
udev renamed from udev.orig +6 -0
@@ -8,6 +8,12 @@
 
 [ -x $UDEV ] || exit 0
 
+. /etc/default/udev
+
+if [ $mount == "no" ]; then
+	exit 0
+fi
+
 case "$(uname -r)" in
   2.[012345].*)
     echo "udev requires a 2.6.x kernel, not started."
# file get copied to /etc/default/udev
# mount on boot?
MOUNT=yes