CT 320: Network and System 2 Booting Administration 1. Bootstrap - - PDF document

ct 320 network and system
SMART_READER_LITE
LIVE PREVIEW

CT 320: Network and System 2 Booting Administration 1. Bootstrap - - PDF document

9/10/12 Topics CT 320: Network and System 2 Booting Administration 1. Bootstrap loaders 2. Run levels 3. CHAPTER 3: BOOTING AND SHUTTING DOWN Startup scripts 4. Shutdown and reboot 5. COLORADO STATE UNIVERSITY COMPUTER SCIENCE DEPARTMENT


slide-1
SLIDE 1

9/10/12 1

CT 320: Network and System Administration

CHAPTER 3: BOOTING AND SHUTTING DOWN COLORADO STATE UNIVERSITY COMPUTER SCIENCE DEPARTMENT CHRIS WILCOX FALL 2012

Original slides from Dr. James Walden at Northern Kentucky University.

Topics

1.

Booting

2.

Bootstrap loaders

3.

Run levels

4.

Startup scripts

5.

Shutdown and reboot

9/11/12

CT 320, Fall Semester 2012

2

Booting

1.

ROM boot code (BIOS in PCs)‏

2.

Master Boot Record (MBR)‏

3.

Bootloader

4.

Kernel

5.

Hardware detection and configuration

6.

Creation of system processes

7.

Multiuser operation

9/11/12

CT 320, Fall Semester 2012

3

BIOS

  • 1. Load CMOS settings.
  • 2. Initialize registers and power management.
  • 3. POST (Power On Self Test.)‏
  • 4. Display system settings (if key pressed.)‏
  • 5. Activate other BIOSes

¡ Disk interfaces ¡ Graphics cards ¡ Network interfaces

  • 6. Find bootable device.
  • 7. Load MBR.
  • 8. Run MBR program.

9/11/12

CT 320, Fall Semester 2012

4

slide-2
SLIDE 2

9/10/12 2

MBR

— Up to four primary

partitions in MBR:

¡ Has CHS (Cyl/Head/Sector)

addresses or partition

¡ LBA (Logical Block Addressing)

for newer disk drives — One can be used as an

extended partition

¡ Links to an Extended Boot

Record (EBR) on first sector

¡ Each logical partition is

described by its own EBR

¡ Includes link to the next EBR,

to allow any # of partitions

9/11/12

CT 320, Fall Semester 2012

5

Bootloader: GRUB

Stage 1 (stored in MBR or boot sector)‏

¡

Initialize the system briefly.

¡

Detect the geometry and access mode of the loading drive.

¡

Load the first sector of Stage 2.

¡

Jump to the starting address of the Stage 2.

Stage 1.5 (stored in sectors of MBR track)‏

¡

One version for each filesystem.

¡

Loads stage 2 from filesystem.

Stage 2 (stored in filesystem)‏

¡

Displays menu of OS choices.

¡

Often displays boot splash screen.

¡

Loads selected OS kernel.

9/11/12

CT 320, Fall Semester 2012

6

GRUB Installation

At OS Install Time

Most distributions install GRUB.

Linux Install

grub-install /dev/hda

Native install

Boot with CD and run grub. #>> root (hd0,0)‏ #>> setup (hd0)‏ #>> quit

9/11/12

CT 320, Fall Semester 2012

7

GRUB Boot

— Automatically boots default OS after timeout. — Key sequences bring up

¡ Menu of boot options (described in menu.lst)‏ ¡ Edit kernel options (runlevel, other features)‏ ¡ GRUB command shell

— A boot prompt password may be required before

edit privileges or shell access granted.

¡ Can bypass OS security by specifying kernel options or

accessing files from GRUB shell.

9/11/12

CT 320, Fall Semester 2012

8

slide-3
SLIDE 3

9/10/12 3

Booting with GRUB

Direct Boot

Specify OS kernel image to load.

Chainloading

Specify another bootloader to load. Chainload NTLDR to boot MS Windows.

9/11/12

CT 320, Fall Semester 2012

9

Config: /boot/grub/menu.lst

# timeout (sec) before booting default timeout 10 # Ubuntu entry title Ubuntu, kernel 2.6.10-5-386 root (hd1,0)‏ kernel /boot/vmlinuz-2.6.10-5-386 root=/dev/hde1 ro quiet splash initrd /boot/initrd.img-2.6.10-5-386 boot # Windows entry title Windows 2000 root hd0,0)‏ makeactive chainloader +1

9/11/12

CT 320, Fall Semester 2012

10

GRUB Naming Convention

GRUB uses BIOS hard disk numbers

OS may not number disks identically to BIOS.

Examples

(hd0,0) First partition of first hard disk (hd1,2) Third partition of second hard disk.

9/11/12

CT 320, Fall Semester 2012

11

Kernel

1.

GRUB loads kernel file into memory

¡

/boot/vmlinuz-VERSION 2.

Kernel uncompresses self and begins running.

3.

Sets up interrupts and virtual memory.

4.

Loads initial RAMdisk into memory

¡

/boot/initrd.img-VERSION 5.

Kernel uncompresses initrd and mounts as /sysroot.

6.

Kernel loads drivers and modules from /sysroot.

¡

SCSI and RAID drivers, ext3 filesystem module, etc. 7.

Switches from real mode to protected mode.

8.

Creates kernel threads (ksoftirq, khelper, kblockd)‏

9.

Starts init or systemd process.

9/11/12

CT 320, Fall Semester 2012

12

slide-4
SLIDE 4

9/10/12 4

Kernel Arguments

Numeric arguments

¡ Specify runlevel. ¡ single also specifies single user mode

Root device options

– root= specifies which root device to use – ro, rw specify access type

Console options

– console=ttyS1,9600 will use serial console

Hardware options

¡ Enable, disable specific hardware devices/features.

9/11/12

CT 320, Fall Semester 2012

13

Run Levels

0 – Shutdown 1 – Single user 2 – Multi-user, no networking 3 – Multi-user, with networking 4 – Unused 5 – Multi-user, networking, and GUI 6 – Reboot

9/11/12

CT 320, Fall Semester 2012

14

/etc/inittab

# The default runlevel. id:2:initdefault: # Boot-time system config/initialization script. si::sysinit:/etc/init.d/rcS # What to do in single-user mode. ~~:S:wait:/sbin/sulogin # /etc/init.d executes the start and kill scripts l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 # What to do when CTRL-ALT-DEL is pressed. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

9/11/12

CT 320, Fall Semester 2012

15

rc

— Executed by init with runlevel as argument. — Starts and stops services for each runlevel. — /etc/rc#.d scripts

¡ Symlinks to actual scripts in /etc/init.d ¡ Kills services beginning with K* ¡ Starts services beginning with S* ¡ Executes in ASCII order. 9/11/12

CT 320, Fall Semester 2012

16

slide-5
SLIDE 5

9/10/12 5

Scripts in runlevel 2

$ ls /etc/rc2.d S05vbesave S13gdm S20openntpd S89cron S08iptables S18hplip S20postfix S91apache2 S10acpid S18portmap S20powernowd S98usplash S10powernowd.early S19cupsys S20rsync S99acpi-support S10sysklogd S20apmd S20ssh S99rc.local S10syslog-ng S20argus-server S20xinetd S99rmnologin S11klogd S20hotkey-setup S21nfs-common S99stop-readahead S12dbus S20makedev S89anacron

9/11/12

CT 320, Fall Semester 2012

17

Example init.d script

#! /bin/sh case "$1" in 'start') if [ -f /usr/local/sbin/sshd ]; then echo "starting SSHD daemon" /usr/local/sbin/sshd & fi ;; 'stop')‏ PID=`/usr/bin/ps -e -u 0 | /usr/bin/fgrep sshd | /usr/bin/awk '{print $1}'` if [ ! -z "$PID" ] ; then /usr/bin/kill ${PID} >/dev/null 2>&1 fi ;; *) echo "usage: /etc/init.d/sshd {start|stop}“ ;; esac

9/11/12

CT 320, Fall Semester 2012

18

Turning Services On/Off

Add a new service

Install startup script in /etc/init.d Create S symlinks in appropriate runlevels Create K symlinks in appropriate runlevels

Prevent a service from starting on boot

Remove S links from /etc/rc?.d/* Remove K links from /etc/rc?.d/*

9/11/12

CT 320, Fall Semester 2012

19

Red Hat Service Commands

Starting or stopping a service

service NAME [start,restart,stop]

is equivalent to

/etc/init.d/NAME [start,restart,stop]

Enabling or disabling a service at boot time

chkconfig NAME on –level <runlevels>

is equivalent to

ln –s /etc/init.d/NAME /etc/init.d/rc.d/ rc#.d/S??name

9/11/12

CT 320, Fall Semester 2012

20

slide-6
SLIDE 6

9/10/12 6

Single User Mode

— Kernel boots (arg 1 or “single”)‏ — System asks for root password — Root shell starts

¡ No system processes ¡ No networking

— Only root filesystem mounted (read-only).

¡ Remount for RW: mount –o remount,rw /

— Why?

¡ Fix without user interference ¡ For example: disks, backups, security 9/11/12

CT 320, Fall Semester 2012

21

What if single user mode doesn’t work?

— Bypass init by booting into shell

¡ Pass init=/bin/bash argument to kernel. ¡ Probably want to specify rw option as well. ¡ No need for root password. ¡ No housekeeping performed.

— Boot from CD

¡ RedHat CD with linux rescue

9/11/12

CT 320, Fall Semester 2012

22

Shutdown

— shutdown, init 0, halt

¡ Offers time-delay option ¡ Runs server/daemon stop scripts ¡ Kill remaining processes ¡ Flushes writes to disk (sync)

— reboot, init 6

¡ restarts system

— Ctrl-Alt-Del

¡ as defined in /etc/inittab ¡ ca:ctrlaltdel:/sbin/shutdown -t1 -a -r now 9/11/12

CT 320, Fall Semester 2012

23

What's wrong with init?

— Performance

¡ Starts services sequentially. ¡ Shell scripts spawn lots of processes.

— Manual configuration

¡ Order to start services determined manually. ¡ Network before authorization before NFS.

— Reliability

¡ Init does NOT monitor or restart services after boot.

— Hotplug hardware

¡ Drives mounted at boot. ¡ What about USB or network drives? 9/11/12

CT 320, Fall Semester 2012

24

slide-7
SLIDE 7

9/10/12 7

Init Alternatives

— systemd

¡ Full replacement for init, used by Fedora Core ¡ Parallel starting of services, reduce shell overhead

— launchd

¡ Mac replacement for init, rc, cron, inetd ¡ Monitors services, starts on demand

— initng

¡ Service configuration specifies dependencies ¡ Starts services in parallel, once dependencies met 9/11/12

CT 320, Fall Semester 2012

25

Systemd

— Systemd is the system and service manager for

Fedora releases

— More information can be found on the Fedora

website at http:/fedoraproject.org/wiki/Systemd

— Uses units to encapsulate services, sockets,

devices, mounts, automounts, and targets

— Has advanced capabilities that make it better than

previous initd mechanism:

¡ Aggressive parallelization when launching processes ¡ Bus activation starts services only when accessed ¡ Supports save and rollback of service states ¡ Automatically maintains mount and automount points 9/11/12

CT 320, Fall Semester 2012

26

Systemd (cont’d)

— systemadm is a graphical front-end for systemd that

allows inspection and control of services

— systemctl is a command front-end for systemd,

identical in functionality to systemadm

— Became default in Fedora 15, replacing Upstart, init

not used since at least Fedora 9

— Still supports the chkconfig command described

previously in these slides

— Files reside in /etc/systemd/system, for example

multi-user.target.wants for run level 5.

— Links set of service files, for example sshd.service:

¡ ExecStart=/usr/bin/sshd –D $OPTIONS ¡ ExecReload=/bin/kill –HUP $MAINPID ¡ WantedBy=multi-user.target 9/11/12

CT 320, Fall Semester 2012

27

Upstart

— Event-based init replacement. — Supports wider range of events than launchd.

¡ Hardware device has been added. ¡ Filesystem has been mounted. ¡ Time-based (can replace cron as well as init.) ¡ File has been modified. ¡ Another job has begun or finished running.

— Backwards compatible with /etc/init.d scripts. — Respawns services that are down. — Used in Ubuntu since version 6.10.

9/11/12

CT 320, Fall Semester 2012

28

slide-8
SLIDE 8

9/10/12 8

References

1.

  • M. Tim Jones, “Inside the Linux boot process,”

http://www.ibm.com/developerworks/library/l-linuxboot/ index.html, 2006.

2.

  • M. Tim Jones, “Parallelize applications for faster Linux

booting,” http://www.ibm.com/developerworks/linux/library/l-boot- faster/index.html, 2007.

3.

Scott James Remnant, “Upstart in Universe,” http://www.netsplit.com/2006/08/26/upstart-in-universe/, 2006.

4.

Starman, “Boot records revealed: MBR details,” http://mirror.href.com/thestarman/asm/mbr/index.html

5.

“Extended boot record,” http://en.wikipedia.org/wiki/Extended_Boot_Record.

6.

GRUB manual http://www.gnu.org/software/grub/manual/grub.html

7.

“How it works: Master Boot Record (MBR),” http://www.ata-atapi.com/hiwmbr.htm

9/11/12

CT 320, Fall Semester 2012

29