Advanced Linux System Administra3on: Topic
Advanced Linux System Administra3on: Topic
LILO
LOGIN
STAGE
1
PROMPT
INIT
POST
SECTOR
LOADER
LOADING
PROCESS
LEVEL
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
INIT
POST
SECTOR
LOADER
LOADING
PROCESS
LEVEL
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
Bootloader
Code
Primary
par##on
Par,,on
Table
Boot Signature
Primary
par##on
Volume
Boot
Record
disk
Logical
Par##on
Extended
Par##on
…
Previous:
MBR
Disks
&
Par,,ons
• Master
Boot
Record
(MBR):
– First
block
of
the
Disk,
512
Bytes.
– Par,,on
Table:
informa#on
about
four
primary
par##ons:
begin
and
end
blocks,
size,
etc.
(64
bytes).
– Boot
Signature:
numerical
value
indica#ng
the
presence
of
valid
bootloader
code
in
the
code
field
(0x55AA)
(2
bytes).
• Volume
Boot
Record
(VBR):
– First
block
of
each
primary
par##on.
– Could
contain
bootloader
code
(indicated
by
Boot
Signature).
• Extended
Par,,on:
– Par##on
that
can
be
sub-‐divided
into
mul#ple
logical
par,,ons.
– Extended
Boot
Record
(EBR):
first
block
of
each
logical
par##on.
It
only
contains
a
par##on
table
with
two
fields.
Extended
par,,on
table
forms
a
linked
list
with
all
logical
par##ons.
Previous:
MBR
Disks
&
Par,,ons
• Linux
Naming
Conven,on:
– Remember:
I/O
devices
are
treated
as
files.
Under
directory
/dev
we
find
all
system
disks.
– Generic
PC:
2
IDE
controllers,
each
can
have
two
devices
(master/slave):
• /dev/hda:
first
device
(master)
of
the
first
IDE
controller.
• /dev/hdb:
second
device
(slave)
of
the
first
IDE
controller.
• /dev/hdc:
first
device
of
the
second
controller.
• /dev/hdd:
second
device
of
the
second
controller.
– In
a
disk,
each
primary
par,,on
is
iden#fied
with
a
number
from
1
to
4:
• /dev/hda1:
first
primary
par##on
of
the
hda
disk.
– Logical
par,,ons
start
from
5:
• /dev/hda5:
first
logical
par##on
of
hda
disk.
– In
SCSI
devices
same
naming
conven#on,
changing
“hd”
to
“sd”:
• /dev/sda1.
Stage
2:
Bootloader
• Hardware
requires
an
OS
in
charge
of
providing
all
the
func#onality
in
a
computer.
• Target:
to
load
the
OS
kernel
into
memory
and
start
running
it.
Loader
with
different
loca#ons:
USB,
CD,
Disk…
• Stage
2.1:
– Located
in
MBR:
512
first
bytes
(block
0)
of
the
ac,ve
device.
– Loaded
into
memory
by
BIOS
(Stage
1).
– Triggers,
when
executed,
the
load
and
execu#on
of
Stage
2.2.
• Stage
2.2:
– Located
in
the
ac,ve
par,,on,
where
the
kernel
is
placed.
– Loads
the
kernel
into
memory
and
transfers
control
to
it
(data
ini#aliza#on,
drivers,
check
CPU,
etc.).
– Acer
this
process,
the
init
process
is
executed
(Stage
3).
Stage
2:
LILO
• LInux
Loader:
– Two
stage
Bootloader.
– Does
not
“understand”
about
opera#ng
system
or
about
file
system.
Only
works
with
physical
loca#ons.
– Obsolete
(but
easy
to
follow
for
academic
purposes).
• Steps:
– Master
boot
loads
LILO
from
the
first
ac#ve
par##on
and
runs
it:
• LILO
can
be
in
the
MBR
or
in
the
Boot
Block
of
a
primary
par##on.
In
the
second
case,
MBR
contains
the
necessary
code
to
load
LILO
from
another
block.
– LILO
asks
the
user
what
kind
of
boot
he
wants
(par##on,
kernel,
mode).
Through
a
prompt.
– LILO
loads
the
kernel
and
a
ramdisk.
– The
kernel
starts
running
once
it
is
loaded
into
memory.
Stage
2:
LILO
• Configura#on:
/etc/lilo.conf:
Device
where
LILO
is
installed
(IDE/
SATA/Floppy…).
boot=/dev/hda #o by ID
map=/boot/map File
with
informa#on
about
disk
blocks
install=/boot/boot.b with
the
files
required
to
boot
system.
prompt
timeout=50
message=/boot/message
Loader
Assembly
code.
linear
default=linux Kernel
for
boo#ng
and
its
op#ons.
image=/boot/vmlinuz-2.6.2-2 Linux
system
par##on
(/).
Not
label=linux
read-only
necessarily
a
disk
(usb
loader).
root=/dev/hda2 #o by UUID
initrd=/boot/initrd-2.4.2-2.img Filesystem
loaded
into
memory
as
a
ramdisk.
Socware
support
not
provided
other=/dev/hda1 by
the
kernel
to
ini#alize
the
system.
label=dos
optional
Link
to
other
loader
(boot
a
different
OS).
Stage
2:
LILO
• Configura#on:
/etc/lilo.conf:
– Any
change
in
the
files
employed
in
boot
process
(boot.b,
kernel,
ramdisk)
requires
loader
update:
• Map
file
must
reflect
those
changes,
otherwise
boo#ng
process
is
corrupted.
• Check
if
map
file
is
updated:
#
lilo
-‐q.
• Update
map
file:
#
lilo
[-‐v].
INIT
POST
SECTOR
LOADER
LOADING
PROCESS
LEVEL
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
• To:
LOGIN
PROMPT
XDM
PROCESS
UEFI
• EFI/UEFI
(Unified
Extensible
Firmware
Interface):
– 2002:
itanium
plavorm
from
intel
provides
EFI
firmware.
– 2005:
UEFI.
Consor#um
of
companies
takes
control
over
the
firmware.
Unified
EFI
Forum.
– Works
in
32/64
bits
mode.
– Much
more
flexible
than
BIOS:
• Supports
big
disks
(MBR:
32-‐bit
block
addresses.
GPT:
64-‐bit
block
addresses):
– MBR:
512KB
block:
2TB
disk.
• Supports
more
boo#ng
devices
(network).
• Can
eliminate
the
need
for
a
bootloader
(no
stage
2).
• Improved
Security
(network
authen#ca#on,
signed
start
up).
• Extends
bootloader
opera#on
(load
the
OS)
to
a
UEFI-‐capable
shell
(interac#on).
– Requires
support
from
the
OS
(Linux,
OSX,
Windows8).
– Can
emulate
BIOS.
– VirtualBox
supports
UEFI.
Previous:
GPT
Disks
&
Par,,ons
Legacy
MBR
Par,,on
Table
Signature
Current
Block
Primary
GPT
Backup
Block
Entries
Start
block
GPT
Header
Entry1
Entry2
Entry3
Entry4
num/size
entries
Entry5
…
Par##on1
CRC32
disk
Par##on 2
Par,,on
Type
Entry128
Par,,on
GUID
First
Block
Last
Block
A`ributes
Par##on
N
Par,,on
name
Secondary
GPT
Previous:
GPT
Disks
&
Par,,ons
• Protec,ve/Legacy
MBR:
– Backward
compa#bility,
first
block
reserved.
– Prevent
MBR-‐based
disk
u#li#es
from
misrecognizing/overwri#ng
GPT
disks.
– Single
par##on
of
special
type
(iden#fies
a
GPT
disk).
OS
&
tools
which
cannot
read
GPT
recognize
the
disk
and
typically
refuse
to
modify
it.
• Primary
GPT
Header:
– Defines
the
usable
blocks
on
the
disk.
– Also
defines
the
par##on
table
(number
&
size
of
the
par##on
entries).
Minimum
table:
128
entries,
each
128
bytes
long.
– Also
contains
disk
UUID,
CRC32
checksum,
its
own
size
and
loca#on
(always
LBA
1)
and
the
size
and
loca#on
of
the
secondary
GPT
header
&
table
(always
last
disk
sectors).
Previous:
GPT
Disks
&
Par,,ons
• Par,,on
Entries:
– 128
bytes
for
each
entry
block.
– Each
par##on
includes
the
following
contents:
Type,
unique
ID,
First
and
last
blocks,
A]ributes
(e.g.
read
only)
&
par##on
name.
• Secondary
GPT
Header:
– Copy
of
the
Primary
GPT
header,
placed
in
last
disk
blocks.
– If
checksum
of
primary
header
fails,
secondary
is
employed.
UEFI
• Instead
of
a
512
MBR
and
some
boot
code,
UEFI
has
its
own
filesystem,
with
files
and
drives
(FAT32,
200-‐500Mb).
• UEFI
marks
one
GPT
par##on
with
the
boot
flag:
– But
this
is
an
EFI
par##on,
never
any
of
the
OS
par##ons.
• Each
installed
OS
has
its
own
directory
in
EFI
par##on:
– All
necessary
files
for
loading
the
OS
are
under
these
directories.
– In
Linux,
acer
computer
boot-‐up
the
EFI
par##on
is
some#mes
mounted
under
the
boot
par##on.
• Taking
a
look
at
the
UEFI
boot
process,
you
realize
it
reminds
you
of
a
mini-‐OS.
!"#
UEFI
!"#$"%#
• Boot
Manager:
– Firmware
policy
!"#$%&''()*%+,-%-.+-/*0(/%(1%2'&+1(34%1034)&3-%56%'(&70/8%!"#$%7309-3%&/7%!"#$%&22'0:&+0(/
engine
that
can
be
configured
by
modifying
architecturally
defined
global
N04&8-*;%<,-/%!"#$%7309-3*%&/7%!"#$%&22'0:&+0(/*%&3-%'(&7-7%+,-6%,&9-%&::-**%+(%&''%!"#$=7-
VRAM
variables.
3>/+04-%&/7%5((+%*-390:-*;%?--%#08>3-%@;%
– In
charge
of
loading
UEFI
drivers
and
UEFI
applica#ons
(including
UEFI
OS
boot
loaders).
EFI EFI EFI
OS Loader
Boot
order
defined
by
the
Driver Application Bootcode
Retry
global
NVRAM
variables.
Failure EFI API
EFI Boot
Platform EFI Image Services
Init Load OS Loader
Load Terminate
INIT
SECTOR
LOADER
LOADING
PROCESS
LEVEL
POST
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
INIT
POST
SECTOR
LOADER
LOADING
PROCESS
LEVEL
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
pablo@si:/etc/rc2.d$ ls
README S03cgroupfs-mount S03vboxdrv S05cups
S01bootlogs S03cron S04avahi-daemon S05cups-browsed
S01rsyslog S03dbus S04docker S05saned
S02apache2 S03exim4 S04lightdm S06plymouth
…
pablo@si:/etc/rc6.d$ ls
K01alsa-utils K01network-manager K02avahi-daemon K06rpcbind
K01apache2 K01plymouth K02vboxdrv K07hwclock.sh
…
Stage
4:
INIT
(SysV)
• Manual
administra#on
of
services:
– Acer
boo#ng
process,
services
can
be
modified
(stop
running
services
or
start
new
services).
– Directly
through
its
script
(example
ssh):
• #
/etc/init.d/ssh
[stop/start/restart/status].
– Or
through
the
command
service:
• Service
-‐-‐status-‐all:
reads
/etc/init.d/
verifying
service
state
[+]
[-‐]
[?].
– These
changes
are
vola#le
(lost
acer
reboot):
• Permanent
with
update.rc-‐d.
– Checking
possible
errors
concerning
boot
process:
• #
tail
-‐f
/var/log/messages
(Other
important
files:
syslog,
daemon.log).
• #
ls
-‐lart
/var/log.
Stage
4:
INIT
(SysV)
• Manual
administra#on
of
services:
– Examples
of
start
script
and
services
command:
#!/bin/sh
#SIMPLIFICADO
[ -f /usr/local/sbin/sshd2 ] || exit 0
PORT=
INIT
POST
SECTOR
LOADER
LOADING
PROCESS
LEVEL
• Introduc,on.
GRUB
GRUB
GRUB
XDM
STAGE
1
STAGE
1.5
STAGE
2
PROCESS
[Service]
Type=oneshot
RemainAcerExit=yes
ExecStart=/usr/local/sbin/simple-‐firewall-‐start
ExecStop=/usr/local/sbin/simple-‐firewall-‐stop
[Install]
WantedBy=mul#-‐user.target
Stage
4:
Systemd
• Systemd
boot
process:
– Configure
grub2
for
systemd:
• GRUB_CMDLINE_LINUX=“init=/lib/systemd/systemd”
(run
update-‐grub
acerwards).
– Systemd
handles
boot
&
service
management
using
Targets:
• Target:
special
unit
employed
to
group
boot
units
and
start
up
synchroniza#on
processes.
– First
target
executed:
default.target:
• Usually
a
symbolic
link
to
graphical.target.
– Target
Unit
File
main
op#ons:
• Requires:
hard
dependencies.
Must
start
before
your
own
service.
• Wants:
soc
dependencies
(not
required
to
start).
Can
be
replaced
by
a
directory,
named
foo.target.wants.
• Acer:
boots
acer
these
services.
[Unit]
– Runlevels:
Specific
Target
units.
Descrip#on=foo
boot
target
Requires=mul#-‐user.target
Wants=foobar.service
Acer=mul#-‐user.target
rescue.service
rescue.target
Stage
4:
Systemd
graphical.target
emergency.target
basic.target
sysinit.target