--- trunk/magellan-initscripts/etc/rc.d/init.d/rc 2004/12/13 22:52:07 3 +++ trunk/magellan-initscripts/etc/rc.d/init.d/rc 2008/03/22 17:55:21 692 @@ -1,47 +1,113 @@ #!/bin/bash +# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.19 2008-03-22 17:55:21 niro Exp $ source /etc/sysconfig/rc source $rc_functions -source /etc/mageversion +# get mage version +MAGEVER="$(< /etc/mageversion)" -#source kernel config if exists +# source kernel config if exists [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel -#some needed functions functions -populate_udev() { - /sbin/udevstart +udev_version() +{ + local version=0 - #not provided by sysfs but needed + if [[ -x /sbin/udev ]] + then + version=$(/sbin/udev -V) + # We need it without a leading '0', else bash do the wrong thing + version=${version##0} + # Older udev's will print nothing + [[ -z ${version} ]] && version=0 + elif [[ -x /sbin/udevd ]] + then + version=$(/sbin/udevd --version) + version=${version##0} + [[ -z ${version} ]] && version=0 + fi + + echo "${version}" +} + +populate_udev() +{ + local opts + + # tell modprobe.sh to be verbose to $CONSOLE + echo CONSOLE=${CONSOLE} > /dev/.udev_populate + + # populate /dev with devices already found by the kernel + echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." + if [[ ${RC_COLDPLUG} = yes ]] + then + /sbin/udevtrigger + else + # do not run any init-scripts + /sbin/udevadm control --env do_not_run_plug_service=1 + + # only create device nodes + /sbin/udevtrigger --attr-match=dev + + # run persistent-net stuff + /sbin/udevtrigger --subsystem-match=net + fi + evaluate_retval + + # loop until everything is finished + echo -e ${COLOREDSTAR}" Letting udev process events ..." + /sbin/udevsettle --timeout=60 + evaluate_retval + + # unset this variable + udevadm control --env do_not_run_plug_service= + + rm -f /dev/.udev_populate + return 0 +} + +seed_dev() +{ + # seed /dev with some things that we know we need + echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." + ( + [ ! -c /dev/console ] && mknod /dev/console c 5 1 + [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1 + [ ! -c /dev/null ] && mknod /dev/null c 1 3 + + # copy over any persistant things + if [[ -d /lib/udev/devices ]] + then + cp -RPp /lib/udev/devices/* /dev 2>/dev/null + fi + + # not provided by sysfs but needed ln -snf /proc/self/fd /dev/fd ln -snf fd/0 /dev/stdin ln -snf fd/1 /dev/stdout ln -snf fd/2 /dev/stderr - ln -snf /proc/kcore /dev/core - ln -snf /proc/asound/oss/sndstat /dev/sndstat - - #create problematic directories - mkdir -p /dev/{pts,shm} + [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core - #same as /dev/.devfsd - touch /dev/.udev - - return 0 + # create problematic directories + mkdir -p /dev/pts /dev/shm + ) + evaluate_retval } trap "" INT QUIT TSTP [ "$1" != "" ] && runlevel=$1 -if [ "$runlevel" = "sysinit" ] +if [[ $runlevel = sysinit ]] then echo echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" - echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\"" + echo -e "Copyright 2001-2008 Niels Rogalla; http://magellan-linux.net" echo - #mount proc filesystem, needed for bootsplash; - #no use of '/etc/rc.d/init.d/mountproc' anymore + # mount proc filesystem, needed for bootsplash; + # no use of '/etc/rc.d/init.d/mountproc' anymore if [ ! -e /proc/mounts ] then echo -e ${COLOREDSTAR}"Mounting proc file system ..." @@ -49,200 +115,158 @@ evaluate_retval fi - #set default verbose level for kernel messages + # set default verbose level for kernel messages [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk - #mount sys file system before udev or devfs (kernel-2.6) - if [ "$(kernel_major_version)" == "2.6" ] + # mount sys file system before udev + if [ -d /sys ] then - if [ -d /sys ] - then - echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." - mount -t sysfs none /sys - evaluate_retval - else - echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." - echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." - echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." - fi + echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." + mount -n -t sysfs sysfs /sys + evaluate_retval + else + echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." + echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." + echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." fi - ## load devfs ## - #load devfs only with a 2.4 kernel or its really wanted with a 2.6 - if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ] - then - # start devfsd daemon, needed for bootsplash; - # no use of '/etc/rc.d/init.d/devfs' anymore - # check if devfs was mounted by the kernel, - # if not mount it (mbuild_livecd needs this one) - if [ ! -e /dev/.devfsd ] - then - echo -e ${COLOREDSTAR}"Mounting devfs file system ..." - mount -t devfs devfs /dev - evaluate_retval - fi - - if [ -e /dev/.devfsd ] - then - echo -e ${COLOREDSTAR}"Starting devfsd ..." - ## directory /lib/dev-state !must! exists ## - /sbin/devfsd /dev &> /dev/null - evaluate_retval - else - echo -e ${COLRED}"No devfs filesystem found ..." - echo -e ${COLYELLOW}"Your Kernel doesn't support the devfs filesystem." - echo -e ${COLYELLOW}"Devfs is necessary to run Magellan-Linux." - echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." - echo - echo -e ${COLYELLOW}"Press any key to shutdown the system safely ..." - read - $rc_base/init.d/halt - fi + #### load udev #### + # check if /dev/console exists outside tmpfs + [ -c /dev/console ] ; need_redirect=$? - fi + # create a ramdisk for populating udev + echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." + # many video drivers needed exec access + fstype=ramfs + # tmpfs was suggested by Greg Kroah-Hartman + kernel_supports_fs tmpfs && fstype=tmpfs + mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755,size=10M + evaluate_retval - #### load udev #### - #load udev only with a 2.6 kernel - if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ] + # if a device tarball exists load it and if it is activated + echo -e ${COLOREDSTAR}"Configurating system to use udev ..." + if [[ ${RC_DEVICE_TARBALL} = yes ]] then -# #first at all unmount devfs if this was loaded by the kernel -# DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" -# if [ "${DEVFS_MOUNTED}" == "devfs" ] -# then -# umount -n /dev \ -# && echo "debug: unmounted devfs successfully" \ -# || echo "debug: unmounting devfs failed" -# fi - - #create a ramdisk for populating udev - echo -e ${COLOREDSTAR}"Mounting ramfs at /dev ..." - mount -n -t ramfs none /dev - evaluate_retval - - #if a device tarball exists load it and if it is activated - echo -e ${COLOREDSTAR}"Configurating system to use udev ..." - if [ "${RC_DEVICE_TARBALL}" = "yes" ] - then - echo -e ${COLOREDSTAR}" Populating /dev with with device nodes ..." - tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev - evaluate_retval - fi + echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." + tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev + evaluate_retval + fi - #now load udev - populate_udev + # other eeded device nodes with udev + seed_dev - #if hotplug support exists in the kernel use it to manage udev - if [ -e /proc/sys/kernel/hotplug -a -x /sbin/hotplug ] - then - echo -e ${COLOREDSTAR}" Using /sbin/hotplug for udev management ..." - - elif [ -e /proc/sys/kernel/hotplug ] - then - echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." - echo "/sbin/udev" > /proc/sys/kernel/hotplug - else - echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" - fi + if [ -e /proc/sys/kernel/hotplug ] + then + echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." + echo "" > /proc/sys/kernel/hotplug evaluate_retval + else + echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" + print_status failure + fi + + echo -e ${COLOREDSTAR}" Starting udevd daemon ..." + if [ ${need_redirect} -eq 1 ] + then + # we need to open fds 0 1 2 + /sbin/udevd --daemon /dev/console 2>/dev/console + else + /sbin/udevd --daemon fi + evaluate_retval + + # write root_link rule + /lib/udev/write_root_link_rule + # populate udev device nodes + populate_udev + + # create nodes that udev can't + echo -e ${COLOREDSTAR}" Finializing udev configuration ..." + [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null + [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null + [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null + print_status success + + # same thing as /dev/.devfsd + touch /dev/.udev + ## end udev ## + - ## load devpts ## # devfs/udev with 2.6 has no ptys, so devpts is also needed - if [ $(kernel_major_version) == 2.6 ] + # check if we really have devpts support + if kernel_supports_fs devpts then - # check if we really have devpts support - DEVPTS_CHECK="$(cat /proc/filesystems | grep devpts | cut -d $'\t' -f2)" - DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" - if [ "${DEVPTS_CHECK}" == devpts ] + # /dev/pts maybe not exists. + # We only create this directory only if devfs was mounted, + # or it will fail as / is still mounted readonly + # udev has this dir already, only a sanity check for devfs + if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs + then + mkdir -p /dev/pts &> /dev/null || \ + echo "Could not create /dev/pts !" + fi + + # now mount devpts + if [ -d /dev/pts ] then - # /dev/pts maybe not exists. - # We only create this directory only if devfs was mounted, - # or it will fail as / is still mounted readonly - if [ ! -d "/dev/pts" \ - -a -e "/dev/.devfsd" \ - -a "${DEVFS_MOUNTED}" == "devfs" ] - then - mkdir -p /dev/pts &> /dev/null || \ - echo "Could not create /dev/pts !" - fi - - #now mount devpts - if [ -d /dev/pts ] - then - echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." - mount -n -t devpts -o gid=4,mode=0620 none /dev/pts - evaluate_retval - fi - else - # devpts is not supported, give a warning - echo -e ${COLRED}"No devpts filesystem found ..." - echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." - echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," - echo -e ${COLYELLOW}"or no pty's are available." - echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." - echo - echo -e ${COLYELLOW}"Press any key to continue ..." - read + echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." + mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts + evaluate_retval fi + else + # devpts is not supported, give a warning + echo -e ${COLRED}"No devpts filesystem found ..." + echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." + echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," + echo -e ${COLYELLOW}"or no pty's are available." + echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." + echo + echo -e ${COLYELLOW}"Press any key to continue ..." + read fi + ## end devpts ## + - ### services state dir ### + ## load usbfs ## + if kernel_supports_fs usbfs + then + echo -e ${COLOREDSTAR}"Mounting usbfs at /proc/bus/usb ..." + mount -n -t usbfs usbfs /proc/bus/usb + evaluate_retval + fi + ## end usbfs ## + + ## services state dir ## echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k evaluate_retval - #load bootsplash + # load bootsplash splash "rc_init" "${runlevel}" fi - -if [ "$runlevel" == "0" ] +if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] then - - #load bootsplash + # load bootsplash splash "rc_init" "${runlevel}" - # if requested save devices to a device tarball before halt # only for kernels >=2.6 *and* udev # make shure that udev is mounted but *not* devfs --> /dev/.devfsd - if [ "${RC_DEVICE_TARBALL}" = "yes" \ - -a -e /dev/.udev \ - -a ! -e /dev/.devfsd ] + if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ + [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] then echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." - cd /dev - tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null + ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 evaluate_retval fi fi -if [ "$runlevel" == "6" ] -then - - #load bootsplash - splash "rc_init" "${runlevel}" - - # if requested save devices to a device tarball before halt - # only for kernels >=2.6 *and* udev - # make shure that udev is mounted but *not* devfs --> /dev/.devfsd - if [ "${RC_DEVICE_TARBALL}" = "yes" \ - -a -e /dev/.udev \ - -a ! -e /dev/.devfsd ] - then - echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." - cd /dev - tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null - mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 - cd .. - evaluate_retval - fi -fi if [ "$runlevel" = "" ] then @@ -250,6 +274,7 @@ exit 1 fi + previous=$PREVLEVEL [ "$previous" = "" ] && previous=N