0% found this document useful (0 votes)
48 views32 pages

CHAPTER 4 Booting A Unix System

Uploaded by

NG Yves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views32 pages

CHAPTER 4 Booting A Unix System

Uploaded by

NG Yves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

CHAPTER 4: BOOTING A

LINUX SYSTEM
Outline
• System startup and shutdown
• Bootstrapping
• Booting PCs
• Boot loaders
• Booting into single user mode
• Startup scripts and run levels
• Rebooting and shutting down
4.1 Bootstrapping: starting the computer

• System is particularly vulnerable to errors


• Steps in boot process
• Execution of boot code in ROM (POST)
• Loading and initialization of kernel
• Device detection and configuration
• Creation of spontaneous system processes
• Operator intervention (manual boot only)
• Execution of system startup scripts
• Multiuser operation
4.1 Booting PCs
• PC starts by executing code (POST) in ROM (BIOS or UEFI)
• Usually BIOS has a configuration mode with special keypress during boot
• Tries to load first 512B of the boot disk – the Master Boot Record.
• This sector contains a boot loader for the installed operating system and information about the drive’s
logical partitions.
• GPT stores multiple copies of this data across the disk, so it’s much more robust and can recover if the
data is corrupted.
• MBR contains program to specify which partition from which to load the secondary boot program (the
“boot loader”)
4.1 Booting PCs (Summary)
1. When a PC is turned on, the Basic Input Output Service (BIOS) performs a self test.
2. When the machine passes its self test, the BIOS loads the MBR, usually from the first 512-byte sector of the
boot drive. The boot drive is most often the first hard drive on the system, but might also be a diskette, CD, or
USB key.
3. For a hard drive, the MBR loads a stage 1 boot loader, which is typically either the LILO or GRUB stage1 boot
loader on a Linux system. This is another 512-byte, single-sector record.
4. The stage 1 boot loader usually loads a sequence of records called the stage 2 boot loader (or sometimes the
stage 1.5 loader).
5. The stage 2 loader loads the operating system. For Linux, this is the kernel and possibly an initial RAM disk
(initrd or initramfs).
4.1 Booting PCs
LINUX AND THE KERNEL
4.1 Booting PCs
LINUX AND THE KERNEL
• After the BIOS/UEFI instructions are given to start the OS,
• A compressed version of the kernel is loaded into the first megabyte of ram.
• The complete kernel is expanded and loaded
• The kernel starts
• Some drivers are compiled into the kernel other drivers are
loaded when the kernel starts.
• Everything recognized by the os has a file node associated
with it. The kernel will establish nodes for each required
device.
4.1 Summary of booting process
BIOS Executes POST, loads MBR, searches for stage 1 bootloader in
floppy, usb, cd-rom or hard drive
MBR Loads and executes second stage bootloader ( GRUB or
GRUB2)
Boot loader Gives a choice of OS to load. Loads kernel and initrd images
GRUB
Kernel Mounts root file system, Executes init

init Looks at /etc/inittab file to decide on Linux run level to run.

Runlevel Executes the services associated with the run level


4.2 Boot loaders
• Load and start the kernel
• Could be one of many
• kernels or OSes!
• MBR set to load the master boot loader
• Each disk partition can have its own second stage loader
• LILO is an older Linux boot loader
• GRUB is the modern Linux boot loader
• Supports most OSes, not just Linux
• GRUB2 is the Loader used today
4.2 Boot loaders
• Other bootloaders in other systems:
• WINDOWS
• BOOTMGR for Windows 7,8 & 10
• NTLDR for Windows 9x, 2000 and 2003 server
•GRUB2WIN: a GNU loader that can manage
4.2 GRUB2
• When GRUB2 loads, it presents information from a
configuration file, normally located in
/boot/grub/grub.cfg or /boot/grub2/grub.cfg.
• Read the Grub2 configuration of your system
4.3 Kernel parameters
• Find and set up swap (virtual memory)
• A hardware probe is done to determine what drivers should be
initialized.
• Read /etc/fstab to mount the root file system.
• Mount other devices
• Start a program called init.
• Kernel passes control to init.
• Kernel keeps output messages in kernel ring buffer. This can be read
using the command dmesg
4.3 init
• The first non-dummy process, PID = 1.
• First process to run and is always running.
• The kernel passes process management to init.
• Init reads its configuration file: /etc/inittab
• Directly or indirectly spawns all other processes until
shutdown.
4.3 init : Processes
• The basis of all Linux systems.
•Run perpetually in the background waiting for
input.
• Services
• Daemons
• Shells
• utilities
4.3 init : Services and daemons
Examples
•login prompt
• X-Window server
•keyboard input functionality
•firewall
•and all classic server programs; e-mail, DNS, FTP,
telnet, ssh, etc.
4.3 init : run levels
the runlevel is determined by inittab:
0. Halt the system
1. Or S Enter single-user mode (no networking)
2. Multiuser mode, without NFS.
3. Full multiuser mode
4. Unused
5. Same as runlevel 3 but with X-windows.
6. Reboot.
• /etc/inittab specifies what init has to do in each level
• During booting, system goes from 0 to default run level (in /etc/inittab), and calls /etc/rc.d/rc for each change
4.4 Startup Scripts
• At the end of single user mode, init executes system startup
scripts
Typical tasks:
• Setting name of computer
• Setting the time zone
• Checking the disks with fsck
• Mounting the system disks
• Removing old files from /tmp
• Configuring network interfaces
• Starting daemons and network services
4.4 Startup Scripts
• At the end of single user mode, init executes system startup
scripts
Typical tasks:
• Setting name of computer
• Setting the time zone
• Checking the disks with fsck
• Mounting the system disks
• Removing old files from /tmp
• Configuring network interfaces
• Starting daemons and network services
4.4 Startup Scripts
• Startup scripts live in /etc/init.d/ (linked to /etc/rc.d/init.d/)
• Each script starts, stops, restarts some service
• /etc/rc.d/rc knows to look in /etc/rc.d/ where there is a subdirectory for
each runlevel
• Symbolic links are made to the actual script in
• /etc/init.d/ within each subdirectory for the services appropriate for that level,
e.g.
• ln -s /etc/init.d/sshd /etc/rc3.d/S99sshd
• Script names indicate order of Start or Kill
4.4 Startup scripts
Inittab and sysinit
•The file rc.sysinit is a script run once at boot time
to set up services specific to the computer
system:
• Hostname
• Networking
• Etc.
4.4 Startup scripts
/etc/rc[0-6].d
• There is an additional directory for each different
runlevel: 0-6.
• Each directory has the scripts needed to run the
specified boot level.
• The files in these subdirectories have two
classifications: kill and start.
4.4 inetd & xinetd
• Daemons – independent background processes that poll for events.
• Events sent to the daemons determine how the daemon behaves at any given time.
• Inetd is a Pre-Linux tool.
• The supervisor of network server-related processes.
• Rather than running many daemons taking up memory, inetd polls for daemon requests. When a
particular daemon gets an event, inetd will activate the appropriate daemon.
4.4 inetd & xinetd
Xinetd
•Linux implementation of inetd.
•A list of the services currently offered by
xinetd are in /etc/xinetd.d directory
4.4 syslogd daemon
• With programs/services disconnected from a
terminal, where does their standard output go?
• Syslogd routes the output of services to text files.
• Most log files are in /var/log
• Works in a heterogeneous environment.
4.4 syslogd
•/sbin/syslogd
•/etc/syslogd.conf
•man syslogd
4.4 /etc/syslog.conf
• Syntax of file involves
• Facility: mail, kern, daemon, lpr, other services
• Priority: emerg, alert, warning, err, notice, etc.
• Log file
Example
*.emerg @loghost,frungang,root
Emergency messages are sent to machine loghost and to the console session
of frungang and root.
4.4 syslogd
•/sbin/syslogd
•/etc/syslogd.conf
•man syslogd
4.5 Rebooting and Shutting down
• Not needed as often as in consumer OSes
• ● Needed for
• Adding or removing hardware
• Change to boot configuration
• Including new kernel
• System really wedged
• Ways to reboot or shutdown
• Use the shutdown command
• Use the halt and reboot commands
• Use telinit to change init's run level
• Use poweroff to tell system to turn off
• Use hardware reset switch or turn off power (last resort!)
4.5 shutdown
• shutdown command is safest, considerate, and most thorough to halt,
reboot, or change to single user mode
• shutdown can wait before bringing down system
• sends warning messages (like wall) to logged-in users
– should explain why, and when it is coming back
• Can specify whether to halt, or reboot:
– shutdown -r +15 “Rebooting to fix NFS”
4.5 Halt; reboot
• halt
• called by shutdown -h
• logs the shutdown
• kills non-essential processes
• executes sync
- waits for filesystem to finish writes
- puts IDE drives in standby mode (flushing write caches)
• halts the kernel
• reboot
• called by shutdown -r
• similar to halt, but tells kernel to reboot system
4.5 telinit; poweroff
•telinit
• Directs init to go to a specific run level
• telinit 1 – takes system to single-user mode
•poweroff
• Identical to halt, but adds request to power
management system to turn off system's power
THANK YOU

You might also like