Lecture 5: Unix Startup Configuration: Asoc. Prof. Guntis Barzdins Asist. Girts Folkmanis
Lecture 5: Unix Startup Configuration: Asoc. Prof. Guntis Barzdins Asist. Girts Folkmanis
Lecture 5: Unix Startup Configuration: Asoc. Prof. Guntis Barzdins Asist. Girts Folkmanis
Configuration
Kernel options
Kernel re-compilation
Dynamically loadable modules
Kernel configuration files
Startup files
BSD model
System V model
Daemons
Network
Cron
Kernel boot tasks
Why Configure The Kernel?
foreground process
by default interactive processes run in the foreground and the
shell must wait until they complete
only one process can be running in the foreground for each
user.
But Remember that Unix is a multi-user system - foreground
and background relate to user sessions. Hence multiple
‘foreground’ processes can be running.
Job control for interactive processes
cont.
Background process
if a process has no output to terminal and will take some time
to run, rather than waiting, it can be run as a background
process
Once started in the background control returns immediately to
the shell.
a user can initiate multiple simultaneous background
processes
with the bash shell following a command with an & places in
the background
eg makewhatis &
Job control for interactive processes
cont.
Background Background
Child Child process process
group 32 group 40
pid=21 pid=22
pgid=20 pgid=20
Foreground
process group 20
Process Control Block
(PCB)
an Application
PCB
OS Kernel
Protected mode
Preemptive Scheduling
…
Preemptive vs. Nonpreemptive
Preemptive:
Nonpreemptive:
Grandchild Grandchild
pstree
System Processes
The kernel identifies the root, swap, and dump devices and then starts programs to
schedule processes, manage physical memory and virtual memory, and the init
process.
Sched
The real-time scheduler.
Swapper
It manages the physical memory by moving process from physical memory to swap
space when more physical memory is needed.
Page Daemon
Various memory handlers run as process 2.
Shell Programs
A shell is an application program that runs programs on
behalf of the user.
sh – Original Unix Bourne Shell
csh – BSD Unix C Shell, tcsh – Enhanced C Shell
bash –Bourne-Again Shell
int main()
{
char cmdline[MAXLINE];
while (1) {
/* read */
printf("> "); Execution is a
Fgets(cmdline, MAXLINE, stdin);
if (feof(stdin)) sequence of
exit(0);
read/evaluate steps
/* evaluate */
eval(cmdline);
}
}
Simple Shell eval Function
void eval(char *cmdline)
{
char *argv[MAXARGS]; /* argv for execve() */
int bg; /* should the job run in bg or fg? */
pid_t pid; /* process id */
bg = parseline(cmdline, argv);
if (!builtin_command(argv)) {
if ((pid = Fork()) == 0) { /* child runs user job */
if (execve(argv[0], argv, environ) < 0) {
printf("%s: Command not found.\n", argv[0]);
exit(0);
}
}
Character file
You must have permission to read and execute
the file
It contains commands just like from the keyboard
Like the .bat file from DOS
Booting and Kernel
Initialization
System Lifecycle: Ups &
Downs
Power Power
on off
Boot Kernel OS RUN! Shut
Init Init down
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
image=/boot/vmlinuz-2.2.12-20
label=linux
initrd=/boot/initrd-2.2.12-20.img
read-only
root=/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
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.
hardware Linux
runlevel
rc.sysinit rc.local Ready
0-6
Initialisation Scripts
Unix Today - You want choice :)
Level 0 – shutdown
Level 1 or S – single-user mode
Level 2 thru 5 – multi-user mode
Level 6 - reboot
Startup Script Directories
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 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
Some Linux inittab action valus
Action Meaning
Boot 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
check root file system quota & turns quotas for groups and
users
mount non-root file systems and checks them for repairs
(see /var/log/messages)
Linux Run Levels
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
Daemon xinetd
Configuration file /etc/xinetd.conf and /etc/xinetd.d
Attribute/value pair
Diable = yes/no
Setup automatic Mounting
/etc/fstab
/etc/vfstab
/
/dev/hda9
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
Net booting:
Remote root (Diskless-root-HOWTO).
Diskless boot (Diskless-HOWTO).
Adding Users