UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by...

37
UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University

Transcript of UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by...

Page 1: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

UNIX Startup and Shutdown

CSCI N321 – System and Network Administration

Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University

Page 2: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Section Overview

Bootstrapping

Startup Scripts and Run Levels

Boot Configuration and

Troubleshooting

System Shutdown

Page 3: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

References

CQU COIT13146 System Administration Course Chapter 13

Page 4: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Monolithic Kernels

HardwareHardware

Device Drivers, Dispatcher, …Device Drivers, Dispatcher, …

Scheduler, Virtual MemoryScheduler, Virtual Memory

IPC, File SystemIPC, File System

VFSVFS

ApplicationApplication

Source:http://en.wikipedia.org/wiki/Monolithic_kernel

KernelKernelModeMode

UserUserModeMode

Page 5: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Microkernels

HardwareHardware

Basic IPC, Virtual Memory, Scheduling Basic IPC, Virtual Memory, Scheduling

ApplicationApplicationIPCIPC

Source:http://en.wikipedia.org/wiki/Microkernel

KernelKernelModeMode

UserUserModeMode

UNIXUNIXServerServer

DeviceDeviceDriversDrivers

FileFileServerServer

ApplicationApplication

Page 6: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Bootstrapping

Starting the systemProcess of loading kernel into memoryBoot Modes Normal Single User/Safe Mode Rescue (on DVD)

Page 7: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

RedHat Boot Process

BIOSBIOS

LoginLoginShellShell

GRUBGRUB

/etc/inittab/etc/inittab

Source: http://nmc.nchu.edu.tw/linux/Linux_boot.htm

LinuxLinuxKernelKernel initinit

/etc/rc.d//etc/rc.d/rc.sysinitrc.sysinit

/etc/rc.d/rc/etc/rc.d/rc

RL SpecificRL Specific/etc/inittab/etc/inittab

/etc/rc.d//etc/rc.d/rc3.drc3.d

/etc/rc.d//etc/rc.d/rc5.drc5.d

Page 8: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Fedora Boot Process

BIOSBIOS

LoginLoginShellShell

GRUBGRUB

Source: http://nmc.nchu.edu.tw/linux/Linux_boot.htm

LinuxLinuxKernelKernel initinit

SystemdSystemd

/etc//etc/init/*.confinit/*.conf

RL SpecificRL Specific

/etc/rc.d//etc/rc.d/rc3.drc3.d

/etc/rc.d//etc/rc.d/rc5.drc5.d

systemdsystemd

Page 9: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Boot Process

Power On Self Tests (POST)Run Boot Loader(s)Load & initialize kernelDetect & configure devicesFork system processes(Stop if Single User mode)Run startup scriptsStart multiuser operations

Page 10: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Boot Loader

ROM loads Master Boot program from diskPrimary Bootloader

BIOS - Basic I/O, Program Loading UEFI – Unified Extensible Firmware Interface

2nd Boot Loader finds/loads kernel Checks available memory Initializes kernel internal data structures

NTLDR – Microsoft Boot LoaderGRand Unified Bootloader (GRUB/GRUB2)

Can boot multiple OS Boot options can be edited at boot

Page 11: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

GRUB Images (/boot/grub2)

boot.img – Loaded first on BIOS systemsdiskboot.img – first sector of core imagecdboot.img – DVD version of diskboot.imgcore.img Main image Includes kernel.img and module lists Built with grub-mkimage

kernel.img – Basic run-time functions*.mod – Dynamically loadable modules

Page 12: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Basic grub.cfg options

Shell script in /etc/boot2

set default=“0”

set timeout=“5”

menuentry ‘Fedora’ <options>

set root=‘(hd0,gpt2)’

linux /vmlinuz-<version> <options>

initrd /initranfs-<version>

Page 13: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Creating grub.cfg

Compiled using grub2-mkconfig/etc/default/grub Variables to change default settings

/etc/grub.d/* 00_header 10_linux 40_custom

Page 14: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

System Processes

BSD Systems swapper – PID 0 init – PID 1 pagedaemon – PID 2

AT&T SVR4 sched – PID 0 (invisible under RedHat) init – PID 1 /etc/inittab

Page 15: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Startup Services

HostnameTimezoneCheck the hard drivesMount the hard drivesRemove files from /tmpConfigure network interfacesStart daemons and network services

Page 16: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

BSD /etc/rc* Scripts

/etc/rc Master script Executes supplemental scripts

Example supplemental scripts (freeBSD) /etc/defaults/rc.conf /etc/rc.conf /etc/rc.conf.local

Page 17: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

/etc/inittab

Initializes system for useFormat: id:rl:action:process id: uniquely identifies entry rl: Run level entry applies to action: How to execute process process: process command line

Ex: Setting the default Runlevel:id:3:initdefault

Replaced in Fedora with systemd

Page 18: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd

Becoming more prevalent in Linux Distros Currently used by Fedora and OpenSUSE Testing in Debian

Mostly compatible with the init system init scripts are read as alternative format Established functionality such as fstab still

supported

Page 19: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd - Units

Uses a dependency system between “units”

Requires/Wants Conflicts Before After

Encapsulate objects relevant to booting and maintenanceConfigured in config filesMay be tied through symbolic links

Page 20: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd – Unit Types

Different unit types control different aspects of the operating system service: handles daemons socket: handles network sockets target: Logical grouping of units (example:

runlevel) device: expose kernel devices mount: controls mount points of the files system automount: mounts the file system snapshot: references other units (similar to

targets)

Page 21: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd Unit File Section

[Unit] Description Requires Wants Conflicts Before After

Page 22: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd Service Section

[Service] Type=

simple|oneshot|forking|dbus|notify|idle ExecStart ExecReload ExecStop Restart=

no|on-success|on-failure|on-abort|always

Page 23: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd Install Section

[Install] Wantedby=

Used to determine when to start (e.g. Runlevel)

Page 24: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Startup Run Levels

RedHatRedHat ModeMode

1 (S) Single user

2 Multiuser (no networking)

3 Full Multiuser

4 Unused

5 X11

6 Reboot

0 Halt

Page 25: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd – Runlevels

Runlevel is defined through a symbolic to one of the runlevel targetsRunlevel Target

Runlevel 3:/lib/systemd/system/multi-user.target

Runlevel 5:/lib/systemd/system/graphical.target

Change Runlevel: Remove current link

/etc/systemd/system/default.target Add a new link to the desired runlevel

Page 26: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd - Virtual Consoles

Started in /etc/systemd/system/getty.target \

.wants/getty@tty#.service

/sbin/agetty agetty <port> <baud rate> Alternative Linux getty Opens tty port and prompts for login

Page 27: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Systemd - Virtual Consoles

Example: [email protected][Unit]

Description=Getty on %I

BindTo=dev-%i.device

[Service]

Environment=TERM=linux

ExecStart=-/sbin/agetty %I 38400

Restart=always

RestartSec=0

UtmpIdentifier=%I

KillMode=process

Page 28: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

/etc/init/*.conf directives

execscriptstart on <event>stop on <event>taskrespawnSee man 5 init for more

Page 29: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

“Events”

control-alt-deletepower-status-changedstartuprunlevel <runlevel>started <job>stopped <job>

Page 30: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

/etc/init - Virtual Consoles

Started in /etc/init/start-ttys.conftty restarts in /etc/init/tty.confExample: /etc/init.d/tty.conf:

# tty - getty

#

# This service maintains a getty on the sepcified device.

stop on runlevel [016]

respawn

instance $TTY

exec /sbin/mingetty $TTY

Page 31: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Started in /etc/init/rc[S].conf:Example (rc.conf):start on runlevel [0123456]

stop on runlevel [!$RUNLEVEL]

task

export RUNLEVEL

console output

exec /etc/rc.d/rc $RUNLEVEL

/etc/init - Run Levels

Page 32: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Run Level Scripts

Actual scripts - /etc/rc.d/init.d//etc/rc.d/rc#.d/ Symbolic links to /etc/init.d scripts S## - Start scripts K## - Stop scripts /etc/sysconfig/ - script configuration files

chkconfig <script> on|off

service <script> start|stop|restart

Page 33: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Startup Messages

Displayed to consoleRedHat – daemon [ ok ]/bin/dmesg History of boot messages Convenient to search

RedHat allows for interactive setup (“i”)

Page 34: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Windows Boot Options

<F8> When system starts booting…

Page 35: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

Boot Display During Safe Mode

Page 36: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

System Shutdown

Turn off power – BAD!!!Reboot reboot shutdown –r

Halting the system halt shutdown –h

Changing the Run Level telinit <mode> shutdown –i<mode>

Page 37: UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.

When to Shutdown

Failures Maintenance and UpgradesRegularly Scheduled Housecleaning Window for Maintenance/Upgrades

User Notification /etc/motd Email Support web pages