ct 320 network and system
play

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


  1. 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 CHRIS WILCOX FALL 2012 Original slides from Dr. James Walden at Northern Kentucky University. CT 320, Fall Semester 2012 9/11/12 Booting BIOS 3 4 1. Load CMOS settings. ROM boot code (BIOS in PCs) ‏ 1. 2. Initialize registers and power management. Master Boot Record (MBR) ‏ 2. 3. POST (Power On Self Test.) ‏ Bootloader 3. 4. Display system settings (if key pressed.) ‏ Kernel 4. 5. Activate other BIOSes Hardware detection and configuration 5. ¡ Disk interfaces Creation of system processes ¡ Graphics cards 6. ¡ Network interfaces Multiuser operation 7. 6. Find bootable device. 7. Load MBR. 8. Run MBR program. CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 1

  2. 9/10/12 MBR Bootloader: GRUB 5 6 — Up to four primary Stage 1 (stored in MBR or boot sector) ‏ partitions in MBR: Initialize the system briefly. ¡ ¡ Has CHS (Cyl/Head/Sector) Detect the geometry and access mode of the loading drive . ¡ addresses or partition Load the first sector of Stage 2. ¡ ¡ LBA (Logical Block Addressing) Jump to the starting address of the Stage 2. for newer disk drives ¡ Stage 1.5 (stored in sectors of MBR track) ‏ — One can be used as an extended partition One version for each filesystem. ¡ ¡ Links to an Extended Boot Loads stage 2 from filesystem. ¡ Record (EBR) on first sector Stage 2 (stored in filesystem) ‏ ¡ Each logical partition is Displays menu of OS choices. ¡ described by its own EBR Often displays boot splash screen. ¡ Includes link to the next EBR, ¡ to allow any # of partitions Loads selected OS kernel. ¡ CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 GRUB Installation GRUB Boot 7 8 At OS Install Time — Automatically boots default OS after timeout. Most distributions install GRUB. — Key sequences bring up Linux Install ¡ Menu of boot options (described in menu.lst) ‏ grub-install /dev/hda ¡ Edit kernel options (runlevel, other features) ‏ Native install ¡ GRUB command shell Boot with CD and run grub. — A boot prompt password may be required before #>> root (hd0,0) ‏ edit privileges or shell access granted. #>> setup (hd0) ‏ ¡ Can bypass OS security by specifying kernel options or #>> quit accessing files from GRUB shell. CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 2

  3. 9/10/12 Booting with GRUB Config: /boot/grub/menu.lst 9 10 # timeout (sec) before booting default Direct Boot timeout 10 Specify OS kernel image to load. Chainloading # Ubuntu entry title Ubuntu, kernel 2.6.10-5-386 Specify another bootloader to load. root (hd1,0) ‏ Chainload NTLDR to boot MS Windows. 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 CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 Kernel GRUB Naming Convention 11 12 GRUB uses BIOS hard disk numbers GRUB loads kernel file into memory 1. OS may not number disks identically to BIOS. /boot/vmlinuz-VERSION ¡ Kernel uncompresses self and begins running. 2. Examples Sets up interrupts and virtual memory. 3. (hd0,0) First partition of first hard disk Loads initial RAMdisk into memory 4. (hd1,2) Third partition of second hard disk. /boot/initrd.img-VERSION ¡ Kernel uncompresses initrd and mounts as /sysroot. 5. Kernel loads drivers and modules from /sysroot. 6. SCSI and RAID drivers, ext3 filesystem module, etc. ¡ Switches from real mode to protected mode. 7. Creates kernel threads (ksoftirq, khelper, kblockd) ‏ 8. Starts init or systemd process. 9. CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 3

  4. 9/10/12 Kernel Arguments Run Levels 13 14 Numeric arguments 0 – Shutdown ¡ Specify runlevel. 1 – Single user ¡ single also specifies single user mode 2 – Multi-user, no networking Root device options 3 – Multi-user, with networking – root= specifies which root device to use 4 – Unused – ro , rw specify access type 5 – Multi-user, networking, and GUI Console options 6 – Reboot – console=ttyS1 , 9600 will use serial console Hardware options ¡ Enable, disable specific hardware devices/features. CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 /etc/inittab rc 15 16 — Executed by init with runlevel as argument. # The default runlevel. id:2:initdefault: — Starts and stops services for each runlevel. # Boot-time system config/initialization script. — /etc/rc#.d scripts si::sysinit:/etc/init.d/rcS # What to do in single-user mode. ¡ Symlinks to actual scripts in /etc/init.d ~~:S:wait:/sbin/sulogin ¡ Kills services beginning with K* # /etc/init.d executes the start and kill scripts l0:0:wait:/etc/init.d/rc 0 ¡ Starts services beginning with S* l1:1:wait:/etc/init.d/rc 1 ¡ Executes in ASCII order. 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 CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 4

  5. 9/10/12 Scripts in runlevel 2 Example init.d script 17 18 #! /bin/sh $ ls /etc/rc2.d case "$1" in S05vbesave S13gdm S20openntpd S89cron 'start') S08iptables S18hplip S20postfix S91apache2 if [ -f /usr/local/sbin/sshd ]; then echo "starting SSHD daemon" S10acpid S18portmap S20powernowd S98usplash /usr/local/sbin/sshd & S10powernowd.early S19cupsys S20rsync S99acpi-support fi S10sysklogd S20apmd S20ssh S99rc.local ;; S10syslog-ng S20argus-server S20xinetd S99rmnologin 'stop') ‏ S11klogd S20hotkey-setup S21nfs-common S99stop-readahead PID=`/usr/bin/ps -e -u 0 | /usr/bin/fgrep sshd | S12dbus S20makedev S89anacron /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 CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 Turning Services On/Off Red Hat Service Commands 19 20 Add a new service Starting or stopping a service Install startup script in /etc/init.d service NAME [start,restart,stop] Create S symlinks in appropriate runlevels is equivalent to Create K symlinks in appropriate runlevels /etc/init.d/NAME [start,restart,stop] Enabling or disabling a service at boot time Prevent a service from starting on boot chkconfig NAME on –level <runlevels> Remove S links from /etc/rc?.d/* is equivalent to Remove K links from /etc/rc?.d/* ln –s /etc/init.d/NAME /etc/init.d/rc.d/ rc#.d/S??name CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 5

  6. 9/10/12 Single User Mode What if single user mode doesn’t work? 21 22 — Kernel boots (arg 1 or “single”) ‏ — Bypass init by booting into shell — System asks for root password ¡ Pass init=/bin/bash argument to kernel. — Root shell starts ¡ Probably want to specify rw option as well. ¡ No need for root password. ¡ No system processes ¡ No networking ¡ No housekeeping performed. — Only root filesystem mounted (read-only). — Boot from CD ¡ Remount for RW: mount –o remount,rw / ¡ RedHat CD with linux rescue — Why? ¡ Fix without user interference ¡ For example: disks, backups, security CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 Shutdown What's wrong with init? 23 24 — Performance — shutdown, init 0, halt ¡ Starts services sequentially. ¡ Offers time-delay option ¡ Shell scripts spawn lots of processes. ¡ Runs server/daemon stop scripts — Manual configuration ¡ Kill remaining processes ¡ Order to start services determined manually. ¡ Flushes writes to disk ( sync ) ¡ Network before authorization before NFS. — Reliability — reboot, init 6 ¡ Init does NOT monitor or restart services after boot. ¡ restarts system — Hotplug hardware — Ctrl-Alt-Del ¡ Drives mounted at boot. ¡ as defined in /etc/inittab ¡ What about USB or network drives? ¡ ca:ctrlaltdel:/sbin/shutdown -t1 -a -r now CT 320, Fall Semester 2012 9/11/12 CT 320, Fall Semester 2012 9/11/12 6

Recommend


More recommend