udev support
nestu
nestu at lunar-linux.org
Sat Aug 7 00:16:04 GMT 2004
Hello ladies and gents,
I have been working on a udev update so it works more OOTB,
and less you-have-to-do-this in order to get it working.
Well, this is a first approach:
/etc/init.d/mount needs a series of modifications. With
current implementation there are problems to mount if a
separate script is used. So, as a temporal example, and
waiting for ideas, I have attached a hacked script. My
script expects dev=[udev|devfs] on the kernel's boot
cmdline. If nothing is supplied, it assume a static /dev and
does "nothing". I could add a check to default on 2.4's to
devfs and to default on 2.6 to udev (and check that you are
not trying to get udev for a 2.4 kernel too ... tsk tsk you!
) I recommend diff'ing against the original mount script ;)
Oh, btw, has been only tested on udev :) Haven't had the
oportunity to test on devfs, but will do tomorrow from qemu.
Right now it is gone 2 am ...
udev module: would need a couple of changes as well. The
init.d would be removed, since the booting would be taken
care of by mount (could be kept, but would need some fixing,
for stopping or restarting the service, for example).
I have attached a POST_INSTALL for the udev module. It
takes care of checking if the 2 necessary nodes under
/dev are mknod'ed if they are not there :) And yes, it
works! Was a surprise for me too! :D
My proposal is based on a /dev on ramfs ( /dev is *small* ).
That could be changed for permanent nodes on /dev (thought
dynamically added by udev). It could even be a choice....
Ideas, complaints, changes? I'm open to listen to all ! ;)
Thanks for listening,
Jaime ;)))
--
Lunar Linux http://www.lunar-linux.org
XFce Desktop http://www.xfce.org
#OnlyLinux LUG http://onlylinux.no-ip.org
QOTD:
<Fuzzbox> "Lunar dev looking for a pretty girl to show her
the stars"
QOT?:
<Veerappan> also, i'm upset. my roommate's treadmill is too
short.
<Veerappan> another foot, and my bike would fit :)
-------------- next part --------------
#!/bin/bash
# description: mount and umount the filesystem
# Lunar devfsd save location
DEVFSDD=/var/state/devfsd
chkresult() {
if [ $? -eq "0" ] ; then
echo -e $RESULT_OK
else
echo -e $RESULT_FAIL
fi
}
# flips a file upside down
flip() {
local STRING
while read -r STRING ; do
flip
echo "$STRING" # New line needed
break
done
}
start() {
echo "Mounting filesystems:"
mount -n -o remount,ro / >& /dev/null
DEVNODES=`grep "Kernel command line:" /var/log/dmesg | grep -ow "dev=\(udev\|devfs\)" | sed 's/dev=//g'`
echo "DEVNODES: \"$DEVNODES\""
sleep 1
if [ "$DEVNODES" = "devfs" ]; then
# I hate this, but it's required to make swapoff work if devfs is runing on /dev
# it's clean and also simplifies the devfsd module
# This scews up mtab
grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto | \
while read DEVICE MOUNTPOINT FSTYPE REST ; do
if [ "$DEVICE" = "devfs" ] ; then
echo -n " * Mounting: $MOUNTPOINT"
mount -n $MOUNTPOINT &> /dev/null
if [ $? -eq "0" ] ; then
if [ -x /sbin/devfsd ] ; then
echo -e $RESULT_OK
echo -n " * Starting devfsd on $MOUNTPOINT:"
devfsd $MOUNTPOINT &> /dev/null
chkresult
fi
else
echo -e $RESULT_FAIL
fi
fi
done
fi
if [ ! -e /fastboot ] ; then
if [ -e /forcefsck ] ; then
FORCE="-f"
fi
echo -n " * Checking all file systems"
fsck -A -y -a &> /dev/null
if [ "$?" -eq "0" ] ; then
echo -e $RESULT_OK
else
if [ "$?" -eq "1" ] ; then # Don't force the poor guy into resuce mode, if fscked cleaned it
echo -e $RESULT_WARN
else
echo -e " * fsck failed.$RESULT_FAIL"
echo " * Please repair your file system"
echo " * manually by running /sbin/fsck"
echo " * without the -a option"
sulogin
reboot -f
fi
fi
fi
echo -n " * Remounting root readwrite"
mount -n -o remount,rw / &> /dev/null
echo > /etc/mtab
rm -f /etc/mtab~* &> /dev/null
mount -f -o remount,rw / &> /dev/null
chkresult
echo -n " * Mounting proc on /proc:"
mount -t proc proc /proc
chkresult
if [ "$DEVNODES" = "udev" ]; then
echo -n " * Mounting sysfs on /sys :"
test -d /sys || mkdir /sys
mount -t sysfs sysfs /sys
chkresult
echo -n " * Creating ramfs on /dev :"
mount -t ramfs none /dev
chkresult
echo -n " * Creating udev device nodes on /dev :"
/sbin/udevstart
chkresult
echo -n " * Creating missing dirs on /dev :"
mkdir /dev/{pts,shm}
chkresult
fi
# the other case left apart from devfs and udev is a static dev. This doesn't need any setup.
echo -n " * Mounting swap"
swapon -a &> /dev/null
chkresult
echo " * Mounting remaining filesystems:"
# /etc/fast should be in order
# ex. /usr should comes before /usr/local
# and /proc before /proc/bus/usb
# better to fail if a mounting dosn't exist than, do it silently
grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto |
while read DEVICE MOUNTPOINT FSTYPE REST; do
# Filter out already mounted fs's: devfs and root
# We should have mounted all devfs before, now a hack to get it into /etc/mtab
if [ "$DEVICE" == "devfs" ] ; then
if [ "$DEVNODES" = "devfs" ]; then
mount -f -t devfs devfs $MOUNTPOINT
fi
continue
fi
# these have been fixed already
if [ "$MOUNTPOINT" == "/" ] ; then
continue
fi
if [ "$MOUNTPOINT" == "/proc" ] ; then
continue
fi
if [ "$MOUNTPOINT" == "/sys" ] ; then
continue
fi
# we don't do networked fs's yet!
case "$FSTYPE" in
nfs|smbfs) continue ;;
esac
# End filter
if [ "$MOUNTPOINT" != "none" ] ; then
echo -n " * Mounting: $MOUNTPOINT"
mount $MOUNTPOINT &> /dev/null
if [ $? -ne "0" ] ; then
if [ "$DEVICE" == "usbdevfs" ] || [ "$DEVICE" == "usbfs" ] ; then # Load the module for usbdevfs if need
modprobe usbcore &> /dev/null
mount $MOUNTPOINT &> /dev/null
chkresult
else
echo -e $RESULT_FAIL
fi
else
echo -e $RESULT_OK
fi
fi
done
rm -f /fastboot /forcefsck
}
stop() {
# Establish where to get mount table from, save these since the files change if we unmount something
if [ -r /proc/mounts ] ; then
MOUNTS=/proc/mounts
else
MOUNTS=/etc/mtab
fi
# Umount all tmpfs mounts fist
# cat it with a pipe cause it will change if we umount anything
# write wtmp in /var before umounting /var
reboot -w
echo "Umounting all filesystems:"
cat $MOUNTS | flip | \
while read TYPE PNT FS REST ; do
SIG="-3"
if [ "$FS" == "nfs" ] || [ "$FS" == "smbfs" ] ; then # Don't umount smbfs and nfs because they should of been handled by another script
continue # and if they are here that means they are frozen, don't want anymore freezing
fi
if [ "$PNT" == "/" ] || [ "$PNT" == "/proc" ] ; then # Leave these two for last
continue
fi
if [ "$PNT" == "/dev" ] ; then # No need to umount /dev, and it has some unwanted sideffects anyways
continue
fi
echo -n " * Umounting: $PNT"
sync ; sync # Flush buffers
if [[ "$TYPE" == "/dev/loop*" ]] ; then
if [ -e $PNT ] ; then # Devfs and some loopback devices (iso images)
echo: -n " * Deataching loopback device $PNT:" # can take care of them selfs
losetup -d $PNT &> /dev/null
chkresult
continue # Not much we can do with loop devices
fi
fi
for TRY in "1" "2" "3" "4" ; do
if [ "$TRY" -eq "1" ] ; then
umount $PNT &> /dev/null
else
sleep 1 # Do a little break before trying again, this helps a lot in some cases
if [ "$TRY" -eq "3" ] ; then
SIG="-9"
fi
fuser -s -km $SIG $PNT &> /dev/null
sleep 1 # Small delay, to make sure it gets killed
if [ "$TRY" -eq "4" ] ; then # A real last resort
umount -lf $PNT &> /dev/null
sleep 4 # Hudge delay here, since it's lazy umount
sync; sync
else
umount $PNT &> /dev/null
fi
fi
TEST=$(cat $MOUNTS | grep "$PNT" | awk '{ print $1}')
if [ -z "$TEST" ] ; then
echo -e $RESULT_OK
continue 2
fi
# Debug!!!!!
# fuser -m -v $PNT
if [ "$TEST" == "$TYPE" ] && [ $TRY -eq "3" ] ; then # Last resort
echo -e $RESULT_WARN
echo -n " * Attempting to remount read only: $PNT"
sleep 1 # This can help sometimes, so why not wait?
mount -o remount,ro $PNT &> /dev/null
chkresult
fi
done
done
echo -n " * Deactivating swap space:"
swapoff -a
chkresult
sync; sync
# Don't umpunt /proc because it can and will crash when umounting any remaining filesystems
# on some systems
echo -n " * Remounting root readonly"
mount -no remount,ro / &> /dev/null
if [ "$?" -ne "0" ] ; then # Lazy remount, last resort
umount -L -O remount,ro / &> /dev/null
sleep 4 # Again lazy needs a long timeout
fi
if [ $? -ne "0" ] ; then
echo -e $RESULT_FAIL
read -n 1 -t 30 -p "Do you want to login? (y/n) " CONFIRM
echo ""
case $CONFIRM in
y|Y) sulogin ;;
esac
else
echo -e $RESULT_OK
fi
# Last chance to flush before reboot
sync; sync
# Should probly use hdparm at this point to put the hds to sleep
# Give the hd a chance to slow down
sleep 2
}
# to avoid confusion we force only these options as being valid:
case "$1" in
start|stop) ;;
*) echo "Warning: $0 should never be called directly"; exit 1 ;;
esac
. /lib/lsb/init-functions
exit
-------------- next part --------------
# this is a way of checking if the nodes are permanent or not
# e.g. if you have /dev with some static nodes, and you have
# devfs on top, you will see the underlaying static nodes
FAKEROOT=/tmp/UDEV_NODE_ROOT/
mkdir ${FAKEROOT}
mount --bind / ${FAKEROOT}
{ test -e ${FAKEROOT}/dev/console && echo "no need to create console"; } || mknod -m 0600 ${FAKEROOT}/dev/console c 5 1
{ test -e ${FAKEROOT}/dev/null && echo "no need to create null"; } || mknod -m 0666 ${FAKEROOT}/dev/null c 1 3
umount ${FAKEROOT}
rm -rf ${FAKEROOT}
More information about the Lunar-dev
mailing list