udev notes

"Alan J. Wylie" <ebpxyvahk-gCrXjPrFnW/[email protected]> Fri, 3 Feb 2006 18:07:26 +0000
Newsgroups gmane.linux.distributions.rock.devel
Message-ID <[email protected]>
1) udevstart is no longer in udev 084

    <http://lwn.net/Articles/154268/>
    <http://article.gmane.org/gmane.linux.hotplug.devel/9251>

   the recommended way of setting up the device nodes from kernel
   2.6.15 on is now something like:

    --------------------------------------------------------------------------
    for i in /sys/block/*/uevent; do echo 1 > $i; done
    for i in /sys/block/*/*/uevent; do echo 1 > $i; done
    for i in /sys/class/*/*/uevent; do echo 1 > $i; done
    for i in /sys/class/*/*/*/uevent; do echo 1 > $i; done
    for i in /sys/bus/*/devices/*/uevent; do echo 1 > $i; done

    # wait until udevd has finished before using devices, e.g. swap
    loop=0
    while test -d /dev/.udev/queue; do
	    sleep 0.1;
	    if test "$loop" -gt 300
	    then
		echo "udev queue timed out"
		status=1
		break
	    fi

	    loop=$(($loop + 1))
    done
    --------------------------------------------------------------------------

2) If /etc/initscript is going to do all the setup, we no longer need
   to mount /proc, /sys, /dev/shm and /dev/pts in /etc/init.d/system,
   or for /etc/init.d/udev to exist

3) It seems that you need to have a console char device in the /dev
   directory on the root file system, otherwise the kernel gives an
   error message "Warning: unable to open an initial console".
   See linux/init/main.c before it tries to exec init.
   Without this, adding "init=/bin/sh" to the grub line won't work.

4) "kill -USR1 1" in /etc/initscript after /dev is mounted will cause
   init to close and reopen its control fifo /dev/initctl which will
   otherwise be hidden.

5) With udev, /dev/misc/microcode is instead at /dev/cpu/microcode.

   The patch file package/x86/microcode_ctl/devfs.patch is not
   applicable to udev based systems.

   Create a compatibility symlink in a udev rule perhaps?


-- 
Alan J. Wylie                                          http://www.wylie.me.uk/
"Perfection [in design] is achieved not when there is nothing left to add,
but rather when there is nothing left to take away."
  -- Antoine de Saint-Exupery

_______________________________________________
rock-devel mailing list
[email protected]
http://www.rocklinux.net/mailman/listinfo/rock-devel
initscript (text/plain, 3.1 KB)
# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/package/base/sysfiles/etc_initscript.txt
# ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---

# Set umask to safe level, and enable core dumps.
#
umask 022
ulimit -c 2097151
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# Do the dev filesystem magic
#
if [ -z "$devtype" ]; then
	devtype=udev
	if [ -f /etc/conf/devtype ]; then
		. /etc/conf/devtype
	fi
fi
case "$devtype" in
    devfs)
	if ! [ -e /dev/.devfsd ] ; then
		mount -v -n -t devfs devfs /dev
		exec > /dev/console 2>&1 < /dev/console
		echo "Mounted /dev (devfs) from /etc/initscript."
	fi
	;;

    udev)
	if ! [ -e /dev/.udev ] ; then
		if [ -e /dev/.devfsd ]; then
			mount --move /dev /etc/udev
			mount -t ramfs ramfs /dev
			mkdir /dev/devfs
			mount --move /etc/udev /dev/devfs
		else
			mount -t ramfs ramfs /dev
		fi

		# send signal to init telling it to close
		# and re-open /dev/initctl
		kill -USR1 1

		mount -n /sys; mount -n /proc

		mkdir -p /dev/pts /dev/shm
		mount -n -t devpts none /dev/pts
		mount -n -t ramfs  none /dev/shm

		ln -s /proc/self/fd /dev/fd

		/sbin/udevd --daemon

		if false
		then
		    udevstart
		else
		    for i in /sys/block/*/uevent; do echo 1 > $i; done
		    for i in /sys/block/*/*/uevent; do echo 1 > $i; done
		    for i in /sys/class/*/*/uevent; do echo 1 > $i; done
		    for i in /sys/class/*/*/*/uevent; do echo 1 > $i; done
		    for i in /sys/bus/*/devices/*/uevent; do echo 1 > $i; done

		    # wait until udevd has finished before using devices, e.g. swap
		    loop=0
		    while test -d /dev/.udev/queue; do
			    sleep 0.1;
			    if test "$loop" -gt 300
			    then
				echo "udev queue timed out"
				status=1
				break
			    fi
		    
			    loop=$(($loop + 1))
		    done
		fi

		exec > /dev/console 2>&1 < /dev/console
		echo "Mounted /dev (udev) from /etc/initscript."
	fi
	;;
    static)
	if ! [ -e /dev/.devfsd ] ; then
		umount -l -n /dev
		echo "Umounted /dev (devfs) from /etc/initscript."
	fi
	;;
    *)
	if ! [ -e /dev/console ]; then
		mount -t ramfs ramfs /dev
		mknod -m 600 /dev/console c 5 1
	fi
	exec > /dev/console 2>&1 < /dev/console
	echo "Unrecognized devtype=$devtype option caught in /etc/initscript."
	;;
esac
unset devtype

# Execute the program.
#
eval exec "$4" > /dev/console 2>&1 < /dev/console
system (text/plain, 9 KB)
#!/bin/sh
#
# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/package/base/sysfiles/system.init
# ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---
#
# Desc: System bootup and shutdown
# Runlevel: 01 rcX rc1 rc2 rc3 rc4 rc5
#

title() {
	local x w="$( stty size 2>/dev/null </dev/tty | cut -d" " -f2  )"
	[ -z "$w" ] && w="$( stty size </dev/console | cut -d" " -f2  )"
	for (( x=1; x<w; x++ )) do echo -n .; done
	echo -e "\e[222G\e[3D v \r\e[36m$* \e[0m"
	error=0
}

status() {
	if [ $error -eq 0 ]
	then
		echo -e "\e[1A\e[222G\e[4D\e[32m :-)\e[0m"
	else
		echo -e "\e[1A\e[222G\e[4D\a\e[1;31m :-(\e[0m"
	fi
}

case "$1" in
    start)
	error=0

	#title "Mounting /proc, /sys, /dev/shm and /dev/pts."
	# already done in /etc/initscript
	#mount -n /proc 2> /dev/null
	#mount -n /sys  2> /dev/null
	#mount -n /dev/shm || error=$?
	#mount -n /dev/pts 2> /dev/null

    if [ -f /etc/conf/hardware ] ; then
	. /etc/conf/hardware
    fi
    dmesg -n 3
    	status

	title "Configuring the /dev filesystem ..."
	sh /etc/conf/devfs || error=$?
    	status

	title "Activating swap devices."
	swapon -a || error=$?
    if [ -s /etc/lvmtab ]; then
		status

	title "Activating Volume Groups..."
	    /sbin/vgchange -ay || error=$?
    fi
    	status

	title "Checking file systems."
	fsck -A -C -a ; fsckrc=$?
	if   [ $(( $fsckrc & ~3 )) != 0 ] ; then
		echo " **"
		echo " ** Filesystem  || error=$? failed (returncode=$fsckrc)."
		echo " ** Please repair the broken disk(s) manually."
		echo " **"
		sulogin -t 600 /dev/console
		umount -adrv ; /sbin/reboot -d -f
		while true ; do sleep 1 ; done
	elif [ $(( $fsckrc &  2 )) != 0 ] ; then
		for x in 10 9 8 7 6 5 4 3 2 ; do  
			echo -en "\rSystem reboot in $x seconds ... "
			sleep 1
		done ; echo -e "\rSystem reboot now!                 "
		umount -adrv ; /sbin/reboot -d -f
		while true ; do sleep 1 ; done
	fi
    	status

	title "Mounting local file systems."
	mount -n -o remount,rw / || error=$?
	rootdev="/dev/$(ls -l /dev/root 2> /dev/null | sed 's,.* -> ,,')"
	if [ "$rootdev" = "/dev/" ]; then
		rootdev="$( sed 's, ,\n,g' < /proc/cmdline | \
				grep ^root= | cut -f2- -d= )"
		[ -z "$rootdev" ] && rootdev="/dev/root"
	fi
	grep -v "^rootfs " /proc/mounts | \
		sed "s,^/dev/root ,$rootdev ," > /etc/mtab || error=$?
	mount -a -t nocoda,nfs,devfs,proc,sysfs || error=$?
    	status

	title "Refresh utmp, delete lock and tmp files and other stuff."
	find /var/lock /var/run /tmp -mindepth 1 -print0 2> /dev/null | xargs --null rm -rf
	rm -f /etc/nologin /nologin /fastboot ; echo -n >> /var/run/utmp
	chmod 664 /var/run/utmp ; chown root:tty /var/run/utmp
	mkdir /tmp/.ICE-unix /var/lock/subsys
	chmod 1777 /tmp/.ICE-unix
    case "$HARDWARE_SETUP" in
      rockplug)
		status

	title "Configuring hardware by activating rockplug."
	    echo "/sbin/rockplug" > /proc/sys/kernel/hotplug
	    for file in /etc/rockplug/*.init; do
		[ -f $file ] && $file start
	    done
	    ;;
      hotplug)
		status

	title "Configuring hardware by activating hotplug."
	    echo "/sbin/hotplug" > /proc/sys/kernel/hotplug
            for RC in /etc/hotplug/*.rc; do
		echo -n "[$( basename ${RC%.rc} )] "
		$RC start || error=$?;
	    done; echo
	    echo -n >> /var/lock/subsys/hotplug
	    ;;
      *) 
		status

	title "Auto-load all modules at boot-time using hwscan."
	hwscan -- -V | sh || error=$?
    esac
    	status

	title "Loading kernel modules and configuring the kernel."
	sh /etc/conf/kernel || error=$?
    [ -f /etc/conf/clock ] && . /etc/conf/clock
    if [ "$clock_tz" = localtime ] ; then
		status

	title "Setting kernel clock to local time."
	    hwclock --hctosys --localtime || error=$?
    fi
    if [ "$clock_rtc" ] ; then
		status

	title "Setting enhanced real time clock precision to $clock_rtc."
	if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
	    echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq || error=$?
	else
	    echo "No /proc/sys/dev/rtc/max-user-freq found."
	fi
    fi
    	status

	title "Setting hostname to $(cat /etc/HOSTNAME)."
	hostname "$(cat /etc/HOSTNAME)" || error=$?
    	status

	title "Writing /var/log/boot.msg."
	dmesg > /var/log/boot.msg || error=$?
    	status

	title "Setting keyboard keymappings."
	if [ -L /etc/default.keymap ] ; then
		mapfile=$(ls -l /etc/default.keymap | sed 's,.* -> ,,')
		loadkeys $mapfile || error=$?
	elif [ -f /etc/default.keymap ] ; then
		loadkeys /etc/default.keymap || error=$?
	else
		echo "No /etc/default.keymap found."
	fi
    	status

	title "Setting keyboard repeat rate and delay time."
	kbd_rate=30; kbd_delay=250
        [ -f /etc/conf/kbd ] && . /etc/conf/kbd
        /usr/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console || error=$?
    	status

	title "Setting console screen font."
	if [ -L /etc/default.vcfont ] ; then
		fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
		setfont $fontfile || error=$?
	elif [ -f /etc/default.vcfont ] ; then
		setfont /etc/default.vcfont || error=$?
	else
		echo "No /etc/default.vcfont found."
	fi
    	status

	title "Setting console terminal type and blank interval."
	con_term=linux; con_blank=0
        [ -f /etc/conf/console ] && . /etc/conf/console
        /usr/bin/setterm -term $con_term -blank $con_blank > /dev/console || error=$?
    	status

	title "Setting up loopback networking."
	ip link set lo up || error=$?
	ip addr add 127.0.0.1/8 dev lo || error=$?
	ip route add 127/8 dev lo || error=$?
    	status

	title "Setting overflow UID and GID kernel parameters."
	sysctl -w kernel.overflowuid=$(grep ^nobody: /etc/passwd | cut -f 3 -d:) > /dev/null || error=$?
	sysctl -w kernel.overflowgid=$(grep ^nobody: /etc/passwd | cut -f 4 -d:) > /dev/null || error=$?
    	status

	title "Reading /etc/sysctl.conf file."
	sysctl -p || error=$?
    	status

	title "Initializing kernel random number generator."
	if [ -e /var/state/random-seed ] ; then
		cat /var/state/random-seed >/dev/urandom || error=$?
	fi
    	status
	;;


    stop)
	title "Saving /var/log/init.msg and /var/log/boot.msg."
	echo -n >> /var/log/init.msg || error=$?
	echo -n >> /var/log/boot.msg || error=$?
	mv /var/log/init.msg /var/log/init.old || error=$?
	mv /var/log/boot.msg /var/log/boot.old || error=$?
    	status

	title "Writing a wtmp record."
	if [ "$RUNLEVEL" = 0 ] ; then halt -w || error=$?
	else reboot -w || error=$? ; fi
    	status

	title "Saving kernel random seed."
	dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
    case "$HARDWARE_SETUP" in
      rockplug)
		status

	title "Unconfiguring hardware by de-activating rockplug."
	    for file in /etc/rockplug/*.init; do
		[ -f $file ] && $file stop
	    done
	    ;;
      hotplug)
		status

	title "Unconfiguring hardware by de-activating hotplug."
            for RC in /etc/hotplug/*.rc; do
		echo -n "[$( basename ${RC%.rc} )] "
		$RC stop || error=$?;
	    done; echo
	    rm -f /var/lock/subsys/hotplug
	    ;;
    esac
    	status

	title "Sending all processes a SIGTERM (15)."
	killall5 -15 || error=$? ; sleep 5 
    	status

	title "Sending all processes a 2nd SIGTERM (15)."
	killall5 -15 || error=$? ; sleep 5 
    	status

	title "Sending all processes a SIGKILL (9)."
	killall5 -9 || error=$? ; sleep 5 
    	status

	title "Turning off swap devices."
	swapoff -a || error=$?
	sync ; sleep 1
    	status

	title "Remounting sync/ro and umount filesystems."
	cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r | \
	while read dev dir fs ; do
		[ "$dir" = "/"        ] && continue
		[ "$dir" = "/dev"     ] && continue
		[ "$dir" = "/dev/shm" ] && continue
		[ "$dir" = "/proc"    ] && continue
		[ "$dir" = "/sys"     ] && continue
		[ "$dir" = "/tmp"     ] && continue
		echo "Umounting $dev on $dir ($fs)."
		mount -o remount,sync $dir
		mount -o remount,ro $dir
		umount -d $dir
	done
    	status

	title "Unmounting remaining file systems."
	grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
	sync ; sleep 1 ; sync
	umount -vdnra -t nodevfs,proc,sysfs,shm
	mount -vn -o remount,sync /
	mount -vn -o remount,ro /
	sleep 1 ; sync ; sleep 1
    	status

	command=""
	[ "$RUNLEVEL" = 0 ] && command=halt
	[ "$RUNLEVEL" = 6 ] && command=reboot
	if [ -n "$command" ] ; then
		echo "Going to $command the system ..."
		$command -d -f -i -p
		while true ; do sleep 1 ; done
	fi
    	;;	

    restart)
	$0 stop; $0 start
	;;

    *)
	echo "Usage: $0 { start | stop | restart }"
	exit 1 ;;

esac

exit 0