Upload
ifama
View
36
Download
0
Embed Size (px)
DESCRIPTION
Unix Startup. Guntis Barzdins Girts Folkmanis Juris Krūmiņš. System Lifecycle: Ups & Downs. start_kernel. sleep? (hlt). LILO. shutdown. init. Power on. Power off. Boot. Kernel Init. OS Init. RUN!. Shut down. Boot Terminology. Loader: Program that moves bits from disk (usually) - PowerPoint PPT Presentation
Citation preview
Unix Startup
Guntis BarzdinsGirts FolkmanisJuris Krūmiņš
System Lifecycle: Ups & Downs
Poweron
Poweroff
Boot KernelInit
OSInit
RUN! Shutdown
Boot Terminology
Loader: Program that moves bits from disk (usually) to memory and then transfers CPU control to the newly“loaded” bits (executable).
Bootloader / Bootstrap: Program that loads the “first program” (the kernel).
Boot PROM / PROM Monitor / BIOS: Persistent code that is “already loaded” on power-up.
Boot Manager: Program that lets you choose the “first program” to load.
LILO: LInux LOader
A versatile boot manager that supports: Choice of Linux kernels. Boot time kernel parameters. Booting non-Linux kernels. A variety of configurations.
Characteristics: Lives in MBR or partition boot sector. Has no knowledge of filesystem structure so… Builds a sector “map file” (block map) to find kernel.
/sbin/lilo – “map installer”. /etc/lilo.conf is lilo configuration file.
Example lilo.conf File
boot=/dev/hdamap=/boot/mapinstall=/boot/boot.bprompttimeout=50default=linux
image=/boot/vmlinuz-2.2.12-20label=linuxinitrd=/boot/initrd-2.2.12-20.imgread-onlyroot=/dev/hda1
LILO v.s. GRUB
LILO Run LILO to modify mini-bootloader in the MBR Cannot read file system itself
GRUB Multistage loader Can read file-system itself
Parameter passing (runlevel, init) to kernel Actually hacking – modifies address and name inside kernel for
the process to start
Init process (1)
initWhen the kernel has started itself (has been loaded into memory, has started running, and has initialised all device drivers and data structures and such), it finishes its own part of the boot process by starting a user level program, init. Thus, init is always the first process (its process number is always 1).
The kernel looks for init in a few locations that have been historically used for it, but the proper location for it (on a Linux system) is /sbin/init. If the kernel can't find init, it tries to run /bin/sh, and if that also fails, the startup of the system fails.
When init starts, it finishes the boot process by doing a number of administrative tasks, such as checking filesystems, cleaning up /tmp, starting various services, and starting a getty for each terminal and virtual console where users should be able to log in (see Chapter 10).
Unix Process Hierarchy
Login shell
ChildChildChild
GrandchildGrandchild
[0]
Daemone.g. httpd
init [1]/etc/inittab
pstree
Kernel threads, not real processes
Forked processes for network connections
Startup Sequence
Power-onPower-onBoot loaderLILO
Boot loaderLILO
Load KernelLoad Kernel
Createinit
process
Createinit
process
rc.sysinitrc.sysinitrunlevel
0-6runlevel
0-6rc.localrc.local
Linux
Initialisation Scripts
ReadyReady
hardware
Different Unix startup files..
Unix systems are usually based in the AT&T System III & V or BSD work.
Sun Mircosystems Solaris 2.X (formally SunOS) BSD-ish DEC OSF/1 is BSD-ish (DEC use to do Ultrix) IBM AIX (neither ATT or BSD but something else) HP HP-UX (BSD-ish) Silicon Graphics, IRIX (ATTish) SCO (Santa Cruz Operation) PC unix (ATT) Linux, kernel from Linus Torvalds (BSD-ish for admin, ATT-ish
for programming) Distributions Slackware, Redhat, SuSE, Debian
other free PC Unixs, NetBSD, 386BSD, free BSD
Startup files How to start other services not in kernel? BSD mode
/etc/rc, /etc/rc.boot and /etc/rc.local System V
Startup runlevels init process and /etc/inittab file
On linux: 0: shutdown and halt 1 single-user mode 2 multiuse mode, no file sharing 3 full multiuser. 4 unused 5 X windows console 6 shuts down and reboots
Sample BSD Startup Scripts/etc/rc.boot
First rc script to run is /etc/rc.boot The first two lines set HOME and PATH environment variables Executes basic system commands during boot hostname file in /etc for each network interface
enables IP networking on each interface
Sample BSD Startup Scripts/etc/rc.boot (cont.)
Address or hostname of default Internet gateway is read from /etc/defaultrouter
non-local NW connections up prior to more complicated routing in boot process
/usr filesystem read-only for system check to see if /fastboot exists Yes: system shut down cleanly~ filesystems in consistent state No: all filesystems listed in /etc/fstab checked in fsck
If disks check cleanly~ rc.boot runs /etc/rc.single
Sample BSD Startup Scripts/etc/rc.single
Commands in /etc/rc.single are executed at boot time even if not using single mode
Remounts / and /usr filesystems read/write if not remounted~ system not able to come up
Cleans out /etc/mtabfile and adds entries for / and /usr was previously mounted but not in mtab file because root
filesystem not writable /usr/kvm mounted~ clean up shared library cache
Sample BSD Startup Scripts/etc/rc.single
/etc/utmp file cleaned out contains user list of current log ins
tzsetup command sets local time zone & status of daylight savings time (kernal is GMT)
loadkeys command sets keyboard mapping rc.single exits~rc.boot exits No problems in autoboot mode the next init process is
/etc/rc If problem~single-user (sh process) on console
Sample BSD Startup Scripts/etc/rc
/etc/rc is the main system startup up script in autoboot after rc.boot if single-user: rc after shell is terminated
if root filesystems not writable~ rerun rc.single clean up shared library cache remove /fastboot file /etc/passwd file edited ~system crashes
vipw and /etc/rc script make sure password file not destroyed at crash
Sample BSD Startup Scripts/etc/rc (cont.)
Enable quotas /bin/ps -u cleans out the ps database (status of
processes) /etc/nologin created by shutdown to prevent logins
during shutdown executes rc.local script swapon -a to make use of all swap partitions listed in
etc/fstab expreserve: looks in /tmp to find files that were edited
when system went down
Sample BSD Startup Scripts/etc/rc (cont.)
Start standard system daemons (i.e., lpd, inetd, update, uushed)
Sample BSD Startup Scripts/etc/rc.local
/etc/rc.local contains commands for local system portmap daemon maps RPC (remote procedure call)
service numbers to the NW ports of appropriate servers NIS (NW info service) Domain Name set from /etc/default
domain set subnet mask of all machines interfaces default route reset~ if no default routing daemon run list current configuration of NW interfaces on console
Sample BSD Startup Scripts/etc/rc.local (cont.)
All NFS filesystems mounted named (server for Domain Name system) maps between
hostnames and Internet addresses Client side NFS daemon run (biod) syslogd: responsible for managing log messages save kernel core dump in /var/crash/hostname
Image saved on swap partition~ save image to real filesystem Clean up temporary mail lock files and start sendmail
Sample BSD Startup Scripts/etc/rc.local (cont.)
Make machine NFS Server if filesystems need to be exported
Daemon to support diskless clients rpc.statd and rpc.lockd manage advisory locks on
NFS filesystems Start automount daemon 3rd party vendor install scripts Appletalk protocol stack started Licensed software add-ons
System V Run Levels
Level 0 – shutdown Level 1 or S – single-user mode Level 2 thru 5 – multi-user mode Level 6 - reboot
Startup Script Directories
/etc/inittab tells init where scripts are /etc/init.d script directory /etc/rc2.d link to script directory
Startup files
Understanding /etc/inittab Label:runlevel:action:process
id:5:initdefault:
# System initialization.si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6
Some Linux inittab action valus
Action MeaningBoot Runs when system boots
Bootwait Init waits for complete
Ctrlaltdel
Initdefault Set the detault runlevel
off Disable the entry
Once For every runlevel
Powerfail When init receive SIGPWR signal
Powerokwait SIGPWR and /etc/powerstatus has ok
Respawn Restart the process wheneven it termincates
Sysinit Before any boot
Wait Upon entrying the run mode and waits to complete
Linux startup - rc.sysinit script
/etc/rc.d/rc.sysinit - does a range of basic tasks including configures networking sets host name checks the root file system for repairs check root file system quota & turns quotas for groups and
users mount non-root file systems and checks them for repairs turns on swapping (virtual memory subsystem) checks and loads modules (drivers)
(see /var/log/messages)
Linux Run Levels
Linux defines 7 run levels Each run level defines a set of commands that are run to stop and start
processes. The actual commands are held in /etc/init.d directory The run level directories rc0.d, rc2.d…rc6.d contain links to the actual
commands Each command is prefixed with S or K and a number 00-99
S prefix means that a process should be started e.g. S10network K prefix means that a process should be stopped (killed) K70syslog
The numbers determine the order in which the commands are run from lowest first to highest last
Linux Run Levels 0-2
Runlevel 0 Directory /etc/rc.d/rc0.d Actually shutdown sequence
Kill all processes Turn off virtual memory system (i.e. swap partition) unmounts swap and file systems
Runlevel 1 /etc/rc.d/rc1.d single user mode used for maintenance by system administrators when they need sole
control of machine, e.g. reconfiguring hardware installing software Runlevel 2 /etc/rc.d/rc2.d
Multi-user + networking (minus NFS)
Linux Run level 3-6
Runlevel 3 /etc/rc.d/rc3.d Default run level multi-user + NFS
Runlevel 4 /etc/rc.d/rc4.d not defined ( available for customization)
Runlevel 5 /etc/rc.d/rc5.d Same as 3 under Redhat this but includes starting X windows
Runlevel 6 /etc/rc.d/rc6.d reboot similar to 0 but allow allows option to shutdown (halt) or reboot
Shutdown
shutdown allows... users to be warned the systems is going down the contents of disk caches to be written disk file systems to be marked as having been closed properly
( avoid file system check on next startup) Access to the shutdown command is restricted (it is in
/sbin) eg shutdown -h now
h = halt
r = reboot
Init scripts in Gentoo
Named (not numbered) run levels. Smart dependencies.
Scripts can ‘use’ or ‘depend’ on others. Start / Stop / Pause. /etc/runlevels/default/.
Internet Daemon Daemon inetd started at boot time Configuration file /etc/inetd.conf
Name, type, protocol, wait-status, uid, server, arguments
#
ftp stream tcp6 nowait root /usr/sbin/tcpd in.ftpd
telnet stream tcp6 nowait root /usr/sbin/tcpd in.telnetd
#
# Mail is a useful thing...
pop3 stream tcp nowait root /etc/mail/popper popper -s
imap stream tcp nowait root /etc/mail/imapd imapd
Internet Daemon
When to modify inetd.conf Disable a service
Add a # at the beginning of the entrySend hang-up to inetd
kill –HUP processid
Enable a service Change the path Modify arguments
Extended Internet Daemon
Daemon xinetd Configuration file /etc/xinetd.conf and /etc/xinetd.d
Attribute/value pair Diable = yes/no
Setup automatic Mounting
/etc/fstab /etc/vfstab
# Device Mpoint FStype Opt Dump Pass/dev/sd01sf /new ufs rw 0 2/dev/da0b none swap sw 0 0
Sample Directory Tree with Mount Points
/b oo t/d e v /h d a1
/u s r/d e v /h d a5
/h om e/d e v /h d a6
sw a p/d e v /h d a7
/va r/d e v /h d a8
//d e v /h d a9
Mounting and Unmounting File Systems
File Systems mounted with the mount command:mount [options] device directoryFor example:mount –o rw –t ext2 /dev/hda10 /tmp
File systems umounted with the umount command:umount [-f] directory For example:umount /tmp
File systems should only be umounted when they are not in use.
/etc/fstab
Configuration file for all partitions known to the system. Entry format:/dev/device /dir/to/mount fstype parameters fs_freq fs_passnoSample entry:/dev/hda10 /tmp ext2 defaults 1 2
For entries in /etc/fstab, can run mount command with just mount point:> mount /tmpTo mount all file systems:> mount -a
Scheduling processes - cron
Many aspects of system administration require things to be done on a routine basis
Rotating logs building help files checking disk space checking permissions
Remembering to do thing is error prone Unix provides scheduling mechanism refereed to as cron. Cron has two parts
Daemon - crond table of actions /etc/crontab
Cron
the crond Daemon is started at boot time the daemon ‘wakes up’ every minute to check its
table of actions if their is something to do -> run command if nothing to do --> go back to sleep for 1 min
Cron table is a list (time,commnd) pairs. The format is
minute hour day month dayofweek command
Crontab
Commands can be scheduled by minute (0 59) Hour ( 0 to 23) Day of the month (1 - 31) Month ( 1 to 12) Day of the week (0=Sunday 6 = sat, or use mon,tues,wed)
Example01 * * * * commnd2 # hourly at 1 minute past
* 1 * * * commnd2 # daily at 1 am
04 1 * * * commands 3 - run at 4 minute past 1 each day* means ‘check every’
Cron
Under Redhat Linux the cron table is used to execute a set of commands in some special directories /etc/cron.hourly /etc/cron.daily
contains logrotate, makewhatis,slocate,tmpwatch /etc/cron.weekly /etc/cron.monthly
You can add you own commands to the appropriate directory, but remember they need to be ‘batch’ commands as they will run automatically
Crontab Files
Minute 0-59 Hour 0-23 Day 1-31 Month 1-12 Weekday 0-6 (0=Sunday)
* Matches everything 1-3 Matches range 1,5 Matches Series
Examples
15,45 10 * * 1-5
write garth % Hi Garth % get a job
30 2 * * 1 (cd /user/joe/p; make)find /tmp –atime +3 –exec rm –f {} ‘;’
Output mailed to owner of crontab file
crontab commands
crontab Replace ^C exit crontab –l List crontab –e Edit crontab –l > cronfile crontab cronfile
cron.allow cron.deny
Common Uses for CRON
Cleaning the filesystem Distribution of config files Rotating log files Backups
WebminWebmin
Webmin is a web-based interface for system administration for Unix. Using any browser that supports tables and forms (and Java for the File Manager module), you can setup user accounts, Apache, DNS, file sharing and so on.
http://www.webmin.com
Advanced Boot Concepts
Initial ramdisk (initrd) – two-stage boot for flexibility: First mount “initial” ramdisk as root. Execute linuxrc to perform additional setup, configuration. Finally mount “real” root and continue. See Documentation/initrd.txt for details. Also see “man initrd”.
Net booting: Remote root (Diskless-root-HOWTO). Diskless boot (Diskless-HOWTO).
System initialization
Overview of the PC Boot Process When a PC is powered on, the BIOS
(Basic Input-Output System) runs first, followed by a boot loader and finally the operating system initialization routine.
System initialization
The BIOS When power is initially applied to the computer this
triggers the RESET pin on the processor. This causes the processor to read from memory location 0xFFFFFFF0 and begin executing the code located there. This address is mapped to the Read-Only Memory (ROM) containing the BIOS. The BIOS must poll the hardware and set up an environment capable of booting the operating system. BIOS functionality can be broken into three areas: Power On Self Test (POST), Setup and Boot.
The last action of the BIOS is to execute the 19h interrupt, which loads the first sector of the first boot device. Since this is the location of the boot loader, execution of the 19h interrupt transfers control to the boot loader.
System initialization The Boot Loader
Once the BIOS loads the first sector of the boot device into RAM, the boot loader begins execution. In the case of a hard drive, this first sector is referred to as the Master Boot Record (MBR). The MBR contains the partition table describing the partitions defined on the hard drive. It also contains a program, the boot loader, which will load the first sector of the partition marked as active into RAM and execute it.
The size of the MBR is limited to one sector on disk or 512 bytes, since it is located within the first sector of the drive at cylinder 0, head 0, sector 1.
Typically boot loaders have been highly integrated with the operating system that they support. This integration cuts down on the operations a boot loader must perform, making a 512 byte boot loader feasible. When more functionality is required, a multi-stage boot loader may be used.
A multi-stage boot loader provides more function and flexibility by working around the 512 byte size limitation. Rather than consisting of a single program which loads the operating system directly, multi-stage boot loaders divide their functionality into a number of smaller programs that each successively load one another.
System initialization
OS Initialization Once the boot loader has loaded the OS image into memory,
control is transferred to the OS. A large aspect of initialization for any operating system is the
establishment of virtual memory management. On an Intel-based system this typically involves setting up the Global Descriptor Table (GDT), creating a Local Descriptor Table (LDT), switching the processor into protected memory mode, setting up page directories and enabling paging.
Additional tasks include device driver initialization and the assignment of interrupts in the Interrupt Descriptor Table (IDT).
Another major initialization task is establishing support for various file system types and mounting a root file system.
System initialization OS Initialization
The initial process must explicitly do for itself all the tasks accomplished by a call to fork(). This initial process, numbered 0 on UNIX systems.
Process 0 must be able to self-generate its own process context. Once this context has been established, the system has the capability to suspend and resume execution of Process 0 just as it would any other process. Once established, the role of Process 0 differs by operating system.
Process 1, commonly referred to as the init process, is the first process forked from Process 0.
Once Process 1 has been forked from Process 0, often a number of additional kernel space processes are created to handle additional kernel space tasks. Once all of these are running, the kernel space operating system initialization is complete.
System initialization
System initialization OpenBSD employs a two-stage boot loading process, if
one does not count the MBR as a separate “stage.” The first stage is handled by a boot loader program called biosboot, while the secondary boot loader is called simply boot.
The boot program sets up an environment suitable for transferring control to the kernel image. It also provides an interactive prompt for user input of additional boot parameters. The main tasks of the boot program are:1. Switching the CPU into protected mode2. Probing for console devices and displaying
subsequent messages to the discovered consoles3. Detecting memory, both that reported by the BIOS
and extended memory4. Detecting if the BIOS supports Advanced Power
Management (APM)
System initialization
System initialization
System initialization
1. A “pagedaemon” process to handle page swapping for the virtual memory subsystem,
2. A “reaper” process to free the resources still allocated to dead processes,
3. A “cleaner” process to clear out dirty buffers found in the BQ_DIRTY buffer queue,
4. An “update” process for synchronizing the file systems,
5. An “aiodoned” process for handling completed asynchronous I/O operations,
System initialization
With all kernel threads running, only a few finishing touches are needed. The random number generator is seeded and the generation of process identification numbers is set up such that each successive process will be given a larger pseudo-random number than its predecessor. At this point, Process 0 finally enters its main loop by calling uvm_scheduler(). This function has Process 0 continually check for processes that are in a runnable state but not resident in memory and swaps them in. Control never returns to the main() function from this call and one could say the operating system is truly running.
System initialization
System initialization
System initialization
Userspace system initialization
Historically there are two initialization systems : System V BSD
These two system differ with names, script running order, directory hierarchy which hold initialization scripts.
Linux systems mainly use System V initialization system. Exclude Slackware, whose initialization system very similar to BSD.
Userspace system initialization
Kernel start up root file system in ro mode and run init process As a result we have:
ro file system init process
The next system step initializing user space environment greatly depends on init configuration file /etc/inittab
It’s very important to understand that until this moment it doesn’t matter what initialization system will be used.
Userspace system initialization
INIT Starting from this point next system behavior greatly
depend on how init program configuration created. Because kernel mount root file system in ro mode init
process can access it’s configuration file /etc/inittab.
Userspace system initialization
1. When it’s time to create process, the kernel first of all try to run program mentioned in rdinit= boot option.
2. If rdinit= boot option didn’t specify path to init programm, kernel try to run /init3. If there’s no /init program, kernel try to run program from init= boot option4. If init= option didn’t specify path, kernel try /sbin/init5. If there’s problem with /sbin/init, kernel try /etc/init6. It there’s problem with /etc/init, then kernel try /bin/init7. If there’s problem running /bin/init, then kernel try to run /bin/sh8. If there’s problem with /bin/sh, then kernel panic with error message “No init
found ….”
Userspace system initialization Run levels
There are 7 runlevels: 0-6 System at any time working in one of this runlevels You, as administrator of the system can switch system from
one runlevel to another using telinit or init programs 0 runlevel – shutdown system 1 runlevel – single user mode 2 runlevel – in most cases same as runlevel 3 but without network file system,
at least in RedHat or SUSE linux 3 runlevel – multiuser mode. 4 runlevel – In Slackware used for GUI login. RedHat and SUSE linux don’t
use this runlevel. 5 runlevel – RedHat and SUSE linux use for GUI login. Slackware don’t use
this level 6 runlevel – system reboot level
Userspace system initialization
Slackware system initialization: Slackware system initialization use BSD style system
initialization scripts. All scripts are in /etc/rc.d directory
Userspace system initialization
/etc/rc.d/rc.S file Based in /etc/inittab file rc.S file will be executed the first one
no matter which runlevel system will run.1. Based on #!/bin/sh we can tell, that it’s a shell script.2. First of all we define PATH environment variable
PATH=/sbin:/usr/sbin:/bin:/usr/bin 3. Then we mount proc filesystem to /proc diretory
/sbin/mount -v proc /proc -n -t proc
Userspace system initialization
4. Check if we can run hotplug system if [ -w /proc/sys/kernel/hotplug ]; then
if grep -w nohotplug /proc/cmdline 1> /dev/null 2> /dev/null ; then echo "/dev/null" > /proc/sys/kernel/hotplug
elif [ ! -x /etc/rc.d/rc.hotplug ]; then echo "/dev/null" > /proc/sys/kernel/hotplug
fi fi
5. Check if we can run devfs script and use devfs filesystemif [ -x /etc/rc.d/rc.devfsd ]; then
/etc/rc.d/rc.devfsd start fi
Userspace system initialization
6. Check if we can use virtual sysfs filesystemif [ -d /sys ]; then
if cat /proc/filesystems | grep -w sysfs 1> /dev/null 2> /dev/null then
if ! cat /proc/mounts | grep -w sysfs 1> /dev/null 2> /dev/null then /sbin/mount -v sysfs /sys -n -t sysfs
fi fi
fi
7.Check if it’s possible to run udev programm.if [ -x /etc/rc.d/rc.udev ]; then
if ! grep -w nohotplug /proc/cmdline 1> /dev/null 2> /dev/null; then /etc/rc.d/rc.udev fi
fi
Userspace system initialization
8. Turn on all swap filesystem/sbin/swapon -a
9. Check what mode root filesystem have been mountedREADWRITE=no if touch /fsrwtestfile 2>/dev/null; then
rm -f /fsrwtestfile READWRITE=yes
else echo "Testing root filesystem status: read-only filesystem"
fi
10. Check is it necessary to force file system check:if [ -r /etc/forcefsck ]; then
FORCEFSCK="-f" fi
Userspace system initialization11. Check if it’s necessary to check root filesystemif [ ! -r /etc/fastboot ]; then
echo "Checking root filesystem:" /sbin/fsck $FORCEFSCK -C -a / RETVAL=$?
fi
12. Check fsck program return codeif [ $RETVAL -ge 2 ]; then
if [ $RETVAL -ge 4 ]; then echo PS1="(Repair filesystem) \#"; export PS1 sulogin
else echo
fi echo "Unmounting file systems." /sbin/umount -a -r /sbin/mount -n -o remount,ro / echo "Rebooting system." sleep 2 reboot -f
fi
Userspace system initialization
13. Ir 12 pint are ok, then remount root filesystem in rw mode/sbin/mount -w -v -n -o remount / if [ $? -gt 0 ] ; then
echo read junk;
fi
Userspace system initialization
14. Set system timeif [ -x /sbin/hwclock ]; then
if grep "^UTC" /etc/hardwareclock 1> /dev/null 2> /dev/null ; then echo "Setting system time from the hardware clock (UTC)." /sbin/hwclock --utc --hctosys
else echo "Setting system time from the hardware clock
(localtime)." /sbin/hwclock --localtime --hctosys
fi fi
15. Try to load kernel modulesif [ -x /etc/rc.d/rc.modules -a -r /proc/modules ]; then
. /etc/rc.d/rc.modules fi
Userspace system initialization
16. Try to load sysctl kernel configurationif [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then
/sbin/sysctl -e -p /etc/sysctl.conf fi
17. If there’s no /etc/fastboot file, then other file systems will be checked.if [ ! -r /etc/fastboot ]; then
/sbin/fsck $FORCEFSCK -C -R -A -a fi
18. Mount all file systems from /etc/fstab file except ntfs and smbfs file systems/sbin/mount -a -v -t nonfs,nosmbfs,noproc
Userspace system initialization
19. Repeatedly turn on swap filesystem/sbin/swapon -a
20. Delete temporary files ( cd /var/log/setup/tmp && rm -rf * ) /bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin
/var/run/lpd* \ /var/run/ppp* /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot
21. If kernel use initrd technology, then turn off RAM disk, delete initrd directory and free memory
if [ -d /initrd ]; then /sbin/umount /initrd 2> /dev/null rmdir /initrd 2> /dev/null blockdev --flushbufs /dev/ram0 2> /dev/null
fi
Userspace system initialization
22. Create utmp filetouch /var/run/utmp chown root.utmp /var/run/utmp chmod 664 /var/run/utmp
23. Create motd fileecho "$(/bin/uname -sr)." > /etc/motd
24. If it’s necessary we can use System V initialization scriptsif [ -x /etc/rc.d/rc.sysvinit ]; then . /etc/rc.d/rc.sysvinit fi
Userspace system initialization
25. Create everything for random number generator if [ -f /etc/random-seed ]; then
echo "Using /etc/random-seed to initialize /dev/urandom." cat /etc/random-seed > /dev/urandom
fi if [ -r /proc/sys/kernel/random/poolsize ]; then
dd if=/dev/urandom of=/etc/random-seed count=1 \ bs=$(cat /proc/sys/kernel/random/poolsize) 2> /dev/null
else dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
fi chmod 600 /etc/random-seed
Userspace system initialization
/etc/rc.d/rc.modules user direct modprobe program execution to load kernel modules. All you have to do – uncomment needed module, ex.:/sbin/modprobe 3c503
/etc/rc.d/rc.modules is also used for loading network card modules, by the means of executing /etc/rc.d/rc.netdevice scriptif [ -x /etc/rc.d/rc.netdevice ]; then
. /etc/rc.d/rc.netdevice fi
Userspace system initialization
/etc/rc.d/rc.S script used for: Activating swap space File system check File system mounting Loading kernel modules, loading network drivers and
so on, by executing /etc/rc.d/rc.modules script Some other system startup behavior
Userspace system initialization
/etc/rc.d/rc.M script /etc/rc.d/rc.M script used to bring system to 2, 3 and 4 runlevel.1. Going multiuser:
echo "Going multiuser..."
2. Set terminal parameters:/bin/setterm -blank 15 -powersave powerdown -powerdown 60
3. Check /etc/HOSTNAME file and set system hostnameif [ -r /etc/HOSTNAME ]; then
/bin/hostname $(cat /etc/HOSTNAME | cut -f1 -d .) else
echo "darkstar.example.net" > /etc/HOSTNAME /bin/hostname darkstar fi
Userspace system initialization
4. Save all kernel messages to /var/log/dmesg file:/bin/dmesg -s 65536 > /var/log/dmesg
5. Start up SYSLOG daemon:if [ -x /etc/rc.d/rc.syslog -a -x /usr/sbin/syslogd -a -d /var/log ] then
. /etc/rc.d/rc.syslog start fi
6. Starp up pcmcia controller supportif [ -x /etc/rc.d/rc.pcmcia ] ; then
. /etc/rc.d/rc.pcmcia start if [ -r /var/run/cardmgr.pid ]; then
sleep 5 fi
fi
Userspace system initialization
7. Start up network phase 1 initializationif [ -x /etc/rc.d/rc.inet1 ]; then
. /etc/rc.d/rc.inet1 fi
8. Hotplug support start upif [ -x /etc/rc.d/rc.hotplug -a -r /proc/modules ]; then
if ! grep nohotplug /proc/cmdline 1> /dev/null 2> /dev/null ; thenecho "Activating hardware detection: /etc/rc.d/rc.hotplug start" . /etc/rc.d/rc.hotplug start fi
fi
Userspace system initialization
9. Start up network phase 2 initializationif [ -x /etc/rc.d/rc.inet2 ]; then
. /etc/rc.d/rc.inet2 fi
10. Remove temporary files/bin/rm -f /var/lock/* /var/spool/uucp/LCK..* \
/tmp/.X*lock /tmp/core /core 2> /dev/null
11. Change root directory access mode and set sticky bit on /tmp and /var/tmp directorychmod 755 / 2> /dev/null chmod 1777 /tmp /var/tmp
Userspace system initialization
12. Create dynamic loadable library cacheif [ -x /sbin/ldconfig ]; then
echo "Updating shared library links: /sbin/ldconfig" /sbin/ldconfig
fi
13. Start simple DNS cache serverif [ -x /etc/rc.d/rc.dnsmasq ]; then /etc/rc.d/rc.dnsmasq start fi
14. Starp up CUPS un LPRng print systemif [ -x /etc/rc.d/rc.cups ]; then
/etc/rc.d/rc.cups start elif [ -x /etc/rc.d/rc.lprng ]; then
. /etc/rc.d/rc.lprng start fi
Userspace system initialization
15. Start up support for “BSD accounting” subsystemif [ -x /sbin/accton -a -r /var/log/pacct ]; then
/sbin/accton /var/log/pacct chmod 640 /var/log/pacct echo "Process accounting turned on."
fi
16. Start cron daemonif [ -x /usr/sbin/crond ]; then
/usr/sbin/crond -l10 >>/var/log/cron 2>&1fi
17. Start atdif [ -x /usr/sbin/atd ]; then
/usr/sbin/atd -b 15 -l 1 fi
Userspace system initialization
18. Start up disk quota mechanismif grep -q quota /etc/fstab ; then
if [ -x /sbin/quotacheck ]; then echo "Checking filesystem quotas: /sbin/quotacheck -avugm" /sbin/quotacheck -avugm
fi if [ -x /sbin/quotaon ]; then
echo "Activating filesystem quotas: /sbin/quotaon -avug" /sbin/quotaon -avug
fi fi
19. Start up sendmail systemif [ -x /etc/rc.d/rc.sendmail ]; then
. /etc/rc.d/rc.sendmail start fi
Userspace system initialization
20. The last one will be /etc/rc.d/rc.local script, which is used for customize system start up and execute applications without System V or BSD initialization scripts.
Userspace system initialization
If we need to execute script upon system start up we need to set execution permissions on this script
And vice versa, if we don’t need to execute this service, don’t make it executable.
Every start up script – relatively simple shell script. It may handle command line parameters like: start – to start service, and stop – to stop service
If you don’t have initialization script for certain application we handle this situation in 2 different way:
Userspace system initialization
1. Make /etc/rc.d/rc.local script execute this program2. Write down your own start up script and add
information about new script to /etc/rc.d/rc.M
Userspace system initialization Script example for custom service using /etc/rc.d/rc.M start up mechanism#! /bin/bash start() {
echo “Program started” program_start
} stop() {
echo “Program stoped” killall program
} case $1 in
start) start ;; stop) stop ;; restart) stop sleep 2 start ;;*) echo “Usage: Program start|stop|restart”
esac
Userspace system initialization Add this script to /etc/rc.d/rc.M script by entering
if [ -x /etc/rc.d/rc.script ]; then . /etc/rc.d/rc.script start
fi