Booting

advertisement
Booting and Shuting Down
WeeSan Lee <weesan@cs.ucr.edu>
Roadmap





Bootstrapping
Boot Loaders
Startup/Init Scripts
Reboot & Shutdown
Q&A
Bootstrapping (simplified version)
BIOS
Boot Loader
Kernel Initialization
init
Runs scripts from
/etc/rc[0-6].d/
Spawns
getty processes
Spawns
Xdm/gdm processes
login
login
BIOS

Basic Input/Output System
Contains information about the machine’s
configuration. Eg. IDE controller, NIC

PC knows which device to boot from via BIOS

PC tries to run code from the MBR, ie. 1st 512 bytes,
of the disk
MBR tells the PC to load the boot loader from
certain disk partition
The boot loader loads the kernel



Boot Loaders - LILO




Traditional and stable
/etc/lilo.conf
 boot=/dev/hda
 root=/dev/hda1
 timeout=5
 image=/boot/vmlinuz-2.6.20

label=Linux

read-only
 other=/dev/hdb1

label=Windows

table=/dev/hdb
To install it
 $ lilo
lilo must be run after every reconfiguration
Boot Loaders – LILO (cont)

At LILO prompt




LILO: linux init=/sbin/init
LILO: linux init=/bin/bash
LILO: linux root=/dev/hda5
LILO: linux single
Boot Loaders – GRUB




GRand Unified Boot loader
Default on Red Hat and SuSe
Read configuration file at boot time
Understand filesystems and kernel executable formats
 ie. Only need to know the device, disk partition and
kernel filename


GRUB device (hd0,0) → /dev/hda1 or /dev/sda1
To install GRUB (for the very first time)
 $ grub-install ‘(hd0,0)’
 Edit /boot/grub/grub.conf
Boot Loaders – GRUB (cont)

/boot/grub/grub.conf
 default=0
 timeout=5
 splashimage=(hd0,0)/boot/grub/splash.xpm.gz
 title CentOS (2.6.18-8.el5)

root (hd0,0)

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/

initrd /boot/initrd-2.6.18-8.el5.img
 title Windows

rootnoverify (hd1,0)

chainloader +1
Boot Loaders – GRUB (cont)

At the splash screen


Hit ‘a’ and type “ single” to boot to single-user
mode
Hit ‘c’ to enter command-line mode



To boot other OSes that aren’t in grub.conf
Display system information
Press TAB to see possible commands
Kernel Initialization

A program itself


/vmlinuz or /boot/vmlinuz
Two-stage loading process

initrd (init RAM disk)




The real root filesystem
Device detection and configuration



A transient root filesystem in RAM before a real root filesystem
is available
Eg. It is used to install file system modules into the kernel
You tell the kernel what to expect
The kernel probes the H/W itself
Kernel threads creation

Eg. init (a user process), kjournald, kswapd
Single-user mode





A manual mode after kernel initialization and before
running startup scripts
“single” is passed to init, sulogin is run instead
Most system processes are not running
Users can’t log in, except root
/ is mounted read-only


Check/repair the disk if there are disk problems


$ mount -o rw,remount /
$ fsck -y /dev/sda1
Run ‘exit’ to exit single-user mode
Startup/Init Scripts


After Kernel initialization, a process called init
is created with PID 1
init runs startup scripts (normal shell scripts)
to perform specific tasks, eg.




Setting the hostname, time zone, etc
Checking and mouting the disks
Configuring network interfaces
Starting up daemons and network services
Startup/Init Scripts (cont)

Startup scripts (rc files) are run based on run levels










0
1
2
3
4
5
6
the level in which the system is completely shut down
single-user mode
multiuser mode w/out NFS
full multiuser mode
unused
X11
reboot level
Starts with run level 0 to the default run level (usually 3)
/etc/inittab tells init what to do at each level
To find out which run level the system is current in

$ runlevel
Startup/Init Scripts (cont)

init runs the scripts from /etc/rc.d/rc[0-6].d/



/etc/rc.d/rc0/K25sshd → /etc/init.d/sshd
/etc/rc.d/rc3/S55sshd → /etc/init.d/sshd
Each server/daemon provides a master script


Stored in /etc/init.d
Understands the arguments: start, stop, restart


run level 0 → 3


/etc/rc.d/rc3/S* start
run level 3 → 0


/etc/init.d/sshd start
/etc/rc.d/rc0/K* stop
Pretty ugly!
Startup/Init Scripts (cont)

Use chkconfig instead. Eg.



$ chkconfig --add sshd
$ chkconfig --del sshd
Before that, need to add/modify
/etc/init.d/sshd

# chkconfig: 2345 55 25

sshd should be started/stopped at run level 2, 3, 4 and 5
with the start priority of 55 and the stop priority of 25
Reboot & Shutdown

To reboot




$ shutdown -r now
$ reboot
$ telinit 6
To halt




$ shutdown -h now
$ halt
$ telinit 0
$ poweroff
Reboot & Shutdown (cont)

To shutdown gracefully

$ shutdown -h +15 “Shutdown in 15 mins”
References

LAH


Ch 2: Booting and Shutting Down
Grub manual

http://www.gnu.org/software/grub/manual/grub.html
Download