1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
|
|
4 |
source /etc/sysconfig/rc |
source /etc/conf.d/rc |
5 |
source $rc_functions |
source ${rc_functions} |
|
source /etc/mageversion |
|
6 |
|
|
7 |
|
# get mage version |
8 |
|
if [[ -f /etc/os-release ]] |
9 |
|
then |
10 |
|
MAGEVER="$(read_os_release version_id)" |
11 |
|
elif [ -f /etc/mageversion ] |
12 |
|
then |
13 |
|
MAGEVER="$(< /etc/mageversion)" |
14 |
|
else |
15 |
|
MAGEVER="unkown" |
16 |
|
fi |
17 |
|
|
18 |
#source kernel config if exists |
# source kernel config if exists |
19 |
[ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
[ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
20 |
|
|
21 |
#some needed functions functions |
# override devicemanager helper functions |
22 |
populate_udev() { |
if [[ ${RC_DEVICEMANAGER} = udev ]] && [[ -f ${rc_base}/init.d/udev ]] |
23 |
/sbin/udevstart |
then |
24 |
|
source ${rc_base}/init.d/udev |
25 |
#not provided by sysfs but needed |
|
26 |
ln -snf /proc/self/fd /dev/fd |
elif [[ ${RC_DEVICEMANAGER} = mdev ]] && [[ -f ${rc_base}/init.d/mdev ]] |
27 |
ln -snf fd/0 /dev/stdin |
then |
28 |
ln -snf fd/1 /dev/stdout |
source ${rc_base}/init.d/mdev |
29 |
ln -snf fd/2 /dev/stderr |
fi |
|
ln -snf /proc/kcore /dev/core |
|
|
ln -snf /proc/asound/oss/sndstat /dev/sndstat |
|
|
|
|
|
#create problematic directories |
|
|
mkdir -p /dev/{pts,shm} |
|
|
|
|
|
#same as /dev/.devfsd |
|
|
touch /dev/.udev |
|
|
|
|
|
return 0 |
|
|
} |
|
30 |
|
|
31 |
trap "" INT QUIT TSTP |
trap "" INT QUIT TSTP |
32 |
|
|
33 |
[ "$1" != "" ] && runlevel=$1 |
[ "$1" != "" ] && runlevel=$1 |
34 |
|
|
35 |
if [ "$runlevel" = "sysinit" ] |
if [[ $runlevel = sysinit ]] |
36 |
then |
then |
37 |
echo |
rc_echo |
38 |
echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
rc_echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" |
39 |
echo -e "\"I'm not a Gentoo-System, I'm a pure LFS\"" |
rc_echo "Copyright 2001-2014 Niels Rogalla; http://magellan-linux.net" |
40 |
echo |
rc_echo |
41 |
|
|
42 |
#mount proc filesystem, needed for bootsplash; |
# mount proc filesystem, needed for bootsplash; |
43 |
#no use of '/etc/rc.d/init.d/mountproc' anymore |
# no use of '/etc/rc.d/init.d/mountproc' anymore |
44 |
if [ ! -e /proc/mounts ] |
if [ ! -e /proc/mounts ] |
45 |
then |
then |
46 |
echo -e ${COLOREDSTAR}"Mounting proc file system ..." |
rc_print "Mounting proc file system ..." |
47 |
mount -n /proc |
mount -n /proc |
48 |
evaluate_retval |
evaluate_retval |
49 |
fi |
fi |
50 |
|
|
51 |
#set default verbose level for kernel messages |
# set default verbose level for kernel messages |
52 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
[ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
53 |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk |
54 |
|
|
55 |
#mount sys file system before udev or devfs (kernel-2.6) |
# mount sys file system before udev |
56 |
if [ "$(kernel_major_version)" == "2.6" ] |
if [ -d /sys ] |
57 |
then |
then |
58 |
if [ -d /sys ] |
if [ ! -e /sys/kernel/notes ] |
59 |
then |
then |
60 |
echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
rc_print "Mounting sysfs file system ..." |
61 |
mount -t sysfs none /sys |
mount -n -t sysfs sysfs /sys |
62 |
evaluate_retval |
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." |
|
63 |
fi |
fi |
64 |
|
else |
65 |
|
rc_echo -e ${COLRED}"Fatal: mountpoint /sys missing ..." |
66 |
|
rc_echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." |
67 |
|
rc_echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." |
68 |
fi |
fi |
69 |
|
|
70 |
## load devfs ## |
# start device management |
71 |
#load devfs only with a 2.4 kernel or its really wanted with a 2.6 |
start_devicemanager |
72 |
if [ "$(kernel_major_version)" == "2.4" -o "${RC_USED_DEV}" == "devfs" ] |
|
73 |
|
## load devpts ## |
74 |
|
# devfs/udev with 2.6 has no ptys, so devpts is also needed |
75 |
|
# check if we really have devpts support |
76 |
|
if kernel_supports_fs devpts |
77 |
then |
then |
78 |
# start devfsd daemon, needed for bootsplash; |
# /dev/pts maybe not exists. |
79 |
# no use of '/etc/rc.d/init.d/devfs' anymore |
# We only create this directory only if devfs was mounted, |
80 |
# check if devfs was mounted by the kernel, |
# or it will fail as / is still mounted readonly |
81 |
# if not mount it (mbuild_livecd needs this one) |
# udev has this dir already, only a sanity check for devfs |
82 |
if [ ! -e /dev/.devfsd ] |
if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs |
83 |
then |
then |
84 |
echo -e ${COLOREDSTAR}"Mounting devfs file system ..." |
mkdir -p /dev/pts &> /dev/null || \ |
85 |
mount -t devfs devfs /dev |
rc_echo "Could not create /dev/pts !" |
|
evaluate_retval |
|
86 |
fi |
fi |
87 |
|
|
88 |
|
# now mount devpts |
89 |
if [ -e /dev/.devfsd ] |
if [ -d /dev/pts ] |
90 |
then |
then |
91 |
echo -e ${COLOREDSTAR}"Starting devfsd ..." |
rc_print "Mounting devpts at /dev/pts ..." |
92 |
## directory /lib/dev-state !must! exists ## |
mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
|
/sbin/devfsd /dev &> /dev/null |
|
93 |
evaluate_retval |
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 |
|
94 |
fi |
fi |
95 |
|
else |
96 |
|
# devpts is not supported, give a warning |
97 |
|
rc_echo -e ${COLRED}"No devpts filesystem found ..." |
98 |
|
rc_echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." |
99 |
|
rc_echo -e ${COLYELLOW}"Devfs/Udev with a kernel-2.6.x needs devpts," |
100 |
|
rc_echo -e ${COLYELLOW}"or no pty's are available." |
101 |
|
rc_echo -e ${COLYELLOW}"Please make sure that this is enabled in your kernel." |
102 |
|
rc_echo |
103 |
|
rc_echo -e ${COLYELLOW}"Press any key to continue ..." |
104 |
|
read |
105 |
fi |
fi |
106 |
|
## end devpts ## |
107 |
|
|
108 |
|
|
109 |
#### load udev #### |
## load usbfs ## |
110 |
#load udev only with a 2.6 kernel |
if kernel_supports_fs usbfs |
|
if [ "$(kernel_major_version)" == "2.6" -a "${RC_USED_DEV}" == "udev" ] |
|
111 |
then |
then |
112 |
# #first at all unmount devfs if this was loaded by the kernel |
rc_print "Mounting usbfs at /proc/bus/usb ..." |
113 |
# DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" |
mount -n -t usbfs usbfs /proc/bus/usb |
|
# 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 |
|
114 |
evaluate_retval |
evaluate_retval |
115 |
|
fi |
116 |
|
## end usbfs ## |
117 |
|
|
118 |
#if a device tarball exists load it and if it is activated |
## services state dir ## |
119 |
echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
rc_print "Mounting tmpfs at ${svcdir} ..." |
120 |
if [ "${RC_DEVICE_TARBALL}" = "yes" ] |
mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k |
121 |
then |
evaluate_retval |
|
echo -e ${COLOREDSTAR}" Populating /dev with with device nodes ..." |
|
|
tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
|
|
evaluate_retval |
|
|
fi |
|
|
|
|
|
#now load udev |
|
|
populate_udev |
|
|
|
|
|
#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 ..." |
|
122 |
|
|
123 |
elif [ -e /proc/sys/kernel/hotplug ] |
## /run /tmp /var/lock |
124 |
|
for i in /run /tmp /var/lock |
125 |
|
do |
126 |
|
if [ -d ${i} ] |
127 |
then |
then |
128 |
echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." |
rc_print "Mounting tmpfs at ${i} ..." |
129 |
echo "/sbin/udev" > /proc/sys/kernel/hotplug |
mount -n -t tmpfs tmpfs ${i} -o rw,nosuid,nodev,relatime |
130 |
else |
evaluate_retval |
|
echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" |
|
131 |
fi |
fi |
132 |
|
done |
133 |
|
# extra check for /var/lock |
134 |
|
if [ -L /var/lock ] |
135 |
|
then |
136 |
|
mkdir -p /run/lock |
137 |
|
rc_print "Mounting tmpfs at /run/lock ..." |
138 |
|
mount -n -t tmpfs tmpfs /run/lock -o rw,nosuid,nodev,relatime |
139 |
evaluate_retval |
evaluate_retval |
140 |
fi |
fi |
141 |
|
# extra check if /run and /var/run are directories |
142 |
|
if [ -d /run ] && [ -d /var/run ] |
|
## load devpts ## |
|
|
# devfs/udev with 2.6 has no ptys, so devpts is also needed |
|
|
if [ $(kernel_major_version) == 2.6 ] |
|
143 |
then |
then |
144 |
# check if we really have devpts support |
rc_print "Mounting tmpfs at /var/run ..." |
145 |
DEVPTS_CHECK="$(cat /proc/filesystems | grep devpts | cut -d $'\t' -f2)" |
mount -n -o bind /run /var/run |
146 |
DEVFS_MOUNTED="$(cat /proc/mounts | grep devfs | cut -d ' ' -f3)" |
evaluate_retval |
|
if [ "${DEVPTS_CHECK}" == devpts ] |
|
|
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 |
|
|
fi |
|
147 |
fi |
fi |
148 |
|
|
149 |
### services state dir ### |
# load bootsplash |
|
echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." |
|
|
mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k |
|
|
evaluate_retval |
|
|
|
|
|
#load bootsplash |
|
150 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
151 |
fi |
fi |
152 |
|
|
153 |
|
|
154 |
|
if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
|
if [ "$runlevel" == "0" ] |
|
155 |
then |
then |
156 |
|
# load bootsplash |
|
#load bootsplash |
|
157 |
splash "rc_init" "${runlevel}" |
splash "rc_init" "${runlevel}" |
158 |
|
|
|
|
|
159 |
# if requested save devices to a device tarball before halt |
# if requested save devices to a device tarball before halt |
160 |
# only for kernels >=2.6 *and* udev |
# only for kernels >=2.6 *and* udev |
161 |
# make shure that udev is mounted but *not* devfs --> /dev/.devfsd |
# make sure that udev is mounted but *not* devfs --> /dev/.devfsd |
162 |
if [ "${RC_DEVICE_TARBALL}" = "yes" \ |
if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
163 |
-a -e /dev/.udev \ |
[ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] |
164 |
-a ! -e /dev/.devfsd ] |
then |
165 |
then |
rc_print "Saving /dev device nodes ..." |
166 |
echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." |
( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
167 |
cd /dev |
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev/state/devices.tar.bz2 |
|
tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null |
|
|
mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
|
168 |
evaluate_retval |
evaluate_retval |
169 |
fi |
fi |
|
fi |
|
|
|
|
|
if [ "$runlevel" == "6" ] |
|
|
then |
|
170 |
|
|
171 |
#load bootsplash |
# stop device management |
172 |
splash "rc_init" "${runlevel}" |
stop_devicemanager |
|
|
|
|
# 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 |
|
173 |
fi |
fi |
174 |
|
|
175 |
|
|
176 |
if [ "$runlevel" = "" ] |
if [ "$runlevel" = "" ] |
177 |
then |
then |
178 |
echo "Usage: $0 <runlevel>" >&2 |
rc_echo "Usage: $0 <runlevel>" >&2 |
179 |
exit 1 |
exit 1 |
180 |
fi |
fi |
181 |
|
|
182 |
|
|
183 |
previous=$PREVLEVEL |
previous=$PREVLEVEL |
184 |
[ "$previous" = "" ] && previous=N |
[ "$previous" = "" ] && previous=N |
185 |
|
|
186 |
if [ ! -d $rc_base/rc$runlevel.d ] |
if [ ! -d $rc_base/rc$runlevel.d ] |
187 |
then |
then |
188 |
echo "$rc_base/rc$runlevel.d does not exist" |
rc_echo "$rc_base/rc$runlevel.d does not exist" |
189 |
exit 1 |
exit 1 |
190 |
fi |
fi |
191 |
|
|
205 |
if [ ! -f $prev_start ] && [ ! -f $sysinit_start ] |
if [ ! -f $prev_start ] && [ ! -f $sysinit_start ] |
206 |
then |
then |
207 |
$WARNING |
$WARNING |
208 |
echo "$i can't be executed because it was" |
rc_echo "$i can't be executed because it was" |
209 |
echo "not started in the previous runlevel ($previous)" |
rc_echo "not started in the previous runlevel ($previous)" |
210 |
$NORMAL |
$NORMAL |
211 |
continue |
continue |
212 |
fi |
fi |