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 3 by niro, Mon Dec 13 22:52:07 2004 UTC revision 692 by niro, Sat Mar 22 17:55:21 2008 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.19 2008-03-22 17:55:21 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   /sbin/udevstart   local version=0
16    
17   #not provided by sysfs but needed   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     elif [[ -x /sbin/udevd ]]
25     then
26     version=$(/sbin/udevd --version)
27     version=${version##0}
28     [[ -z ${version} ]] && version=0
29     fi
30    
31     echo "${version}"
32    }
33    
34    populate_udev()
35    {
36     local opts
37    
38     # tell modprobe.sh to be verbose to $CONSOLE
39     echo CONSOLE=${CONSOLE} > /dev/.udev_populate
40    
41     # populate /dev with devices already found by the kernel
42     echo -e ${COLOREDSTAR}"  Populating /dev with existing devices through uevents ..."
43     if [[ ${RC_COLDPLUG} = yes ]]
44     then
45     /sbin/udevtrigger
46     else
47     # do not run any init-scripts
48     /sbin/udevadm control --env do_not_run_plug_service=1
49    
50     # only create device nodes
51     /sbin/udevtrigger --attr-match=dev
52    
53     # run persistent-net stuff
54     /sbin/udevtrigger --subsystem-match=net
55     fi
56     evaluate_retval
57    
58     # loop until everything is finished
59     echo -e ${COLOREDSTAR}"  Letting udev process events ..."
60     /sbin/udevsettle --timeout=60
61     evaluate_retval
62    
63     # unset this variable
64     udevadm control --env do_not_run_plug_service=
65    
66     rm -f /dev/.udev_populate
67     return 0
68    }
69    
70    seed_dev()
71    {
72     # seed /dev with some things that we know we need
73     echo -e ${COLOREDSTAR}"  Seeding /dev with needed nodes ..."
74     (
75     [ ! -c /dev/console ] && mknod /dev/console c 5 1
76     [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1
77     [ ! -c /dev/null ] && mknod /dev/null c 1 3
78    
79     # copy over any persistant things
80     if [[ -d /lib/udev/devices ]]
81     then
82     cp -RPp /lib/udev/devices/* /dev 2>/dev/null
83     fi
84    
85     # not provided by sysfs but needed
86   ln -snf /proc/self/fd /dev/fd   ln -snf /proc/self/fd /dev/fd
87   ln -snf fd/0 /dev/stdin   ln -snf fd/0 /dev/stdin
88   ln -snf fd/1 /dev/stdout   ln -snf fd/1 /dev/stdout
89   ln -snf fd/2 /dev/stderr   ln -snf fd/2 /dev/stderr
90   ln -snf /proc/kcore /dev/core   [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
  ln -snf /proc/asound/oss/sndstat /dev/sndstat  
   
  #create problematic directories  
  mkdir -p /dev/{pts,shm}  
91    
92   #same as /dev/.devfsd   # create problematic directories
93   touch /dev/.udev   mkdir -p /dev/pts /dev/shm
94     )
95   return 0   evaluate_retval
96  }  }
97    
98  trap "" INT QUIT TSTP  trap "" INT QUIT TSTP
99    
100  [ "$1" != "" ] && runlevel=$1  [ "$1" != "" ] && runlevel=$1
101    
102  if [ "$runlevel" = "sysinit" ]  if [[ $runlevel = sysinit ]]
103  then  then
104   echo   echo
105   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"   echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
106   echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\""   echo -e "Copyright 2001-2008 Niels Rogalla; http://magellan-linux.net"
107   echo   echo
108    
109   #mount proc filesystem, needed for bootsplash;   # mount proc filesystem, needed for bootsplash;
110   #no use of '/etc/rc.d/init.d/mountproc' anymore   # no use of '/etc/rc.d/init.d/mountproc' anymore
111   if [ ! -e /proc/mounts ]   if [ ! -e /proc/mounts ]
112   then   then
113   echo -e ${COLOREDSTAR}"Mounting proc file system ..."   echo -e ${COLOREDSTAR}"Mounting proc file system ..."
# Line 49  then Line 115  then
115   evaluate_retval   evaluate_retval
116   fi   fi
117    
118   #set default verbose level for kernel messages   # set default verbose level for kernel messages
119   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3   [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
120   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk   echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
121    
122   #mount sys file system before udev or devfs (kernel-2.6)   # mount sys file system before udev
123   if [ "$(kernel_major_version)" == "2.6" ]   if [ -d /sys ]
124   then   then
125   if [ -d /sys ]   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
126   then   mount -n -t sysfs sysfs /sys
127   echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."   evaluate_retval
128   mount -t sysfs none /sys   else
129   evaluate_retval   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."
130   else   echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)."
131   echo -e ${COLORED}"Fatal: mountpoint /sys missing ..."   echo -e ${COLYELLOW}"It's essential for a 2.6 kernel."
  echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)."  
  echo -e ${COLYELLOW}"It's essential for a 2.6 kernel."  
  fi  
132   fi   fi
133    
  ## 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  
134    
135     #### load udev ####
136   if [ -e /dev/.devfsd ]   # check if /dev/console exists outside tmpfs
137   then   [ -c /dev/console ] ; need_redirect=$?
  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  
138    
139   fi   # create a ramdisk for populating udev
140     echo -e ${COLOREDSTAR}"Mounting udev at /dev ..."
141     # many video drivers needed exec access
142     fstype=ramfs
143     # tmpfs was suggested by Greg Kroah-Hartman
144     kernel_supports_fs tmpfs && fstype=tmpfs
145     mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755,size=10M
146     evaluate_retval
147    
148   #### load udev ####   # if a device tarball exists load it and if it is activated
149   #load udev only with a 2.6 kernel   echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
150   if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ]   if [[ ${RC_DEVICE_TARBALL} = yes ]]
151   then   then
152  # #first at all unmount devfs if this was loaded by the kernel   echo -e ${COLOREDSTAR}"  Populating /dev with saved device nodes ..."
153  # DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)"   tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
154  # if [ "${DEVFS_MOUNTED}" == "devfs" ]   evaluate_retval
155  # then   fi
 # 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  
156    
157   #now load udev   # other eeded device nodes with udev
158   populate_udev   seed_dev
159    
160   #if hotplug support exists in the kernel use it to manage udev   if [ -e /proc/sys/kernel/hotplug ]
161   if [ -e /proc/sys/kernel/hotplug -a -x /sbin/hotplug ]   then
162   then   echo -e ${COLOREDSTAR}"  Using netlink for hotplug events ..."
163   echo -e ${COLOREDSTAR}"  Using /sbin/hotplug for udev management ..."   echo "" > /proc/sys/kernel/hotplug
   
  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  
164   evaluate_retval   evaluate_retval
165     else
166     echo -e ${COLOREDSTAR}${COLYELLOW}"  Kernel was not compiled with hotplug support !"
167     print_status failure
168     fi
169    
170     echo -e ${COLOREDSTAR}"  Starting udevd daemon ..."
171     if [ ${need_redirect} -eq 1 ]
172     then
173     # we need to open fds 0 1 2
174     /sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console
175     else
176     /sbin/udevd --daemon
177   fi   fi
178     evaluate_retval
179    
180     # write root_link rule
181     /lib/udev/write_root_link_rule
182     # populate udev device nodes
183     populate_udev
184    
185     # create nodes that udev can't
186     echo -e ${COLOREDSTAR}"  Finializing udev configuration ..."
187     [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null
188     [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
189     [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null
190     print_status success
191    
192     # same thing as /dev/.devfsd
193     touch /dev/.udev
194     ## end udev ##
195    
196    
   
197   ## load devpts ##   ## load devpts ##
198   # 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
199   if [ $(kernel_major_version) == 2.6 ]   # check if we really have devpts support
200     if kernel_supports_fs devpts
201   then   then
202   # check if we really have devpts support   # /dev/pts maybe not exists.
203   DEVPTS_CHECK="$(cat /proc/filesystems | grep devpts | cut -d $'\t' -f2)"   # We only create this directory only if devfs was mounted,
204   DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)"   # or it will fail as / is still mounted readonly
205   if [ "${DEVPTS_CHECK}" == devpts ]   # udev has this dir already, only a sanity check for devfs
206     if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs
207     then
208     mkdir -p /dev/pts &> /dev/null || \
209     echo "Could not create /dev/pts !"
210     fi
211    
212     # now mount devpts
213     if [ -d /dev/pts ]
214   then   then
215   # /dev/pts maybe not exists.   echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
216   # We only create this directory only if devfs was mounted,   mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
217   # or it will fail as / is still mounted readonly   evaluate_retval
  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  
218   fi   fi
219     else
220     # devpts is not supported, give a warning
221     echo -e ${COLRED}"No devpts filesystem found ..."
222     echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem."
223     echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts,"
224     echo -e ${COLYELLOW}"or no pty's are available."
225     echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel."
226     echo
227     echo -e ${COLYELLOW}"Press any key to continue ..."
228     read
229   fi   fi
230     ## end devpts ##
231    
232    
233   ### services state dir ###   ## load usbfs ##
234     if kernel_supports_fs usbfs
235     then
236     echo -e ${COLOREDSTAR}"Mounting usbfs at /proc/bus/usb ..."
237     mount -n -t usbfs usbfs /proc/bus/usb
238     evaluate_retval
239     fi
240     ## end usbfs ##
241    
242     ## services state dir ##
243   echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..."   echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..."
244   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
245   evaluate_retval   evaluate_retval
246    
247   #load bootsplash   # load bootsplash
248   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
249  fi  fi
250    
251    
252    if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
 if [ "$runlevel" == "0" ]  
253  then  then
254     # load bootsplash
  #load bootsplash  
255   splash "rc_init" "${runlevel}"   splash "rc_init" "${runlevel}"
256    
   
257   # if requested save devices to a device tarball before halt   # if requested save devices to a device tarball before halt
258   # only for kernels >=2.6 *and* udev   # only for kernels >=2.6 *and* udev
259   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd   # make shure that udev is mounted but *not* devfs --> /dev/.devfsd
260   if [ "${RC_DEVICE_TARBALL}" = "yes" \   if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
261   -a -e /dev/.udev \   [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
  -a ! -e /dev/.devfsd ]  
262   then   then
263   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."   echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
264   cd /dev   ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
  tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null  
265   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2   mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2
266   evaluate_retval   evaluate_retval
267   fi   fi
268  fi  fi
269    
 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  
270    
271  if [ "$runlevel" = "" ]  if [ "$runlevel" = "" ]
272  then  then
# Line 250  then Line 274  then
274   exit 1   exit 1
275  fi  fi
276    
277    
278  previous=$PREVLEVEL  previous=$PREVLEVEL
279  [ "$previous" = "" ] && previous=N  [ "$previous" = "" ] && previous=N
280    

Legend:
Removed from v.3  
changed lines
  Added in v.692