1 AUTHOR: Leslie Polzer <leslie.polzer@gmx.net>
2 AUTHOR: Marc Heerdink <marc@koelkast.net>
6 LICENSE: GNU Free Documentation License Version 1.2
8 SYNOPSIS: Setting up LFS with BSD/Slackware style init.
11 The BSD style is often perceived as a more simple (in contrast to SysVInit) way
12 of booting your system and controlling runlevels.
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
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).
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.
47 This hint will never be complete, comments can be sent to
48 me <leslie.polzer@gmx.net>.
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).
62 You'll have to choose what runlevels you want to use before you begin,
63 too. Somewhat default runlevels are thus:
66 RUNLEVEL: | DESCRIPTION:
67 ----------+----------------------
71 2 | Multi user runlevel with console login
74 5 | Multi user runlevel with graphical login
76 ----------+----------------------
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
90 To give you an idea of how BSD init works, I'll show you the final directory
94 + rc.sysinit # system initialization
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
104 ...and maybe later, to your liking, these and more:
111 I suggest you create the directory and basic files (the first list) now.
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.
119 2.3 Setting up the inittab
120 --------------------------
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
127 Now let's get down to business! Put this in your /etc/inittab:
130 -------------------------------/etc/inittab----------------------------------
133 si:S:sysinit:/etc/rc.d/rc.sysinit
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
143 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -r now
145 su:S1:respawn:/sbin/sulogin
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------------------------------
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).
160 3 Creating the boot scripts
161 ===========================
163 3.1 Creating essential scripts
164 ------------------------------
166 Let's create /etc/rc.d/rc.sysinit first:
169 -----------------------------/etc/rc.d/rc.sysinit----------------------------
171 echo "Mounting root device read-only..."
172 /bin/mount -n -o remount,ro /
174 ### this would be a good spot for hdparm, because
175 ### the whole boot process will benefit from it!
177 echo "Initializing swap partitions..."
181 if [ $? -gt 1 ]; then
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."
188 PS1="(Repair filesystem)# "
195 echo "Remounting root device read-write..."
196 /bin/mount -n -v -o remount,rw /
199 /bin/mount -f -o remount,rw /
201 echo "Mounting other local filesystems..."
202 /bin/mount -a -v -tnonfs
204 echo "Setting up hostname..."
205 /bin/hostname `cat /etc/HOSTNAME |cut -d . -f1`
206 /bin/domainname `cat /etc/HOSTNAME |cut -d . -f2-`
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
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
219 echo "Loading keymap..."
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
226 ### And the console font as well:
227 # echo "Setting console font..."
228 # /usr/bin/setfont lat9u-12.psfu.g
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
236 ### mplayer likes this...
237 # echo "Configuring RTC..."
238 # echo 1024 > /proc/sys/dev/rtc/max-user-freq
240 echo "Setting system time from hardware clock..."
241 /sbin/hwclock --hctosys --utc
243 echo "Starting system and kernel log daemons...."
247 ### Use modules? If yes, uncomment this:
248 # echo "Updating module dependencies..."
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
257 -------------------------end of /etc/rc.d/rc.sysinit-------------------------
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
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.
273 --------------------------------/etc/rc.d/rc.1-------------------------------
275 echo "Unmounting remote filesystems..."
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):
281 # echo "Bringing down network interface eth0..."
282 # /sbin/ifconfig eth0 down
284 echo "Sending all processes the TERM signal..."
288 echo "Sending all processes the KILL signal..."
290 ----------------------------end of /etc/rc.d/rc.1----------------------------
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.
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.
303 --------------------------------/etc/rc.d/rc.2-------------------------------
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.
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
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
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
322 echo "Mounting remote filesystems..."
323 /bin/mount -a -v -tnfs
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:
329 # if [ -x /etc/rc.d/rc.firewall ]; then
330 # echo "Restoring firewall rules..."
331 # /etc/rc.d/rc.firewall
334 # if [ -x /etc/rc.d/rc.netdaemons ]; then
335 # echo "Starting network daemons..."
336 # /etc/rc.d/rc.netdaemons
340 if [ -x /etc/rc.d/rc.local ]; then
343 ----------------------------end of /etc/rc.d/rc.2----------------------------
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
352 and add the following to the
353 bottom of the file /etc/rc.d/rc.5:
356 ------------------------------------snip-------------------------------------
357 echo "Starting graphical login manager..."
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
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:"
370 echo " KDM /opt/kde/bin/kdm"
371 echo " GDM /usr/bin/gdm"
372 echo " XDM /usr/X11R6/bin/xdm"
374 echo "This message will go away in 10 seconds, and after that you will be dropped"
375 echo "in runlevel 2."
379 ----------------------------end of /etc/rc.d/rc.5----------------------------
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.
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
393 --------------------------------/etc/rc.d/rc.0-------------------------------
395 echo "Sending all processes the TERM signal..."
399 echo "Sending all processes the KILL signal..."
403 echo "Deactivating swap partitions..."
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
409 echo "Saving the system time to hardware clock..."
410 /sbin/hwclock --systohc --utc
412 echo "Unmounting remote filesystems..."
413 /bin/umount -a -f -tnfs
425 echo "Remounting root filesystem read-only..."
426 /bin/mount -n -o remount,ro /
428 echo "Flushing filesystem buffers..."
431 echo "Unmounting local filesystems..."
432 /bin/umount -a -tnonfs
436 echo "Please stand by while rebooting..."
437 /sbin/reboot -d -f -i
445 ----------------------------end of /etc/rc.d/rc.0----------------------------
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
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.
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:
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
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.
480 3.2 Creating extra scripts
481 --------------------------
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?
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:
494 Put this in a file /etc/rc.d/rc.local:
496 -------------------------------/etc/rc.d/rc.local----------------------------
498 -----------------------------end /etc/rc.d/rc.local--------------------------
500 And make it executable:
502 chmod 754 /etc/rc.d/rc.local
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.
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.
513 Do what you like best - BSD init is IMHO closer to human thinking
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
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
536 * runlevel organization fixes
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)
545 * changed /tmp/random-seed to /etc/random-seed in case
546 /tmp is mounted as tmpfs (thanks to C. T. Waley)
550 * corrected a mistake where runlevel 3 would be 5
554 * Conversion to new hint format