linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marco d'Itri" <md@Linux.IT>
To: linux-hotplug@vger.kernel.org
Subject: updated init script
Date: Sat, 21 Feb 2004 22:20:36 +0000	[thread overview]
Message-ID: <20040221222036.GA9441@wonderland.linux.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 756 bytes --]

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.
-- 
ciao, |
Marco | [4698 pryzWZsHITiM6]

[-- Attachment #2: udev --]
[-- Type: text/plain, Size: 3154 bytes --]

#!/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


[-- Attachment #3: links.conf --]
[-- Type: text/plain, Size: 364 bytes --]

# 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


[-- Attachment #4: MAKEDEV-wrapper --]
[-- Type: text/plain, Size: 201 bytes --]

#!/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 "$*"


             reply	other threads:[~2004-02-21 22:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-21 22:20 Marco d'Itri [this message]
2004-02-22  9:25 ` updated init script John L Fjellstad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040221222036.GA9441@wonderland.linux.it \
    --to=md@linux.it \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).