Booting And Shutting Down
Download
Report
Transcript Booting And Shutting Down
Booting And Shutting Down
Bootstrapping
Bootstrapping is standard term for
“starting up a computer”
During bootstrapping the kernel is
loaded into memory and begin its
execution
Overview of Linux Booting
Overview Linux booting
Turn on
CPU jump to address of BIOS
BIOS runs POST (Power-On Self Test) and it also
performs system integrity check
BIOS searches, loads, and executes boot loader
program
BIOS finds bootable devices
BIOS gives control to MBR reads from the memory
BIOS loads and execute boot sector form MBR
4
Booting Process
Recovery Boot to a shell
Basic minimal shell is loaded in case of system failed to
load.
This shell can be used as a recovery tool by system
admins.
Traditionally known as booting in ‘single user mode’
or ‘maintenance mode’
On most system ,you request a boot to ‘single user
mode’ by passing an argument to kernel at boot time.
If system is alredy up and running, you can bring it
down to single user mode with shutdown or telinit
command.
Steps in the boot process
1.
2.
3.
4.
5.
6.
Reading of the boot loader from the MBR
(Master Boot Record)
Loading and initialization of the kernel
Device detection and configuration
Creation of kernel processes
Administrator intervention (single-user-mode
only)
Execution of system startup scripts
7
MBR (Master Boot Record)
OS is booted from a hard disk, where the
Master Boot Record (MBR) contains the
primary boot loader
The MBR is a 512-byte sector, located in the
first sector of the bootable disk (sector 1 of
cylinder 0, head 0)
After the MBR is loaded into RAM, the
BIOS yields control to it.
8
MBR (Master Boot Record)
9
MBR (Master Boot Record)
The first 446 bytes are the primary boot loader,
which contains both executable code and error
message text
The next sixty-four bytes are the partition table,
which contains a record for each of four partitions
The MBR ends with two bytes that are defined as
the magic number (0xAA55). The magic number
serves as a validation check of the MBR
10
Extracting the MBR
To see the contents of MBR, use this
command:
# dd if=/dev/hda of=mbr.bin bs=512
count=1
# od -xa mbr.bin
**The dd command, which needs to be run from
root, reads the first 512 bytes from /dev/hda (the
first Integrated Drive Electronics, or IDE drive)
and writes them to the mbr.bin file.
**The od command prints the binary file in hex and
ASCII formats.
11
Boot loader
Boot loader could be more aptly called the
kernel loader. The task at this stage is to load
the Linux kernel
MBR contains information about boot loaders
MBR loads and executes GRUB (Linux boot
loader)
GRUB(Grand Unified Bootloader) contains
images of the kernel i.e. loads and execute
kernel, it also loads initial RAM disk (init rd)
12
2. Loading and initialization of the kernel
Kernel is itself a program, and the first
bootstrapping task is to get this program into
memory so that it can be executed
Linux system kernel - /boot/vmlinuz
Kernel mounts root filesystem i.e. loads
filesystems
Probes the system to determine how much
RAM is available
Kernel executes init program located in
/sbin/init
13
3. Device detection and configuration
Kernel loads device drivers
The kernel prints out a line of cryptic
information about each device it finds
14
4. Creation of kernel processes
Kernel creates several “spontaneous”
processes in user space
They are called spontaneous processes
because they are not created through the
normal system call fork
Processes sched have PID 0 and init have
PID 1
15
16
5. Administrator intervention (single user
mode – recovery mode)
During ‘single-user-boot’ user is prompted to enter the
root password.
A root shell is spawned by Init process which is aware
of the fact that system is booted in recovery mode.
(because of the extra argument passed by kernel)
Only root portion is mounted
Fsck cmd is run during a normal boot to check and
repair filesystems.
When the system in single user mode, need to run fsck
by hand
17
6. Execution of startup scripts
Startup scripts are just normal shell scripts,
and they are selected and run by init
Startup scripts serves in setting up the user
environment
Finally boot process completed
But Init is not done with its job…. Continues
18
to play an important role
Booting PCs
When a machine boots, it begins by executing boot
code stored in ROMs.
The exact location and nature of this boot code
varies, depending on the type of machine you have.
The boot code is typically firmware that knows
how to use the devices connected to the machine,
how to talk to the network on a basic level, and
how to understand disk-based filesystems.
On PCs, the initial boot code is generally called a
BIOS.
19
Built-in BIOS knows about some of the devices
that live on the motherboard, IDE and disks,
network interface, power and temperature meters
and system hardware.
BIOS select which devices you want the system to
try to boot from.
You can usually specify an ordered list of
preferences such as “try to boot from DVD, USB
drive, hard disk”.
20
Once the BIOS has figured out what device to boot
from, it tries to read the first block of the device.
This 512-byte segment is known as the master boot
record or MBR.
MBR contains a program that tells the computer
from which partition to load a secondary boot
program, the “boot loader”.
Default MBR contains a simple program that tells
the computer to get its boot loader from the first
partition on the disk.
21
MBR that knows how to deal with multiple
operating systems and kernels.
Once the MBR has chosen a partition to boot from,
it tries to load the boot loader specific to that
partition. This loader is then responsible for
loading the kernel.
22
GRUB : The Grand Unified Boot Loader
GRUB, developed by the GNU (Gnu’s Not Unix)
project.
It is the default boot loader for most UNIX and
Linux systems with Intel processors.
GRUB’s job is to choose a kernel from a
previously assembled list and to load that kernel
with options specified by the administrator.
23
There are two branches of the GRUB lineage:
original GRUB called GRUB Legacy, and the
newer GRUB 2.
Grub 2 is similar in concept but varies in its
config file syntax.
By default, GRUB reads its default boot
configuration from /boot/grub/menu.lst or
/boot/grub/grub.conf.
24
GRUB reads the configuration file at startup
time.
menu.lst and grub.conf files are slightly different
but have a similar syntax.
Red hat system use grub.conf and solaris, suse
and ubuntu still use menu.lst
25
GRUB 2 : New Layout
GRUB 2 places its files in three core
locations:
/boot/grub/grub.cfg :
Should not be edited by hand
/etc/grub.d/
Contains grub scripts , these scripts
generate grub.cfg
/etc/default/grub
This file contains the GRUB menu
settings that are read by the GRUB
scripts and written into grub.cfg
Red Hat system - grub.conf file
default=0
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
splash image
#
displays
title Red Hat Enterprise Linux Server (2.6.18-92.1.10.el5)
root (hd0,0) # root file system
kernel /vmlinuz-2.6.18-92.1.10.el5ro root=LABEL=/
#Grub loads this kernel
27
Ubuntu system - menu.lst file
28
GRUB is an operating system independant
boot loader
Flexible command line interface
File system access
29
Multibooting
default=0
timeout=5
splashimage=(hd0,2)/boot/grub/splash.xpm.gz
hiddenmenu
title Windows XP
rootnoverify (hd0,0)
chainloader +1
title Red Hat
root (hd0,1)
kernel /vmlinuz
30
Grub Command Line
Press ‘c’ from grub boot screen to enter in
command line mode
Press <TAB> to obtain quick list of possible
commands.
We can boot OS that is not in grub.cong
file
GRUB command-line options
Command
Meaning
reboot Reboots the system
find - Finds files on all mountable partitions
root - Specifies the root device (a partition)
kernel - Loads a kernel from the root device
help - Gets interactive help for a command
boot - Boots the system from the specified kernel image
32
Booting To Single-User Mode
Boot options should be easily modifiable and
decided on the ‘a’ key as the appropriate tool.
To boot into single-user mode, add the single flag
to the end of the existing kernel options.
ro root=LABEL=/rhgb quiet single
33
Init and start-up scripts
Bootloader loads the kernel, kernel
spawns the init process.
Init executes start up scripts
Start up scripts are kept in
/etc/init.d ( rc0.d , rc1.d and so on)
Tasks often performed by start-up scripts
Setting the name of computer
Setting the time zone
Checking the disk with fsck
Mounting the system disk
Removing old files from the temp
directory
Configuring network settings
Starting up daemon and netwwork
services
Init and its run level
Init controls the system run levels
and decides (based on /etc/inittab)
which set of processes to run at each
run level
Each run level is normally a single
digit (0 to 6) or S
When system is booted init first runs
at level 1 or S.
Run levels
At level 0, the system is completely
shut down.
Levels 1 and S represent single-user
mode.
Levels 2 through 5 include support
for networking.
Level 6 is a “reboot” level.
Rebooting and Shutting Down
Always a good idea to shut down the machine
when possible.
Improper shutdown can result problem in the
system.
To modify or make significant system changes,
you should reboot just to make sure that the
system comes up successfully.
38
Shutdown : the gentle way to halt the system
Shutdown sends messages to logged-in users at
progressively shorter intervals, warning them
of the impending downtime.
Warning simply say that the system is being
shut down and give the time remaining until
the event.
39
40
$ sudo shutdown
system halt after
$ sudo shutdown
system halt after
–h +15 "system is going down for
15 minutes! “
–r +1 “system is going down for
1 minutes!”
Halt cmd performs the essential duties required to
shut the system down.
Halt logs the shutdown, kills nonessential processes,
executes the sync system call, waits for filesystem
writes to complete, and then halts the kernel.
Reboot is almost identical to halt, but it reboots
instead of halting.
41