Magellan Linux

Diff of /trunk/magellan-initscripts/etc/rc.d/init.d/rc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by niro, Mon Dec 13 23:24:11 2004 UTC revision 376 by niro, Mon May 29 21:25:45 2006 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.9 2006-05-29 21:25:45 niro Exp $
3    
4  source /etc/sysconfig/rc  source /etc/sysconfig/rc
5  source $rc_functions  source $rc_functions
 source /etc/mageversion  
6    
7    # get mage version
8    MAGEVER="$(< /etc/mageversion)"
9    
10  #source kernel config if exists  # source kernel config if exists
11  [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel  [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel
12    
13  #some needed functions functions  udev_version()
14  populate_udev() {  {
15     local version=0
16    
17     if [[ -x /sbin/udev ]]
18     then
19     version=$(/sbin/udev -V)
20     # We need it without a leading '0', else bash do the wrong thing
21     version=${version##0}
22     # Older udev's will print nothing
23     [[ -z ${version} ]] && version=0
24     fi
25    
26     echo "${version}"
27    }
28    
29    # this works only for 2.6.15 kernels and greater
30    trigger_events()
31    {
32     local list=""
33     local i
34     local first
35     local last
36     local default
37    
38     # if you want real hotplug (with all modules being loaded for all
39     # devices in the system), uncomment out the next line.
40     #list="$list $(echo /sys/bus/*/devices/*/uevent)"
41     list="${list} $(echo /sys/class/*/*/uevent)"
42     list="${list} $(echo /sys/block/*/uevent /sys/block/*/*/uevent)"
43     for i in ${list}
44     do
45     case "${i}" in
46     */device/uevent)
47     # skip followed device symlinks
48     continue
49     ;;
50     */class/mem/*|*/class/tty/*)
51     first="${first} ${i}"
52     ;;
53     */block/md*)
54     last="${last} ${i}"
55     ;;
56     */*)
57     default="${default} ${i}"
58     ;;
59     esac
60     done
61    
62     # trigger the sorted events
63     for i in ${first} ${default} ${last}
64     do
65     echo "add" > "${i}"
66     done
67    }
68    
69    populate_udev()
70    {
71     local loop
72    
73     # populate /dev with devices already found by the kernel
74     if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
75     then
76     echo -e ${COLOREDSTAR}"  Populating /dev with existing devices through uevents ..."
77     trigger_events
78     evaluate_retval
79     else
80     echo -e ${COLOREDSTAR}"  Populating /dev with existing devices with udevstart ..."
81   /sbin/udevstart   /sbin/udevstart
82     evaluate_retval
83     fi
84    
85     # loop until everything is finished
86     # there's gotta be a better way...
87     echo -e ${COLOREDSTAR}"  Letting udev process events ..."
88     loop=0
89     while test -d /dev/.udev/queue
90     do
91     sleep 0.1;
92     test "${loop}" -gt 300 && break
93     loop=$((${loop} + 1))
94     done
95     evaluate_retval
96    
97   #not provided by sysfs but needed   return 0
98    }
99    
100    seed_dev()
101    {
102     # seed /dev with some things that we know we need
103     echo -e ${COLOREDSTAR}"  Seeding /dev with needed nodes ..."
104     (
105     # copy over any persistant things
106     cp --preserve=all --recursive --update /lib/udev/devices/* /dev
107    
108     # not provided by sysfs but needed
109   ln -snf /proc/self/fd /dev/fd   ln -snf /proc/self/fd /dev/fd
110   ln -snf fd/0 /dev/stdin   ln -snf fd/0 /dev/stdin
111   ln -snf fd/1 /dev/stdout   ln -snf fd/1 /dev/stdout
112   ln -snf fd/2 /dev/stderr   ln -snf fd/2 /dev/stderr
113   ln -snf /proc/kcore /dev/core   [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
114   ln -snf /proc/asound/oss/sndstat /dev/sndstat  
115     # create problematic directories
  #create problematic directories  
116   mkdir -p /dev/{pts,shm}   mkdir -p /dev/{pts,shm}
117     )
118   #same as /dev/.devfsd   evaluate_retval
  touch /dev/.udev  
   
  return 0  
119  }  }
120    
121  trap "" INT QUIT TSTP  trap "" INT QUIT TSTP
122    
123  [ "$1" != "" ] && runlevel=$1  [ "$1" != "" ] && runlevel=$1
124    
125  if [ "$runlevel" = "sysinit" ]  if [[ $runlevel = sysinit ]]
126  then  then
127   echo   echo
128   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
129   echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\""   echo -e "Copyright 2001-2006 Niels Rogalla; http://magellan-linux.net"
130   echo   echo
131    
132   #mount proc filesystem, needed for bootsplash;   # mount proc filesystem, needed for bootsplash;
133   #no use of '/etc/rc.d/init.d/mountproc' anymore   # no use of '/etc/rc.d/init.d/mountproc' anymore
134   if [ ! -e /proc/mounts ]   if [ ! -e /proc/mounts ]
135   then   then
136   echo -e ${COLOREDSTAR}"Mounting proc file system ..."   echo -e ${COLOREDSTAR}"Mounting proc file system ..."
# Line 49  then Line 138  then
138   evaluate_retval   evaluate_retval
139   fi   fi
140    
141   #set default verbose level for kernel messages   # set default verbose level for kernel messages
142   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
143   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
144    
145   #mount sys file system before udev or devfs (kernel-2.6)   # mount sys file system before udev or devfs (kernel-2.6)
146   if [ "$(kernel_major_version)" == "2.6" ]   if [[ $(kernel_major_version) = 2.6 ]]
147   then   then
148   if [ -d /sys ]   if [ -d /sys ]
149   then   then
150   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
151   mount -t sysfs none /sys   mount -n -t sysfs sysfs /sys
152   evaluate_retval   evaluate_retval
153   else   else
154   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."
# Line 69  then Line 158  then
158   fi   fi
159    
160   ## load devfs ##   ## load devfs ##
161   #load devfs only with a 2.4 kernel or its really wanted with a 2.6   # load devfs only with a 2.4 kernel or its really wanted with a 2.6
162   if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ]   if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]]
163   then   then
164   # start devfsd daemon, needed for bootsplash;   # start devfsd daemon, needed for bootsplash;
165   # no use of '/etc/rc.d/init.d/devfs' anymore   # no use of '/etc/rc.d/init.d/devfs' anymore
# Line 79  then Line 168  then
168   if [ ! -e /dev/.devfsd ]   if [ ! -e /dev/.devfsd ]
169   then   then
170   echo -e ${COLOREDSTAR}"Mounting devfs file system ..."   echo -e ${COLOREDSTAR}"Mounting devfs file system ..."
171   mount -t devfs devfs /dev   mount -n -t devfs devfs /dev
172   evaluate_retval   evaluate_retval
173   fi   fi
174    
   
175   if [ -e /dev/.devfsd ]   if [ -e /dev/.devfsd ]
176   then   then
177   echo -e ${COLOREDSTAR}"Starting devfsd ..."   echo -e ${COLOREDSTAR}"Starting devfsd ..."
# Line 100  then Line 188  then
188   read   read
189   $rc_base/init.d/halt   $rc_base/init.d/halt
190   fi   fi
   
191   fi   fi
192    
193   #### load udev ####   #### load udev ####
194   #load udev only with a 2.6 kernel   # load udev only with a 2.6 kernel
195   if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ]   if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]]
196   then   then
197  # #first at all unmount devfs if this was loaded by the kernel   # create a ramdisk for populating udev
198  # DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)"   echo -e ${COLOREDSTAR}"Mounting udev at /dev ..."
199  # if [ "${DEVFS_MOUNTED}" == "devfs" ]   # tmpfs was suggested by Greg Kroah-Hartman
200  # then   # many video drivers needed exec access
201  # umount -n /dev \   mount -n -t ramfs udev /dev -o exec,nosuid,mode=0755
 # && 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  
202   evaluate_retval   evaluate_retval
203    
204   #if a device tarball exists load it and if it is activated   # if a device tarball exists load it and if it is activated
205   echo -e ${COLOREDSTAR}"Configurating system to use udev ..."   echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
206   if [ "${RC_DEVICE_TARBALL}" = "yes" ]   if [[ ${RC_DEVICE_TARBALL} = yes ]]
207   then   then
208   echo -e ${COLOREDSTAR}"  Populating /dev with with device nodes ..."   echo -e ${COLOREDSTAR}"  Populating /dev with saved device nodes ..."
209   tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev   tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
210   evaluate_retval   evaluate_retval
211   fi   fi
212    
213   #now load udev   # other eeded device nodes with udev
214   populate_udev   seed_dev
215    
216   #if hotplug support exists in the kernel use it to manage udev   if [ -e /proc/sys/kernel/hotplug ]
  if [ -e /proc/sys/kernel/hotplug -a -x /sbin/hotplug ]  
217   then   then
218   echo -e ${COLOREDSTAR}"  Using /sbin/hotplug for udev management ..."   if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
219     then
220   elif [ -e /proc/sys/kernel/hotplug ]   echo -e ${COLOREDSTAR}"  Using netlink for hotplug events ..."
221   then   echo "" > /proc/sys/kernel/hotplug
222   echo -e ${COLOREDSTAR}"  Setting /sbin/udev as hotplug agent ..."   evaluate_retval
223   echo "/sbin/udev" > /proc/sys/kernel/hotplug   elif [[ $(udev_version) -ge "48" ]]
224     then
225     echo -e ${COLOREDSTAR}"  Setting /sbin/udevsend as hotplug agent ..."
226     echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
227     evaluate_retval
228     elif [[ -x /sbin/hotplug ]]
229     then
230     echo -e ${COLOREDSTAR}"  Using /sbin/hotplug as hotplug agent ..."
231     print_status success
232     else
233     echo -e ${COLOREDSTAR}"  Setting /sbin/udev as hotplug agent ..."
234     echo "/sbin/udev" > /proc/sys/kernel/hotplug
235     evaluate_retval
236     fi
237   else   else
238   echo -e ${COLOREDSTAR}${COLYELLOW}"  Kernel was not compiled with hotplug support !"   echo -e ${COLOREDSTAR}${COLYELLOW}"  Kernel was not compiled with hotplug support !"
239     print_status failure
240   fi   fi
241    
242     echo -e ${COLOREDSTAR}"  Starting udevd daemon ..."
243     /sbin/udevd --daemon
244   evaluate_retval   evaluate_retval
245    
246     populate_udev
247    
248     # create nodes that udev can't
249     echo -e ${COLOREDSTAR}"  Finializing udev configuration ..."
250     [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
251     [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
252     [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
253     print_status success
254    
255     # same thing as /dev/.devfsd
256     touch /dev/.udev
257   fi   fi
258    
   
259   ## load devpts ##   ## load devpts ##
260   # devfs/udev with 2.6 has no ptys, so devpts is also needed   # devfs/udev with 2.6 has no ptys, so devpts is also needed
261   if [ $(kernel_major_version) == 2.6 ]   if [[ $(kernel_major_version) = 2.6 ]]
262   then   then
263   # check if we really have devpts support   # check if we really have devpts support
264   DEVPTS_CHECK="$(cat /proc/filesystems | grep devpts | cut -d $'\t' -f2)"   if kernel_supports_fs devpts
  DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)"  
  if [ "${DEVPTS_CHECK}" == devpts ]  
265   then   then
266   # /dev/pts maybe not exists.   # /dev/pts maybe not exists.
267   # We only create this directory only if devfs was mounted,   # We only create this directory only if devfs was mounted,
268   # or it will fail as / is still mounted readonly   # or it will fail as / is still mounted readonly
269   if [ ! -d "/dev/pts" \   # udev has this dir already, only a sanity check for devfs
270   -a -e "/dev/.devfsd" \   if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs
  -a  "${DEVFS_MOUNTED}" == "devfs" ]  
271   then   then
272   mkdir -p /dev/pts &> /dev/null || \   mkdir -p /dev/pts &> /dev/null || \
273   echo "Could not create /dev/pts !"   echo "Could not create /dev/pts !"
274   fi   fi
275    
276   #now mount devpts   # now mount devpts
277   if [ -d /dev/pts ]   if [ -d /dev/pts ]
278   then   then
279   echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."   echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
280   mount -n -t devpts -o gid=4,mode=0620 none /dev/pts   mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
281   evaluate_retval   evaluate_retval
282   fi   fi
283   else   else
# Line 194  then Line 298  then
298   mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k   mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k
299   evaluate_retval   evaluate_retval
300    
301   #load bootsplash   # load bootsplash
302   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
303  fi  fi
304    
305    
306    if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
 if [ "$runlevel" == "0" ]  
307  then  then
308     # load bootsplash
  #load bootsplash  
309   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
310    
   
311   # if requested save devices to a device tarball before halt   # if requested save devices to a device tarball before halt
312   # only for kernels >=2.6 *and* udev   # only for kernels >=2.6 *and* udev
313   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd
314   if [ "${RC_DEVICE_TARBALL}" = "yes" \   if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
315   -a -e /dev/.udev \   [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
  -a ! -e /dev/.devfsd \  
  -a ! -e /.bootdev ]  
316   then   then
317   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
318   cd /dev   ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
  tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null  
319   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2
320   evaluate_retval   evaluate_retval
321   fi   fi
322  fi  fi
323    
 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 \  
  -a ! -e /.bootdev ]  
  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  
324    
325  if [ "$runlevel" = "" ]  if [ "$runlevel" = "" ]
326  then  then
# Line 252  then Line 328  then
328   exit 1   exit 1
329  fi  fi
330    
331    
332  previous=$PREVLEVEL  previous=$PREVLEVEL
333  [ "$previous" = "" ] && previous=N  [ "$previous" = "" ] && previous=N
334    

Legend:
Removed from v.10  
changed lines
  Added in v.376