cit 470: advanced network and system administration

36
CIT 470: Advanced Network and System Administration Slide #1 CIT 470: Advanced Network and System Administration Booting and Runlevels

Upload: salvador-perkins

Post on 03-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

Booting and Runlevels. CIT 470: Advanced Network and System Administration. Topics. Booting Bootstrap loaders Run levels Startup scripts Shutdown and reboot. Booting. 1. ROM boot code (BIOS) Bootloader Kernel Init. 2. 3. 4. 1. BIOS. Load CMOS settings. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #1

CIT 470: Advanced Network and System Administration

Booting and Runlevels

Page 2: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #2

Topics

1. Booting

2. Bootstrap loaders

3. Run levels

4. Startup scripts

5. Shutdown and reboot

Page 3: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #3

Booting

ROM boot code (BIOS)BootloaderKernelInit4

321

Page 4: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #4

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 interfacesGraphics cardsNetwork interfaces

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

1

Page 5: CIT 470: Advanced Network and System Administration

Dell BIOS Screenshot

CIT 470: Advanced Network and System Administration

1

Page 6: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration

MBR contains Bootloader

Only 446 bytes!

MBR bootloader bootstraps itself by loading larger bootloader program from disk.

2

Page 7: CIT 470: Advanced Network and System Administration

Bootloader: GRUB

CIT 470: Advanced Network and System Administration

2

Page 8: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #8

GRUB Boot ProcessStage 1 (stored in MBR)

Detect the geometry and the accessing mode of the loading drive. Finds and runs stage 1.5.

Stage 1.5 (stored at beginning of partition)Understands filesystem; loads stage 2 from filesystem.

Stage 2 (stored in filesystem)Displays menu of OS choices.Often displays boot splashscreen.Loads selected OS kernel.

2

Page 9: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #9

GRUB Installation

At OS Install TimeMost distributions install GRUB.

Linux Installgrub-install /dev/hda

Native installBoot with CD and run grub.

#>> root (hd0,0)

#>> setup (hd0)

#>> quit

2

Page 10: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #10

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/shell access granted.– Can bypass OS security by specifying kernel

options or accessing files from GRUB shell.

2

Page 11: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #11

Booting with GRUB

Direct BootSpecify OS kernel image to load.

ChainloadingSpecify another bootloader to load.

Chainload NTLDR to boot MS Windows.

2

Page 12: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #12

Config: /boot/grub/menu.lst# timeout (sec) before booting defaulttimeout 10

title Ubuntu, kernel 2.6.10-5-386root (hd1,0)kernel /boot/vmlinuz-2.6.10-5-386

root=/dev/hde1 ro quiet splashinitrd /boot/initrd.img-2.6.10-5-386boot

title Windows 2000root (hd0,0)makeactivechainloader +1

2

Page 13: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #13

GRUB Naming Convention

GRUB uses BIOS hard disk numbersOS may not number disks identically to BIOS.

Examples(hd0,0) First partition of first hard disk

(hd1,2) Third partition of second hard disk.

2

Page 14: CIT 470: Advanced Network and System Administration

Kernel Booting

CIT 470: Advanced Network and System Administration

3

Page 15: CIT 470: Advanced Network and System Administration

Initial RAMDisk

Temporary filesystem used for booting.– Stored as /boot/initrd-VERSION– Loaded into memory by bootloader

Contains drivers needed to mount root fs– RAID, LVM, NFS or other device drivers– Filesystem drivers

Allows single kernel to be shipped by vendor– Drivers specific to your system on RAMdisk– Also supports hibernation for laptops

CIT 470: Advanced Network and System Administration

3

Page 16: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #16

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.

3

Page 17: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #17

Run Levels

0 – Shutdown

1 – Single user mode

2 – Multi-user, no networking, no GUI

3 – Multi-user, with networking, no GUI

4 – Unused

5 – Multi-user, networking, and GUI

6 – Reboot

4

Page 18: CIT 470: Advanced Network and System Administration

Single User Mode

Single user mode has– No GUI.

– No network access.

– Only one user (root) can use system.

Why use single user mode?– Run fsck to fix filesystem corruption.

– Backup files without filesystem active.

– Fix problems without user interference.

– May allow access to system without a password in case you have forgotten root’s password.

CIT 470: Advanced Network and System Administration

4

Page 19: CIT 470: Advanced Network and System Administration

Booting in Single User Mode

1. At GRUB prompt, select ‘a’ to append args

2. Append this argument to list:

single

3. Hit return to complete argument changes

4. Select ‘b’ to boot the kernel

Single-user mode differs from run level 1 in that run level 1 runs the scripts for run level 1, then enters single-user mode.

CIT 470: Advanced Network and System Administration

4

Page 20: CIT 470: Advanced Network and System Administration

What if you lost your root password?

CIT 470: Advanced Network and System Administration

1. At GRUB prompt, select ‘a’ to append arguments

2. Append this argument to list:

init=/bin/bash

3. Hit return to complete argument changes

4. Select ‘b’ to boot the kernel

5. At root prompt, remount /mount / -o rw,remount

6. Reset root passwordpasswd

7. Power cycle system

4

Page 21: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration

/etc/inittab# The default runlevel.

id:2:initdefault:

# Boot-time system configuration/initialization script.

si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.

~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change

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

4

Page 22: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration

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– Stops services beginning with K*– Starts services beginning with S*– Executes in ASCII order.

4

Page 23: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration

Scripts in runlevel 2$ ls /etc/rc2.dS05vbesave S13gdm S20openntpd S89cronS08iptables S18hplip S20postfix S91apache2S10acpid S18portmap S20powernowd S98usplashS10powernowd.early S19cupsys S20rsync S99acpi-supportS10sysklogd S20apmd S20ssh S99rc.localS10syslog-ng S20argus-server S20xinetd S99rmnologinS11klogd S20hotkey-setup S21nfs-common S99stop-readaheadS12dbus S20makedev S89anacron

4

Page 24: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #24

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

4

Page 25: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #25

Turning Services On/Off

Add a new serviceInstall startup script in /etc/init.d

Create S symlinks in appropriate runlevels

Create K symlinks in appropriate runlevels

Prevent a service from starting on bootRemove S links from /etc/rc?.d/*

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

4

Page 26: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #26

Red Hat Service Commands

Starting or stopping a serviceservice NAME [start,restart,stop]

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

Enabling or disabling a service at boot timechkconfig --level # NAME

is equivalent toln –s /etc/init.d/NAME /etc/init.d/rc.d/rc#.d/S??name

4

Page 27: CIT 470: Advanced Network and System Administration

Red Hat Service Configuration

RH Linuxes use files in /etc/sysconfigVARIABLE=value format

Documentation in RHEL manuals

Examplesdesktop: select GNOME, KDE, XFCE desktop

iptables: firewall configuration

network-scripts/ifcfg-eth0: eth0 cfg

4

Page 28: CIT 470: Advanced Network and System Administration

/etc/sysconfig

CIT 470: Advanced Network and System Administration

4

Page 29: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #29

Shutdown

shutdown –h now (or init 0)Offers time-delay option (-h time)

Runs server stop scripts.

Kill remaining processes.

Flushes writes to disk.

haltKills processes.

Flushes writes to disk (sync).

4

Page 30: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #30

Reboot

reboot (or init 6)restarts system

Ctrl-Alt-DelDefined in /etc/inittabca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

4

Page 31: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #31

What's wrong with init?Performance

– Starts services sequentially.– Shell scripts spawn lots of processes.

Manual configuration– Order to start services determined manually.– i.e. network before authentication before nfs.

Reliability– Init doesn’t monitor or restart services after boot.

Hotplug hardware– Drives mounted at boot.– What about USB or network drives?

4

Page 32: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #32

Init Alternatives

iniNG– Service config specifies dependencies.– need = system/initial net/all; – Starts services in parallel once dependencies met.

launchd– Mac replacement for init, rc, cron, atd, inetd– Monitors services, starts on demand.

Service Management Facility– Sun replacement for init with service monitoring.

4

Page 33: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration

Upstart

• Event-based init replacement.• Events

– Hardware device has been added.– Filesystem has been mounted.– Time (cron-replacement)– File has been modified.– Another job has begun or finished

running.

• Backwards compatible with /etc/init.d scripts.

• Respawns services that are down.

4

Page 34: CIT 470: Advanced Network and System Administration

Boot Process Summary

CIT 470: Advanced Network and System Administration

Page 35: CIT 470: Advanced Network and System Administration

Key PointsBoot Steps

1. BIOS

2. Bootloader (GRUB)

3. Kernel

4. init

init is PID 1, parent of all processes, started by kernel

– Uses rc command to run all scripts in /etc.rcN.d dir where N is runlevel

– RHEL: use chkconfig to configure, /etc/sysconfig for options

Run levels

1 and Single user mode (use to fix problems)

3 = multiuser + network (servers)

5 = multiuser + network + GUI (workstations)

CIT 470: Advanced Network and System Administration

Page 36: CIT 470: Advanced Network and System Administration

CIT 470: Advanced Network and System Administration Slide #36

References1. Aeleen Frisch, Essential System Administration, 3rd edition, O’Reilly, 2002.2. M. Tim Jones, “Inside the Linux boot process,”

http://www.ibm.com/developerworks/library/l-linuxboot/index.html, 2006.3. M. Tim Jones, “Parallelize applications for faster Linux booting,”

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

4. Evi Nemeth et al, UNIX System Administration Handbook, 3rd edition, Prentice Hall, 2001.

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

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

7. “Extended boot record,” http://en.wikipedia.org/wiki/Extended_Boot_Record.8. GRUB manual, http://www.gnu.org/software/grub/manual/grub.html9. “How it works: Master Boot Record (MBR),”

http://www.ata-atapi.com/hiwmbr.htm10. “Replacement Init”, https://wiki.ubuntu.com/ReplacementInit