boot-1

advertisement
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
References
CQU COIT13146 System Administration Course
Chapter 13
Monolithic Kernels
Application
User
Mode
VFS
IPC, File System
Scheduler, Virtual Memory
Kernel
Mode
Device Drivers, Dispatcher, …
Hardware
Source:http://en.wikipedia.org/wiki/Monolithic_kernel
Microkernels
Application
Application
IPC
UNIX
Server
Device
Drivers
File
Server
Basic IPC, Virtual Memory, Scheduling
User
Mode
Kernel
Mode
Hardware
Source:http://en.wikipedia.org/wiki/Microkernel
Bootstrapping
Starting the system
Process of loading kernel into memory
Boot Modes



Normal
Single User/Safe Mode
Rescue (on DVD)
RedHat Boot Process
BIOS
GRUB
/etc/rc.d/
rc3.d
/etc/inittab
Linux
Kernel
init
/etc/rc.d/
rc.sysinit
/etc/rc.d/rc
Login
Shell
RL Specific
/etc/inittab
/etc/rc.d/
rc5.d
Source: http://nmc.nchu.edu.tw/linux/Linux_boot.htm
Fedora Boot Process
BIOS
GRUB
/etc/rc.d/
rc3.d
systemd
Linux
Kernel
Systemd
init
Login
Shell
/etc/
init/*.conf
RL Specific
/etc/rc.d/
rc5.d
Source: http://nmc.nchu.edu.tw/linux/Linux_boot.htm
Boot Process
Power On Self Tests (POST)
Run Boot Loader(s)
Load & initialize kernel
Detect & configure devices
Fork system processes
(Stop if Single User mode)
Run startup scripts
Start multiuser operations
Boot Loader
ROM loads Master Boot program from disk
Primary 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 Loader
GRand Unified Bootloader (GRUB/GRUB2)


Can boot multiple OS
Boot options can be edited at boot
GRUB Images (/boot/grub2)
boot.img – Loaded first on BIOS systems
diskboot.img – first sector of core image
cdboot.img – DVD version of diskboot.img
core.img



Main image
Includes kernel.img and module lists
Built with grub-mkimage
kernel.img – Basic run-time functions
*.mod – Dynamically loadable modules
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>
Creating grub.cfg
Compiled using grub2-mkconfig
/etc/default/grub

Variables to change default settings
/etc/grub.d/*



00_header
10_linux
40_custom
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
Startup Services
Hostname
Timezone
Check the hard drives
Mount the hard drives
Remove files from /tmp
Configure network interfaces
Start daemons and network services
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
/etc/inittab
Initializes system for use
Format: 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
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
Systemd - Units
Uses a dependency system between “units”




Requires/Wants
Conflicts
Before
After
Encapsulate objects relevant to booting and
maintenance
Configured in config files
May be tied through symbolic links
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)
Systemd Unit File Section
[Unit]






Description
Requires
Wants
Conflicts
Before
After
Systemd Service Section
[Service]

Type=
simple|oneshot|forking|dbus|notify|idle




ExecStart
ExecReload
ExecStop
Restart=
no|on-success|on-failure|on-abort|always
Systemd Install Section
[Install]
 Wantedby=
Used to determine when to start
(e.g. Runlevel)
Startup Run Levels
RedHat
1 (S)
2
3
4
5
6
0
Mode
Single user
Multiuser (no networking)
Full Multiuser
Unused
X11
Reboot
Halt
Systemd – Runlevels
Runlevel is defined through a symbolic to one of the
runlevel targets
Runlevel 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
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
Systemd - Virtual Consoles
Example: getty@tty1.service
[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
…
/etc/init/*.conf directives
exec
script
start on <event>
stop on <event>
task
respawn
See man 5 init for more
“Events”
control-alt-delete
power-status-changed
startup
runlevel <runlevel>
started <job>
stopped <job>
/etc/init - Virtual Consoles
Started in /etc/init/start-ttys.conf
tty restarts in /etc/init/tty.conf
Example: /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
/etc/init - Run Levels
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
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
Startup Messages
Displayed to console
RedHat – daemon [ ok ]
/bin/dmesg


History of boot messages
Convenient to search
RedHat allows for interactive setup (“i”)
Windows Boot Options
<F8> When system starts booting…
Boot Display During Safe Mode
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>
When to Shutdown
Failures
Maintenance and Upgrades
Regularly Scheduled


Housecleaning
Window for Maintenance/Upgrades
User Notification



/etc/motd
Email
Support web pages
Download