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 428 by niro, Sun Mar 4 13:24:34 2007 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.13 2007-03-04 13:24:34 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    populate_udev()
30    {
31     local opts
32    
33     # tell modprobe.sh to be verbose to $CONSOLE
34     echo CONSOLE=${CONSOLE} > /dev/.udev_populate
35    
36     # populate /dev with devices already found by the kernel
37     if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
38     then
39     echo -e ${COLOREDSTAR}"  Populating /dev with existing devices through uevents ..."
40     [[ $(udev_version) -ge "96" ]] && opts="--attr-match=dev"
41     /sbin/udevtrigger ${opts}
42     evaluate_retval
43     else
44     echo -e ${COLOREDSTAR}"  Populating /dev with existing devices with udevstart ..."
45   /sbin/udevstart   /sbin/udevstart
46     evaluate_retval
47     fi
48    
49     # loop until everything is finished
50     echo -e ${COLOREDSTAR}"  Letting udev process events ..."
51     /sbin/udevsettle --timeout=60
52     evaluate_retval
53    
54     rm -f /dev/.udev_populate
55     return 0
56    }
57    
58   #not provided by sysfs but needed  seed_dev()
59    {
60     # seed /dev with some things that we know we need
61     echo -e ${COLOREDSTAR}"  Seeding /dev with needed nodes ..."
62     (
63     [ ! -c /dev/console ] && mknod /dev/console c 5 1
64     [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1
65     [ ! -c /dev/null ] && mknod /dev/null c 1 3
66    
67     # copy over any persistant things
68     if [[ -d /lib/udev/devices ]]
69     then
70     cp --preserve=all --recursive --update /lib/udev/devices/* /dev
71     fi
72    
73     # not provided by sysfs but needed
74   ln -snf /proc/self/fd /dev/fd   ln -snf /proc/self/fd /dev/fd
75   ln -snf fd/0 /dev/stdin   ln -snf fd/0 /dev/stdin
76   ln -snf fd/1 /dev/stdout   ln -snf fd/1 /dev/stdout
77   ln -snf fd/2 /dev/stderr   ln -snf fd/2 /dev/stderr
78   ln -snf /proc/kcore /dev/core   [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
79   ln -snf /proc/asound/oss/sndstat /dev/sndstat  
80     # create problematic directories
  #create problematic directories  
81   mkdir -p /dev/{pts,shm}   mkdir -p /dev/{pts,shm}
82     )
83   #same as /dev/.devfsd   evaluate_retval
  touch /dev/.udev  
   
  return 0  
84  }  }
85    
86  trap "" INT QUIT TSTP  trap "" INT QUIT TSTP
87    
88  [ "$1" != "" ] && runlevel=$1  [ "$1" != "" ] && runlevel=$1
89    
90  if [ "$runlevel" = "sysinit" ]  if [[ $runlevel = sysinit ]]
91  then  then
92   echo   echo
93   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
94   echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\""   echo -e "Copyright 2001-2007 Niels Rogalla; http://magellan-linux.net"
95   echo   echo
96    
97   #mount proc filesystem, needed for bootsplash;   # mount proc filesystem, needed for bootsplash;
98   #no use of '/etc/rc.d/init.d/mountproc' anymore   # no use of '/etc/rc.d/init.d/mountproc' anymore
99   if [ ! -e /proc/mounts ]   if [ ! -e /proc/mounts ]
100   then   then
101   echo -e ${COLOREDSTAR}"Mounting proc file system ..."   echo -e ${COLOREDSTAR}"Mounting proc file system ..."
# Line 49  then Line 103  then
103   evaluate_retval   evaluate_retval
104   fi   fi
105    
106   #set default verbose level for kernel messages   # set default verbose level for kernel messages
107   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
108   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
109    
110   #mount sys file system before udev or devfs (kernel-2.6)   # mount sys file system before udev or devfs (kernel-2.6)
111   if [ "$(kernel_major_version)" == "2.6" ]   if [[ $(kernel_major_version) = 2.6 ]]
112   then   then
113   if [ -d /sys ]   if [ -d /sys ]
114   then   then
115   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
116   mount -t sysfs none /sys   mount -n -t sysfs sysfs /sys
117   evaluate_retval   evaluate_retval
118   else   else
119   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."
# Line 69  then Line 123  then
123   fi   fi
124    
125   ## load devfs ##   ## load devfs ##
126   #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
127   if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ]   if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]]
128   then   then
129   # start devfsd daemon, needed for bootsplash;   # start devfsd daemon, needed for bootsplash;
130   # no use of '/etc/rc.d/init.d/devfs' anymore   # no use of '/etc/rc.d/init.d/devfs' anymore
# Line 79  then Line 133  then
133   if [ ! -e /dev/.devfsd ]   if [ ! -e /dev/.devfsd ]
134   then   then
135   echo -e ${COLOREDSTAR}"Mounting devfs file system ..."   echo -e ${COLOREDSTAR}"Mounting devfs file system ..."
136   mount -t devfs devfs /dev   mount -n -t devfs devfs /dev
137   evaluate_retval   evaluate_retval
138   fi   fi
139    
   
140   if [ -e /dev/.devfsd ]   if [ -e /dev/.devfsd ]
141   then   then
142   echo -e ${COLOREDSTAR}"Starting devfsd ..."   echo -e ${COLOREDSTAR}"Starting devfsd ..."
# Line 100  then Line 153  then
153   read   read
154   $rc_base/init.d/halt   $rc_base/init.d/halt
155   fi   fi
   
156   fi   fi
157    
158   #### load udev ####   #### load udev ####
159   #load udev only with a 2.6 kernel   # load udev only with a 2.6 kernel
160   if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ]   if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]]
161   then   then
162  # #first at all unmount devfs if this was loaded by the kernel   # check if /dev/console exists outside tmpfs
163  # DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)"   [ -c /dev/console ] ; need_redirect=$?
164  # if [ "${DEVFS_MOUNTED}" == "devfs" ]  
165  # then   # create a ramdisk for populating udev
166  # umount -n /dev \   echo -e ${COLOREDSTAR}"Mounting udev at /dev ..."
167  # && echo "debug: unmounted devfs successfully" \   # many video drivers needed exec access
168  # || echo "debug: unmounting devfs failed"   fstype=ramfs
169  # fi   # tmpfs was suggested by Greg Kroah-Hartman
170     kernel_supports_fs tmpfs && fstype=tmpfs
171   #create a ramdisk for populating udev   mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755
  echo -e ${COLOREDSTAR}"Mounting ramfs at /dev ..."  
  mount -n -t ramfs none /dev  
172   evaluate_retval   evaluate_retval
173    
174   #if a device tarball exists load it and if it is activated   # if a device tarball exists load it and if it is activated
175   echo -e ${COLOREDSTAR}"Configurating system to use udev ..."   echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
176   if [ "${RC_DEVICE_TARBALL}" = "yes" ]   if [[ ${RC_DEVICE_TARBALL} = yes ]]
177   then   then
178   echo -e ${COLOREDSTAR}"  Populating /dev with with device nodes ..."   echo -e ${COLOREDSTAR}"  Populating /dev with saved device nodes ..."
179   tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev   tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
180   evaluate_retval   evaluate_retval
181   fi   fi
182    
183   #now load udev   # other eeded device nodes with udev
184   populate_udev   seed_dev
185    
186   #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 ]  
187   then   then
188   echo -e ${COLOREDSTAR}"  Using /sbin/hotplug for udev management ..."   if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -gt "2614" ]
189     then
190     echo -e ${COLOREDSTAR}"  Using netlink for hotplug events ..."
191     echo "" > /proc/sys/kernel/hotplug
192     evaluate_retval
193     else
194     echo -e ${COLOREDSTAR}"  Setting /sbin/udevsend as hotplug agent ..."
195     echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
196     evaluate_retval
197     fi
198     else
199     echo -e ${COLOREDSTAR}${COLYELLOW}"  Kernel was not compiled with hotplug support !"
200     print_status failure
201     fi
202    
203   elif [ -e /proc/sys/kernel/hotplug ]   echo -e ${COLOREDSTAR}"  Starting udevd daemon ..."
204     if [ ${need_redirect} -eq 1 ]
205   then   then
206   echo -e ${COLOREDSTAR}"  Setting /sbin/udev as hotplug agent ..."   # we need to open fds 0 1 2
207   echo "/sbin/udev" > /proc/sys/kernel/hotplug   /sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console
208   else   else
209   echo -e ${COLOREDSTAR}${COLYELLOW}"  Kernel was not compiled with hotplug support !"   /sbin/udevd --daemon
210   fi   fi
211   evaluate_retval   evaluate_retval
212    
213     populate_udev
214    
215     # create nodes that udev can't
216     echo -e ${COLOREDSTAR}"  Finializing udev configuration ..."
217     [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
218     [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
219     [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
220     print_status success
221    
222     # same thing as /dev/.devfsd
223     touch /dev/.udev
224   fi   fi
225    
   
226   ## load devpts ##   ## load devpts ##
227   # 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
228   if [ $(kernel_major_version) == 2.6 ]   if [[ $(kernel_major_version) = 2.6 ]]
229   then   then
230   # check if we really have devpts support   # check if we really have devpts support
231   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 ]  
232   then   then
233   # /dev/pts maybe not exists.   # /dev/pts maybe not exists.
234   # We only create this directory only if devfs was mounted,   # We only create this directory only if devfs was mounted,
235   # or it will fail as / is still mounted readonly   # or it will fail as / is still mounted readonly
236   if [ ! -d "/dev/pts" \   # udev has this dir already, only a sanity check for devfs
237   -a -e "/dev/.devfsd" \   if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs
  -a  "${DEVFS_MOUNTED}" == "devfs" ]  
238   then   then
239   mkdir -p /dev/pts &> /dev/null || \   mkdir -p /dev/pts &> /dev/null || \
240   echo "Could not create /dev/pts !"   echo "Could not create /dev/pts !"
241   fi   fi
242    
243   #now mount devpts   # now mount devpts
244   if [ -d /dev/pts ]   if [ -d /dev/pts ]
245   then   then
246   echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."   echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
247   mount -n -t devpts -o gid=4,mode=0620 none /dev/pts   mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
248   evaluate_retval   evaluate_retval
249   fi   fi
250   else   else
# Line 194  then Line 265  then
265   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
266   evaluate_retval   evaluate_retval
267    
268   #load bootsplash   # load bootsplash
269   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
270  fi  fi
271    
272    
273    if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
 if [ "$runlevel" == "0" ]  
274  then  then
275     # load bootsplash
  #load bootsplash  
276   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
277    
   
278   # if requested save devices to a device tarball before halt   # if requested save devices to a device tarball before halt
279   # only for kernels >=2.6 *and* udev   # only for kernels >=2.6 *and* udev
280   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd
281   if [ "${RC_DEVICE_TARBALL}" = "yes" \   if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
282   -a -e /dev/.udev \   [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
  -a ! -e /dev/.devfsd \  
  -a ! -e /.bootdev ]  
283   then   then
284   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
285   cd /dev   ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
  tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null  
286   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2
287   evaluate_retval   evaluate_retval
288   fi   fi
289  fi  fi
290    
 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  
291    
292  if [ "$runlevel" = "" ]  if [ "$runlevel" = "" ]
293  then  then
# Line 252  then Line 295  then
295   exit 1   exit 1
296  fi  fi
297    
298    
299  previous=$PREVLEVEL  previous=$PREVLEVEL
300  [ "$previous" = "" ] && previous=N  [ "$previous" = "" ] && previous=N
301    

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