| 1 |
AUTHOR: Leslie Polzer <leslie.polzer@gmx.net> |
|---|
| 2 |
AUTHOR: Marc Heerdink <marc@koelkast.net> |
|---|
| 3 |
|
|---|
| 4 |
DATE: 2005-01-08 |
|---|
| 5 |
|
|---|
| 6 |
LICENSE: GNU Free Documentation License Version 1.2 |
|---|
| 7 |
|
|---|
| 8 |
SYNOPSIS: Setting up LFS with BSD/Slackware style init. |
|---|
| 9 |
|
|---|
| 10 |
DESCRIPTION: |
|---|
| 11 |
The BSD style is often perceived as a more simple (in contrast to SysVInit) way |
|---|
| 12 |
of booting your system and controlling runlevels. |
|---|
| 13 |
|
|---|
| 14 |
PREREQUISITES: |
|---|
| 15 |
LFS 2.4 or higher. |
|---|
| 16 |
|
|---|
| 17 |
HINT: |
|---|
| 18 |
|
|---|
| 19 |
Contents |
|---|
| 20 |
-------- |
|---|
| 21 |
1 Preface |
|---|
| 22 |
2 Preparations |
|---|
| 23 |
2.1 Runlevel planning |
|---|
| 24 |
2.2 Directory layout |
|---|
| 25 |
2.3 Setting up /etc/inittab |
|---|
| 26 |
3 Creating the boot scripts |
|---|
| 27 |
3.1 Creating essential scripts |
|---|
| 28 |
3.2 Creating extra scripts |
|---|
| 29 |
4 Final words |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
1 Preface |
|---|
| 33 |
========= |
|---|
| 34 |
|
|---|
| 35 |
Since LFS uses SYSV init scripts by default, about everybody who has an LFS |
|---|
| 36 |
system uses this kind of init. But a few days ago, I read about someone on the |
|---|
| 37 |
mailing list who wanted to setup BSD style init. Since I was using this since |
|---|
| 38 |
the beginning i decided to write a hint for everybody who wants to use BSD |
|---|
| 39 |
style init (or just wants to try it). |
|---|
| 40 |
|
|---|
| 41 |
BSD init uses the normal SYSV init program, but a different inittab and has |
|---|
| 42 |
the boot scripts arranged different. BSD boots your system in a much less |
|---|
| 43 |
complicated way, so the scripts are easier to maintain. I think one should |
|---|
| 44 |
read this hint before installing either init, because the decision should |
|---|
| 45 |
preferably be made before the first boot. |
|---|
| 46 |
|
|---|
| 47 |
This hint will never be complete, comments can be sent to |
|---|
| 48 |
me <leslie.polzer@gmx.net>. |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
2 Preparations |
|---|
| 52 |
============== |
|---|
| 53 |
|
|---|
| 54 |
2.1 Runlevel planning |
|---|
| 55 |
--------------------- |
|---|
| 56 |
|
|---|
| 57 |
Runlevels are a convenient way of changing a system's current purpose |
|---|
| 58 |
on the fly by terminating and starting a bulk of running programs at once. |
|---|
| 59 |
If you are not confident with runlevels and init, I suggest you get yourself |
|---|
| 60 |
some information on it now. Search for primers on the web and read init(8). |
|---|
| 61 |
|
|---|
| 62 |
You'll have to choose what runlevels you want to use before you begin, |
|---|
| 63 |
too. Somewhat default runlevels are thus: |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
RUNLEVEL: | DESCRIPTION: |
|---|
| 67 |
----------+---------------------- |
|---|
| 68 |
0 | Power down |
|---|
| 69 |
S | Single user mode |
|---|
| 70 |
1 | Alias for S |
|---|
| 71 |
2 | Multi user runlevel with console login |
|---|
| 72 |
3 | Alias for 2 |
|---|
| 73 |
4 | Alias for 2 |
|---|
| 74 |
5 | Multi user runlevel with graphical login |
|---|
| 75 |
6 | Reboot |
|---|
| 76 |
----------+---------------------- |
|---|
| 77 |
|
|---|
| 78 |
I don't recommend changing the purpose of runlevels 0, 6 and S because |
|---|
| 79 |
they should be configured like this for many programs - we'll stick with |
|---|
| 80 |
their function in this hint. Because I use only 3 modes for booting |
|---|
| 81 |
(Single User, Console Multi User and Graphical Multi User) runlevels 4 and 5 |
|---|
| 82 |
are aliases (realised with symlinks) for runlevel 2 (default). You can change |
|---|
| 83 |
their purpose to whatever you like, but I suggest you'll do that after you |
|---|
| 84 |
finished this hint. |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
2.2 Directory layout |
|---|
| 88 |
-------------------- |
|---|
| 89 |
|
|---|
| 90 |
To give you an idea of how BSD init works, I'll show you the final directory |
|---|
| 91 |
layout: |
|---|
| 92 |
|
|---|
| 93 |
/etc/rc.d |
|---|
| 94 |
+ rc.sysinit # system initialization |
|---|
| 95 |
+ rc.0 # shutdown |
|---|
| 96 |
+ rc.1 # single user |
|---|
| 97 |
+ rc.2 # multi user |
|---|
| 98 |
+ rc.3 # linked to rc.2 |
|---|
| 99 |
+ rc.4 # linked to rc.2 |
|---|
| 100 |
+ rc.5 # multi user with graphical login |
|---|
| 101 |
+ rc.6 # reboot, linked to rc.0 |
|---|
| 102 |
+ rc.local # local extensions of rc.sysinit |
|---|
| 103 |
|
|---|
| 104 |
...and maybe later, to your liking, these and more: |
|---|
| 105 |
+ rc.firewall |
|---|
| 106 |
+ rc.daemons |
|---|
| 107 |
+ rc.netdaemons |
|---|
| 108 |
+ rc.nfs |
|---|
| 109 |
+ rc.nis |
|---|
| 110 |
|
|---|
| 111 |
I suggest you create the directory and basic files (the first list) now. |
|---|
| 112 |
|
|---|
| 113 |
In the following section I will give you the contents of each of those |
|---|
| 114 |
files; these are resembling my own - but the parts that may not be applicable |
|---|
| 115 |
to anyone are commented out shell-style with a '#'. Please take a close look |
|---|
| 116 |
at these lines and decide whether you need them. |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
2.3 Setting up the inittab |
|---|
| 120 |
-------------------------- |
|---|
| 121 |
|
|---|
| 122 |
The inittab resides in /etc and configures your init. Before you start |
|---|
| 123 |
writing it, you should realize that a wrong inittab will probably result (in |
|---|
| 124 |
the worst case) in a kernel panic, but at least a lot of trouble booting your |
|---|
| 125 |
system. |
|---|
| 126 |
|
|---|
| 127 |
Now let's get down to business! Put this in your /etc/inittab: |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
-------------------------------/etc/inittab---------------------------------- |
|---|
| 131 |
id:2:initdefault: |
|---|
| 132 |
|
|---|
| 133 |
si:S:sysinit:/etc/rc.d/rc.sysinit |
|---|
| 134 |
|
|---|
| 135 |
l0:0:wait:/etc/rc.d/rc.0 |
|---|
| 136 |
l1:1:wait:/etc/rc.d/rc.1 |
|---|
| 137 |
l2:2:wait:/etc/rc.d/rc.2 |
|---|
| 138 |
l3:3:wait:/etc/rc.d/rc.3 |
|---|
| 139 |
l4:4:wait:/etc/rc.d/rc.4 |
|---|
| 140 |
l5:5:wait:/etc/rc.d/rc.5 |
|---|
| 141 |
l6:6:wait:/etc/rc.d/rc.6 |
|---|
| 142 |
|
|---|
| 143 |
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -r now |
|---|
| 144 |
|
|---|
| 145 |
su:S1:respawn:/sbin/sulogin |
|---|
| 146 |
|
|---|
| 147 |
c1:2345:respawn:/sbin/agetty tty1 38400 linux |
|---|
| 148 |
c2:2345:respawn:/sbin/agetty tty2 38400 linux |
|---|
| 149 |
c3:2345:respawn:/sbin/agetty tty3 38400 linux |
|---|
| 150 |
c4:2345:respawn:/sbin/agetty tty4 38400 linux |
|---|
| 151 |
c5:2345:respawn:/sbin/agetty tty5 38400 linux |
|---|
| 152 |
c6:2345:respawn:/sbin/agetty tty6 38400 linux |
|---|
| 153 |
----------------------------end of /etc/inittab------------------------------ |
|---|
| 154 |
|
|---|
| 155 |
This is a pretty basic configuration but should do for about everybody. As |
|---|
| 156 |
you can see, init first starts /etc/rc.d/rc.sysinit and then loads the needed |
|---|
| 157 |
file for the default runlevel (/etc/rc.d/rc.2). |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
3 Creating the boot scripts |
|---|
| 161 |
=========================== |
|---|
| 162 |
|
|---|
| 163 |
3.1 Creating essential scripts |
|---|
| 164 |
------------------------------ |
|---|
| 165 |
|
|---|
| 166 |
Let's create /etc/rc.d/rc.sysinit first: |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
-----------------------------/etc/rc.d/rc.sysinit---------------------------- |
|---|
| 170 |
#!/bin/sh |
|---|
| 171 |
echo "Mounting root device read-only..." |
|---|
| 172 |
/bin/mount -n -o remount,ro / |
|---|
| 173 |
|
|---|
| 174 |
### this would be a good spot for hdparm, because |
|---|
| 175 |
### the whole boot process will benefit from it! |
|---|
| 176 |
|
|---|
| 177 |
echo "Initializing swap partitions..." |
|---|
| 178 |
/sbin/swapon -a |
|---|
| 179 |
|
|---|
| 180 |
/sbin/fsck -A -a -C |
|---|
| 181 |
if [ $? -gt 1 ]; then |
|---|
| 182 |
echo |
|---|
| 183 |
echo "ERROR:" |
|---|
| 184 |
echo "Your filesystem has been severely damaged. You can probably correct this" |
|---|
| 185 |
echo "problem by running e2fsck manually (eg. with the -v and -y options). After" |
|---|
| 186 |
echo "you logout, the system will reboot." |
|---|
| 187 |
echo |
|---|
| 188 |
PS1="(Repair filesystem)# " |
|---|
| 189 |
export PS1 |
|---|
| 190 |
/sbin/sulogin |
|---|
| 191 |
/bin/umount -a -r |
|---|
| 192 |
/sbin/reboot -f |
|---|
| 193 |
fi |
|---|
| 194 |
|
|---|
| 195 |
echo "Remounting root device read-write..." |
|---|
| 196 |
/bin/mount -n -v -o remount,rw / |
|---|
| 197 |
|
|---|
| 198 |
echo "" >/etc/mtab |
|---|
| 199 |
/bin/mount -f -o remount,rw / |
|---|
| 200 |
|
|---|
| 201 |
echo "Mounting other local filesystems..." |
|---|
| 202 |
/bin/mount -a -v -tnonfs |
|---|
| 203 |
|
|---|
| 204 |
echo "Setting up hostname..." |
|---|
| 205 |
/bin/hostname `cat /etc/HOSTNAME |cut -d . -f1` |
|---|
| 206 |
/bin/domainname `cat /etc/HOSTNAME |cut -d . -f2-` |
|---|
| 207 |
|
|---|
| 208 |
if [ -f "/etc/random-seed" ]; then |
|---|
| 209 |
echo "Initializing random number generator..." |
|---|
| 210 |
/bin/cat /etc/random-seed >/dev/urandom |
|---|
| 211 |
rm -f /etc/random-seed |
|---|
| 212 |
fi |
|---|
| 213 |
|
|---|
| 214 |
### removing stale PID files is good, too |
|---|
| 215 |
# echo "Removing stale PID files..." |
|---|
| 216 |
# /bin/rm /var/run/*.pid |
|---|
| 217 |
# /bin/rm /etc/dhcpc/*.pid |
|---|
| 218 |
|
|---|
| 219 |
echo "Loading keymap..." |
|---|
| 220 |
/usr/bin/loadkeys -d |
|---|
| 221 |
|
|---|
| 222 |
### I also suggest setting keyboard repeat rate and delay here: |
|---|
| 223 |
# echo "Setting keyboard rate (30) and delay (250)..." |
|---|
| 224 |
# /usr/bin/kbdrate -r 30 -d 250 |
|---|
| 225 |
|
|---|
| 226 |
### And the console font as well: |
|---|
| 227 |
# echo "Setting console font..." |
|---|
| 228 |
# /usr/bin/setfont lat9u-12.psfu.g |
|---|
| 229 |
|
|---|
| 230 |
### And if you like to have numlock on: |
|---|
| 231 |
# echo "Setting numlock on VTs 1-12 to on..." |
|---|
| 232 |
# for tty in /dev/tty{1,2,3,4,5,6,7,8,9,10,11,12}; do |
|---|
| 233 |
# /usr/bin/setleds +num < $tty |
|---|
| 234 |
# done |
|---|
| 235 |
|
|---|
| 236 |
### mplayer likes this... |
|---|
| 237 |
# echo "Configuring RTC..." |
|---|
| 238 |
# echo 1024 > /proc/sys/dev/rtc/max-user-freq |
|---|
| 239 |
|
|---|
| 240 |
echo "Setting system time from hardware clock..." |
|---|
| 241 |
/sbin/hwclock --hctosys --utc |
|---|
| 242 |
|
|---|
| 243 |
echo "Starting system and kernel log daemons...." |
|---|
| 244 |
/usr/sbin/syslogd |
|---|
| 245 |
/usr/sbin/klogd -c3 |
|---|
| 246 |
|
|---|
| 247 |
### Use modules? If yes, uncomment this: |
|---|
| 248 |
# echo "Updating module dependencies..." |
|---|
| 249 |
# /sbin/depmod -a |
|---|
| 250 |
|
|---|
| 251 |
### You may find this useful when you have some (non-networking) daemons |
|---|
| 252 |
### and an extra .rc-file for them: |
|---|
| 253 |
# echo "Starting daemons..." |
|---|
| 254 |
# if [ -x /etc/rc.d/rc.daemons ]; then |
|---|
| 255 |
# /etc/rc.d/rc.daemons |
|---|
| 256 |
# fi |
|---|
| 257 |
-------------------------end of /etc/rc.d/rc.sysinit------------------------- |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
To make the hostname lines work as expected, create a file /etc/HOSTNAME |
|---|
| 261 |
which holds your FQDN (Full Qualified Domain Name). That is, for example, |
|---|
| 262 |
foo.bar.com or gimli.gimli.org. A last note on the hwclock command: if your system |
|---|
| 263 |
clock isn't configured for using UTC (that means you're using local time) you |
|---|
| 264 |
should drop the --utc options from that line. Read the 'time' hint for more |
|---|
| 265 |
information. |
|---|
| 266 |
|
|---|
| 267 |
Now let's create the script for the single user runlevel. Since this |
|---|
| 268 |
runlevel won't be used very often to boot in, but instead to fall back to if |
|---|
| 269 |
something happens to the system, all running programs will be killed so you're |
|---|
| 270 |
in a very clean environment when running in single user mode. |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
--------------------------------/etc/rc.d/rc.1------------------------------- |
|---|
| 274 |
#!/bin/sh |
|---|
| 275 |
echo "Unmounting remote filesystems..." |
|---|
| 276 |
/bin/umount -a -tnfs |
|---|
| 277 |
|
|---|
| 278 |
# insert a line for each network card you use here. This is an example for |
|---|
| 279 |
# a single network card set-up (configured as eth0): |
|---|
| 280 |
# |
|---|
| 281 |
# echo "Bringing down network interface eth0..." |
|---|
| 282 |
# /sbin/ifconfig eth0 down |
|---|
| 283 |
|
|---|
| 284 |
echo "Sending all processes the TERM signal..." |
|---|
| 285 |
/sbin/killall5 -15 |
|---|
| 286 |
sleep 1 |
|---|
| 287 |
|
|---|
| 288 |
echo "Sending all processes the KILL signal..." |
|---|
| 289 |
/sbin/killall5 -9 |
|---|
| 290 |
----------------------------end of /etc/rc.d/rc.1---------------------------- |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
If this script has run, no daemons have been left except the kernel daemons |
|---|
| 294 |
and init. After it has finished sulogin will be started (that's what the line |
|---|
| 295 |
"su:S1:respawn:/sbin/sulogin" is for :) so only root can use the system. All |
|---|
| 296 |
virtual consoles will be disabled. |
|---|
| 297 |
|
|---|
| 298 |
Let's get on to the next script, /etc/rc.d/rc.2. This file has many common |
|---|
| 299 |
options in it, eg. to set up networking and start network daemons. Remove |
|---|
| 300 |
every line you won't use, but don't add anything before you read chapter 4. |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
--------------------------------/etc/rc.d/rc.2------------------------------- |
|---|
| 304 |
#!/bin/sh |
|---|
| 305 |
# In this example, the network card is configured with 192.168.0.2 as ip |
|---|
| 306 |
# address and a netmask of 255.255.255.0. This network card uses 192.168.0.1 |
|---|
| 307 |
# as the default gateway. This is the set up you would use if the box |
|---|
| 308 |
# 192.168.0.1 would be the gateway. |
|---|
| 309 |
|
|---|
| 310 |
### You may wish to add some commands changing sysctl states here, for example: |
|---|
| 311 |
# echo 1 > /proc/sys/net/ipv4/ip_forward # enable IP forwarding |
|---|
| 312 |
# echo 1 > /proc/sys/net/ipv4/tcp_syncookies # defend against SYN flood |
|---|
| 313 |
|
|---|
| 314 |
echo "Setting up loopback networking..." |
|---|
| 315 |
/sbin/ifconfig lo 127.0.0.1 |
|---|
| 316 |
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo |
|---|
| 317 |
|
|---|
| 318 |
echo "Setting up eth0..." |
|---|
| 319 |
/sbin/ifconfig eth0 192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0 |
|---|
| 320 |
/sbin/route add -net default gw 192.168.0.1 netmask 0.0.0.0 |
|---|
| 321 |
|
|---|
| 322 |
echo "Mounting remote filesystems..." |
|---|
| 323 |
/bin/mount -a -v -tnfs |
|---|
| 324 |
|
|---|
| 325 |
### you can create additional scripts for specific (networking) tasks, |
|---|
| 326 |
### for example NFS, which needs a lot of daemons to work (see 3.2) |
|---|
| 327 |
### or your firewall script: |
|---|
| 328 |
|
|---|
| 329 |
# if [ -x /etc/rc.d/rc.firewall ]; then |
|---|
| 330 |
# echo "Restoring firewall rules..." |
|---|
| 331 |
# /etc/rc.d/rc.firewall |
|---|
| 332 |
# fi |
|---|
| 333 |
|
|---|
| 334 |
# if [ -x /etc/rc.d/rc.netdaemons ]; then |
|---|
| 335 |
# echo "Starting network daemons..." |
|---|
| 336 |
# /etc/rc.d/rc.netdaemons |
|---|
| 337 |
# fi |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
if [ -x /etc/rc.d/rc.local ]; then |
|---|
| 341 |
/etc/rc.d/rc.local |
|---|
| 342 |
fi |
|---|
| 343 |
----------------------------end of /etc/rc.d/rc.2---------------------------- |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
Now copy /etc/rc.d/rc.2 to /etc/rc.d/rc.5 and link the |
|---|
| 347 |
aliases for runlevel 2: |
|---|
| 348 |
ln -sf /etc/rc.d/rc.2 /etc/rc.d/rc.3 |
|---|
| 349 |
ln -sf /etc/rc.d/rc.2 /etc/rc.d/rc.4 |
|---|
| 350 |
cp /etc/rc.d/rc.2 /etc/rc.d/rc.5 |
|---|
| 351 |
|
|---|
| 352 |
and add the following to the |
|---|
| 353 |
bottom of the file /etc/rc.d/rc.5: |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
------------------------------------snip------------------------------------- |
|---|
| 357 |
echo "Starting graphical login manager..." |
|---|
| 358 |
|
|---|
| 359 |
if [ -x /opt/kde/bin/kdm ]; then |
|---|
| 360 |
/opt/kde/bin/kdm -nodaemon |
|---|
| 361 |
elif [ -x /usr/bin/gdm ]; then |
|---|
| 362 |
/usr/bin/gdm -nodaemon |
|---|
| 363 |
elif [ -x /usr/X11R6/bin/xdm ]; then |
|---|
| 364 |
/usr/X11R6/bin/xdm -nodaemon |
|---|
| 365 |
else |
|---|
| 366 |
echo "You chose to start graphical login mode, but you don't have either KDM or" |
|---|
| 367 |
echo "GDM or XDM installed. This script looks for these display managers in the" |
|---|
| 368 |
echo "following locations:" |
|---|
| 369 |
echo |
|---|
| 370 |
echo " KDM /opt/kde/bin/kdm" |
|---|
| 371 |
echo " GDM /usr/bin/gdm" |
|---|
| 372 |
echo " XDM /usr/X11R6/bin/xdm" |
|---|
| 373 |
echo |
|---|
| 374 |
echo "This message will go away in 10 seconds, and after that you will be dropped" |
|---|
| 375 |
echo "in runlevel 2." |
|---|
| 376 |
sleep 10 |
|---|
| 377 |
/sbin/telinit 2 |
|---|
| 378 |
fi |
|---|
| 379 |
----------------------------end of /etc/rc.d/rc.5---------------------------- |
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
The script is pretty self-explaining. It looks for the most commonly used |
|---|
| 383 |
display managers in their default locations. If none of them is found, a |
|---|
| 384 |
warning will be displayed and the system will change to runlevel 2 with a |
|---|
| 385 |
normal console login screen. If you have a specific display manager you |
|---|
| 386 |
can leave out the 'if' and the others, of course. |
|---|
| 387 |
|
|---|
| 388 |
Now we have created all bootscripts except /etc/rc.d/rc.0 and |
|---|
| 389 |
/etc/rc.d/rc.6. Since they both perform pretty much the same function, we'll |
|---|
| 390 |
create it only once: |
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
--------------------------------/etc/rc.d/rc.0------------------------------- |
|---|
| 394 |
#!/bin/sh |
|---|
| 395 |
echo "Sending all processes the TERM signal..." |
|---|
| 396 |
/sbin/killall5 -15 |
|---|
| 397 |
sleep 1 |
|---|
| 398 |
|
|---|
| 399 |
echo "Sending all processes the KILL signal..." |
|---|
| 400 |
/sbin/killall5 -9 |
|---|
| 401 |
sleep 1 |
|---|
| 402 |
|
|---|
| 403 |
echo "Deactivating swap partitions..." |
|---|
| 404 |
/sbin/swapoff -a |
|---|
| 405 |
|
|---|
| 406 |
echo "Saving random seed to a temporary file..." |
|---|
| 407 |
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null |
|---|
| 408 |
|
|---|
| 409 |
echo "Saving the system time to hardware clock..." |
|---|
| 410 |
/sbin/hwclock --systohc --utc |
|---|
| 411 |
|
|---|
| 412 |
echo "Unmounting remote filesystems..." |
|---|
| 413 |
/bin/umount -a -f -tnfs |
|---|
| 414 |
|
|---|
| 415 |
case "$0" in |
|---|
| 416 |
*6) |
|---|
| 417 |
/sbin/reboot -w |
|---|
| 418 |
;; |
|---|
| 419 |
|
|---|
| 420 |
*0) |
|---|
| 421 |
/sbin/halt -w |
|---|
| 422 |
;; |
|---|
| 423 |
esac |
|---|
| 424 |
|
|---|
| 425 |
echo "Remounting root filesystem read-only..." |
|---|
| 426 |
/bin/mount -n -o remount,ro / |
|---|
| 427 |
|
|---|
| 428 |
echo "Flushing filesystem buffers..." |
|---|
| 429 |
/bin/sync |
|---|
| 430 |
|
|---|
| 431 |
echo "Unmounting local filesystems..." |
|---|
| 432 |
/bin/umount -a -tnonfs |
|---|
| 433 |
|
|---|
| 434 |
case "$0" in |
|---|
| 435 |
*6) |
|---|
| 436 |
echo "Please stand by while rebooting..." |
|---|
| 437 |
/sbin/reboot -d -f -i |
|---|
| 438 |
;; |
|---|
| 439 |
|
|---|
| 440 |
*0) |
|---|
| 441 |
echo "Bye..." |
|---|
| 442 |
/sbin/halt -d -f -p |
|---|
| 443 |
;; |
|---|
| 444 |
esac |
|---|
| 445 |
----------------------------end of /etc/rc.d/rc.0---------------------------- |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
Some notes on this file: the hwclock should be configured like the one in |
|---|
| 449 |
/etc/rc.d/rc.sysinit (no --utc if your hardware clock uses local time). The |
|---|
| 450 |
construction |
|---|
| 451 |
|
|---|
| 452 |
case "$0" in |
|---|
| 453 |
*6) |
|---|
| 454 |
/sbin/reboot -w |
|---|
| 455 |
;; |
|---|
| 456 |
|
|---|
| 457 |
*0) |
|---|
| 458 |
/sbin/halt -w |
|---|
| 459 |
;; |
|---|
| 460 |
esac |
|---|
| 461 |
|
|---|
| 462 |
writes some status information to /etc/wtmp. It's a good idea to do this, |
|---|
| 463 |
but you can safely remove it. At about two-third of the file, I call |
|---|
| 464 |
/bin/sync. This program flushes the filesystem buffers so you won't lose any |
|---|
| 465 |
data. Like the construct above this is optional but I recommend it. |
|---|
| 466 |
|
|---|
| 467 |
Now that we have created all the required files, some changes have to made to |
|---|
| 468 |
make them work. Run the following commands to do this: |
|---|
| 469 |
|
|---|
| 470 |
chmod 754 /etc/rc.d/rc.0 /etc/rc.d/rc.1 /etc/rc.d/rc.2 |
|---|
| 471 |
chmod 754 /etc/rc.d/rc.3 /etc/rc.d/rc.sysinit |
|---|
| 472 |
ln -s /etc/rc.d/rc.2 /etc/rc.d/rc.4 |
|---|
| 473 |
ln -s /etc/rc.d/rc.0 /etc/rc.d/rc.6 |
|---|
| 474 |
|
|---|
| 475 |
You're done! Take a deep breath, type (as root) "reboot" and watch |
|---|
| 476 |
your system boot with BSD style init scripts! If you have troubles using |
|---|
| 477 |
these scripts, drop me a line: leslie.polzer@gmx.net. |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
3.2 Creating extra scripts |
|---|
| 481 |
-------------------------- |
|---|
| 482 |
|
|---|
| 483 |
As you probably know, it is common to have a /etc/rc.d/rc.local file where |
|---|
| 484 |
you put commands in that will be executed at the very end of the boot process. |
|---|
| 485 |
You can use it to create up-to-date issue files or to pick a random |
|---|
| 486 |
message of the day. But since you created all bootscripts yourself, |
|---|
| 487 |
you can change them as much as you like, and you probably won't need this |
|---|
| 488 |
script. So what's it going to be? |
|---|
| 489 |
|
|---|
| 490 |
I personally recommend you create this script, for the purpose of |
|---|
| 491 |
portability. Many daemons write one or two lines to this file, and it saves |
|---|
| 492 |
you trouble if it's already present. This is how you create one: |
|---|
| 493 |
|
|---|
| 494 |
Put this in a file /etc/rc.d/rc.local: |
|---|
| 495 |
|
|---|
| 496 |
-------------------------------/etc/rc.d/rc.local---------------------------- |
|---|
| 497 |
#!/bin/sh |
|---|
| 498 |
-----------------------------end /etc/rc.d/rc.local-------------------------- |
|---|
| 499 |
|
|---|
| 500 |
And make it executable: |
|---|
| 501 |
|
|---|
| 502 |
chmod 754 /etc/rc.d/rc.local |
|---|
| 503 |
|
|---|
| 504 |
It is very easy for you to disable /etc/rc.d/rc.local; just remove |
|---|
| 505 |
the executable flag from the script and it will be skipped at boot time. |
|---|
| 506 |
|
|---|
| 507 |
When I showed you the synopsis of rc.d/, I also told you that you can |
|---|
| 508 |
create extra files. You might put your iptables/ipchains lines for your |
|---|
| 509 |
firewall into rc.firewall and call it from rc.{2,3}, or you may stuff |
|---|
| 510 |
all daemons essential to NFS into rc.nfs and call that from another |
|---|
| 511 |
script called rc.netdaemons, in which you start all networking daemons. |
|---|
| 512 |
|
|---|
| 513 |
Do what you like best - BSD init is IMHO closer to human thinking |
|---|
| 514 |
than SysVInit. |
|---|
| 515 |
|
|---|
| 516 |
As a final tip in this section, I would like to point out to you that I |
|---|
| 517 |
have often had a multi-user environment without networking. It would be a |
|---|
| 518 |
good practice for you to set up this environment on, for example, runlevel 5 |
|---|
| 519 |
and set it up in a secure way. This implies you have to decide whether you |
|---|
| 520 |
really need a service or not, to avoid any damage that may be caused by your |
|---|
| 521 |
ignorance. |
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
4 Final Words |
|---|
| 525 |
============= |
|---|
| 526 |
I hope you learnt from this hint how a BSD style init works. Although this |
|---|
| 527 |
setup is not the same as Slackware's or BSD's setup, the idea is basically the |
|---|
| 528 |
same. If you have comments on this hint, be they positive or negative, |
|---|
| 529 |
please mail me at leslie.polzer@gmx.net. |
|---|
| 530 |
I would like to thank all the people who emailed me so far, fixing bugs |
|---|
| 531 |
in the hint. |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
CHANGELOG: |
|---|
| 535 |
[2005-02-16] |
|---|
| 536 |
* runlevel organization fixes |
|---|
| 537 |
|
|---|
| 538 |
[2005-01-08] |
|---|
| 539 |
* changed permissions from 755 to 754 (thanks to Randy McMurchy) |
|---|
| 540 |
* removed linking from rc.2 to rc.5 - these are different files |
|---|
| 541 |
(thanks to George Boudreau from DIY Linux) |
|---|
| 542 |
* moved syncing before umounting (thanks to Noturno) |
|---|
| 543 |
|
|---|
| 544 |
[2004-09-10] |
|---|
| 545 |
* changed /tmp/random-seed to /etc/random-seed in case |
|---|
| 546 |
/tmp is mounted as tmpfs (thanks to C. T. Waley) |
|---|
| 547 |
|
|---|
| 548 |
[2004-06-05] |
|---|
| 549 |
* corrected a typo |
|---|
| 550 |
* corrected a mistake where runlevel 3 would be 5 |
|---|
| 551 |
|
|---|
| 552 |
[2003-10-02] |
|---|
| 553 |
* New maintainer |
|---|
| 554 |
* Conversion to new hint format |
|---|
| 555 |
|
|---|