chapter-3

31
CT 320: Network and System Administra8on Fall 2014 * Dr. Indrajit Ray Email: [email protected] Department of Computer Science Colorado State University Fort Collins, CO 80528, USA Dr. Indrajit Ray, Computer Science Department CT 320 – Network and Systems Administra8on, Fall 2014 * Thanks to Dr. James Walden, NKU and Russ Wakefield, CSU for contents of these slides

description

chapter-3

Transcript of chapter-3

  • CT 320: Network and System Administra8on Fall 2014*

    Dr. Indrajit Ray Email: [email protected]

    Department of Computer Science

    Colorado State University Fort Collins, CO 80528, USA

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

    * Thanks to Dr. James Walden, NKU and Russ Wakeeld, CSU for contents of these slides

  • Boo#ng and Shutdown

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Topics

    Boo8ng process Bootstrap loaders Run levels Startup scripts Shutdown and reboot

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Subsystems Involved in Boo#ng

    ROM boot code (BIOS in PCs) Master Boot Record (MBR) Bootloader Kernel Hardware detec8on and congura8on Crea8on of system processes Mul8user opera8on

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Boot Sequence

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • BIOS Ini#aliza#on

    Load CMOS se^ngs. Ini8alize registers and power management. Power On Self Test (POST) Display system se^ngs (if key pressed.) Ac8vate other BIOSes Disk interfaces Graphics cards Network interfaces

    Find bootable device. Load and run MBR.

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Master Boot Record Structure

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

    CHS = Cylinder/ Head/Sector addresses

    LBA = Logical Block Address for newer disk drives

    Sector 0 MBR

    Sector 1

    Sector 2

    Sector 3

    ....

    Sector N-2

    Sector N-1

    N-sectorhard disk

    (512 bytessector size)

    Master Boot Record Code(440 bytes)

    Disk Signature(4 bytes)

    Null(2 bytes)

    Partition Table 1(16 bytes)

    Partition Table 2(16 bytes)

    Partition Table 3(16 bytes)

    Partition Table 4(16 bytes)

    MBR Signature(2 bytes)

    Bootloader

    Partition Flag

    Start CHS

    Partition Byte

    End CHS

    Start LBA

    Size

  • Master Boot Record

    4 primary par88ons One par88on can be used as an extended par88on Linked to an Extended Boot Record (EBR) on the rst sector of that par88on

    Each logical par88on is described by its own EBR which links to the next EBR (to allow any number of par88ons)

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Bootloader: GRUB

    Stage 1 (stored in MBR or boot sector) Ini8alize the system briey. Detect the geometry and the accessing mode of the loading

    drive. Load the rst sector of Stage 2. Jump to the star8ng address of the Stage 2.

    Stage 1.5 (stored in sectors of MBR track) One version for each lesystem. Loads stage 2 from lesystem.

    Stage 2 (stored in lesystem) Displays menu of OS choices. Ofen displays boot splash screen. Loads selected OS kernel.

    CT 320: Network and System Administra8on

  • GRUB Installa#on

    At OS Install Time Most distribu8ons install GRUB.

    Linux Install grub-install /dev/hda

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

    CT 320: Network and System Administra8on

  • GRUB Boot

    Automa8cally boots default OS afer 8meout. Key sequences bring up Menu of boot op8ons (described in menu.lst) Edit kernel op8ons (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 op8ons or accessing les from GRUB shell.

    CT 320: Network and System Administra8on

  • Boo#ng with GRUB

    Direct Boot Specify OS kernel image to load.

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

    CT 320: Network and System Administra8on

  • Cong: /boot/grub/menu.lst

    CT 320: Network and System Administra8on

    # timeout (sec) before booting default timeout 10 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

  • GRUB Naming Conven#on

    GRUB uses BIOS hard disk numbers OS may not number disks iden8cally to BIOS.

    Examples (hd0,0) First par88on of rst hard disk (hd1,2) Third par88on of second hard disk.

    CT 320: Network and System Administra8on

  • Kernel 1. GRUB loads kernel le into memory

    /boot/vmlinuz-VERSION 2. Kernel uncompresses self and begins running. 3. Sets up interrupts and virtual memory. 4. Loads ini8al 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 lesystem module, etc. 7. Switches from real mode to protected mode. 8. Creates kernel threads (ksofirq, khelper, kblockd) 9. Starts init or systemd process.

    CT 320: Network and System Administra8on

  • Kernel Arguments

    Numeric arguments Specify runlevel. single also species single user mode

    Root device op8ons root= species which root device to use ro, rw specify access type

    Console op8ons console=ttyS1,9600 will use serial console

    Hardware op8ons Enable, disable specic hardware devices/features.

    CT 320: Network and System Administra8on

  • Run Levels

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

    CT 320: Network and System Administra8on

  • /etc/inittab

    CT 320: Network and System Administra8on

    # 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

  • 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.

    CT 320: Network and System Administra8on

  • Scripts in runlevel 2

    CT 320: Network and System Administra8on

    $ ls /etc/rc2.d S05vbesave S13gdm S20openntpd S89cron S08iptables S18hplip S20posoix 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

  • Example init.d script

    CT 320: Network and System Administra8on

    #! /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

  • Turning Services On/O

    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 star8ng on boot Remove S links from /etc/rc?.d/* Remove K links from /etc/rc?.d/*

    CT 320: Network and System Administra8on

  • Single User Mode

    Kernel boots (with arg 1 or single) System asks for root password Root shell starts No system processes No networking

    Only root lesystem mounted (read-only). Remount for RW: mount o remount,rw /

    Why? Fix without user interference: For example: disks, backups, security.

    CT 320: Network and System Administra8on

  • What if single user mode doesnt work?

    Bypass init by boo8ng into shell Pass init=/bin/bash argument to kernel. Probably want to specify rw op8on as well. No need for root password. No housekeeping performed.

    Boot from CD RedHat CD with linux rescue Knoppix CD

    CT 320: Network and System Administra8on

  • Shutdown

    shutdown (or init 0) Oers 8me-delay op8on. Runs server stop scripts. Kill remaining processes. Flushes writes to disk.

    halt Kills processes. Flushes writes to disk (sync).

    CT 320: Network and System Administra8on

  • Reboot

    init 6 shutdown restarts system

    Ctrl-Alt-Del Dened in /etc/inittab ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

    reboot halt restarts system

    CT 320: Network and System Administra8on

  • What's wrong with init? Performance

    Starts services sequen8ally. Shell scripts spawn lots of processes.

    Manual congura8on Order to start services determined manually. i.e. network before auth before nfs.

    Reliability Init doesnt monitor or restart services afer boot.

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

    CT 320: Network and System Administra8on

  • Init Alterna#ves

    initng Service congur8on species dependencies. need = system/ini8al net/all; Starts services in parallel once dependencies met.

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

    systemd Full replacement for init, used by Fedora Core Parallel star8ng of services, reduce shell overhead

    CT 320: Network and System Administra8on

  • Systemd

    Systemd is the system and service manager for Fedora releases

    More informa8on can be found on the Fedora website at hvp://fedoraproject.org/wiki/Systemd

    Uses units to encapsulate services, sockets, devices, mounts, automounts, and targets

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • Systemd

    Has advanced capabili8es that make it bever than previous initd mechanism Aggressive paralleliza8on when launching processes Bus ac8va8on starts services only when accessed Supports save and rollback of service states Automa8cally maintains mount and automount points

    Dr. Indrajit Ray, Computer Science Department CT 320 Network and Systems Administra8on, Fall 2014

  • 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 modied. Another job has begun or nished running.

    Backwards compa8ble with /etc/init.d scripts.

    Respawns services that are down. Used in Ubuntu since version 6.10.

    CT 320: Network and System Administra8on