Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

LPI – 101

System Architecture
Why Linux?
Open Source
 Many people have been able to adapt Linux in

different ways
 This caused wide range of new features and

versions customized to meet new specific needs


Why Linux?
Multiuser and Multitasking
 Linux is designed to be multi-user operating

system.
 Each user can run multiple tasks at the same time,

without affecting each other.


Why Linux?
Tools
 Large number of tools available for a variety of

jobs

Why Linux?
Portability
 Linux Operating system is programmed to be

portable across different hardware.



Why Linux?
Other reasons ...
 Reliability, security and speed
 Critical businesses, database servers, data centers,

all run on Linux.


 Amazon, Google, Wikipedia are few
 Mature Operating System, long time
 Best choices for Developing Countries as there are

no or low cost associated


 It is used as a model for teaching Operating

systems “having the source code makes learning a


great experience”

101: system Architecuture
Key Knowledge Areas
 Enable and disable integrated devices
 Set the correct hardware ID for different devices,

the boot device


 Difference between coldplug, and hotplug
 Tools and utilities to list various hardware

information
 Tools and utilities to manipulate USB devices
 Conceptual understanding of sysfs, udev, hald, dbus
8
101: system Architecuture
1. Determine and configure Hardware settings
Interrupt Requests
 IO addresses are regions of memory mapped to devices where the

CPU can write information of devices


 The limited IRQ lines become a problem as some devices were

hardwired to use specific IRQ.


 Plug and play have solved this limitation by sharing interrupt

lines to devices.
 Now with Intel’s Advanced Programmable Interrupt Controller

(APIC) architecture, there are now usually 24 interrupt lines


available that can accommodate upto 255 devices
9
101: system Architecuture
1. Determine and configure Hardware settings ...
Interrupt Requests … contd.
 /proc/interrupts – directory that lists allocation of IRQs to

devices in Linux System


 /proc – It is a virtual file system, kernel sets up this file

system
 to export information about the running kernel user processes,
& hardware devices that have been configured
 Exist only in memory & doesnot represent any true physical
files
10
101: system Architecuture
1. Determine and configure Hardware settings ...
Input / Output Addresses.
 CPU and peripheral devices, communications make use of IO

addresses
 Two types of methods 1)Memory Mapped IO
 2) Port Mapped IO
 MMIO – regions of memory reserved for communication
 PMIO – CPU has separate set of instructions for performing IO

with devices having a separate address space


#less /proc/ioports – reveals allocation of IO ports
#less /proc/iomem – reveals allocation of IO memory
11
101: system Architecuture
1. Determine and configure Hardware settings ...
DMA Addresses.
 Enahancement /optimisation that allows devices to read/write

directly to memory w/o CPU involvement


#less /proc/dma – shows allocation of DMA addresses
 For most devices it is automatically configured by the OS
 PATA devices may not be automatically configured

#hdparm –d1 /dev/sda – enabling DMA address


#hdparm –d /dev/sda – see current setting on hard disk
12
101: system Architecuture
1. Determine and configure Hardware settings ...
Configuring IRQs, IO Ports/Addresses
 Configuration for device IRQ, IO addresses, DMA channels and

memory regions happens automatically with PnPs


 Via system BIOS, Linux Kernel & device drivers resource

conflicts are resolved for PnPs


 Linux provides utilities to query devices to find resources they

use,
 lspci, setpci } utilities that use information from /proc

#lspci -vv : provides verbose information on any devices using PCI


bus
#setpci : for configuring and querying pci devices
13
101: system Architecuture
1. Determine and configure Hardware settings ...
Linux Device Management Overview
 Device driver – a kernel space program that allow applications to

interact with hardware.


 Kernel space – privileged code having full access to hardware and runs

in ring 0
 User space applications – run in less privileged mode ring 3, and

cannot access hardware directly, calls kernel space in order to access


hardware on their behalf.
 Linux exports information about devices to /sys, virtual FS when PnP

device is inserted/removed /sys is updated, and udev daemon takes care


of this.
 udev also creates relevant entries under /dev FS

 D-Bus daemon then receive and post notification to Desktop


14
101: system Architecuture
1. Determine and configure Hardware settings ...
Linux Device Management Overview
15
101: system Architecuture
1. Determine and configure Hardware settings ...
Mass Storage Devices … contd
 Originally x86 machines hard disks only supported a max. of 4

partitions, i.e. partition table holds only 4 entry


 If more partition required, mark one of 4 partitions as extended

partition in order to create as many logical partitions as we want.


 MBR – is a special type of boot sector, at the beginning of

partitioned computer
 Boot sector – is region of hard disk that contains machine code to

be loaded to RAM, allow boot process of a computer to load


programs.
16
101: system Architecuture
1. Determine and configure Hardware settings ...
Mass Storage Devices
 PATA – Parallel Advanced Technology Attachment

 Linux identifies it as /dev/hd[a-z]

 /dev/hda – master drive on primary connector

 /dev/hdc – master drive on secondary connector


 /dev/hda1 – first primary partition on hda
 /dev/hda2 – second primary partition on hda
 Hard disks have their data accessible randomly and are called block

devices
 Linux kernels’ device-mapper framework allows for creation of virtual

block devices on which FS is created.


 Virtual Block Devices allow creation of encrypted partition as well as

RAID, w/o need for special hardware


101: system Architecture
1. Determine and configure Hardware setting …

 http://wiki.osdev.org/MBR_(x86)#Building_a_Custom_MB
R_Bootstrap_program
18
101: system Architecuture
1. Determine and configure Hardware settings ...
USB Support
 Hot plug interface
 USB support is present from Linux kernel 2.2.7
 #lsusb – command to list the USB devices

Device Drivers
 Kernel uses drivers to export device info to /sys file system
 In most Linux distributions, drivers are provided as part of the kernel, can

be loaded/unloaded dynamically without the need to recompile the Kernel.


 #lsmod – lists currently installed modules
 #modinfo – query a module for dependency, author
 #insmod – install a module, by providing path to driver
 #modprob – installs a module via module name, handles deps
 #rmmod – Remove
19
101: system Architecuture
1. Boot the System
Introduction
 BIOS, CPU goes to address of BIOS and loads it

 BIOS loads MBR of Boot device


 MBR contains bootstrap program, written in Assembly
 MBR has partition table portion
 MBR format
 The partition has 4 entries, order doesn’t matter
 There can be one active partition at most
 Partition table (PT) conforms to a standard layout, that is

independent of the Operating System


 Each PT is 16-byte long, max of 4 entries
20
101: system Architecture
1. Boot the System … contd
Dual Booting
 A huge improvement over the standard MBR
 Standard x86 boot sequence only boot the MBR from the

first disk found during disk detection phase, as well as


allow a single active partition on that disk
 The standard MBR is replaced with dual booting MBR.
 Now, one MBR can load and run a different MBR of

different drive, “Chain Loading”


101: system Architecture
1. Boot the System … contd
22
101: system Architecture
1. Boot the System … contd
Boot process
1. BIOS loads MBR, the first stage boot loader
2. First boot loader loads second stage boot loader, this stage gives
flexibility in selecting the Kernel
3. Kernel takes over the control
 The kernel starts and configures the CPU type, interrupts …
 Kernel loads initial RAM Disk (initrd), way to access system

hardware where root partition is located.


 as root partition is loaded, initrd swaps out

4. Kernel becomes fully operational, then loads /sbin/init, which sets

up user space, login shell, graphical logins …


23
101: system Architecture
1. Boot the System … contd
2nd stage boot loader,
 Gives a lot of options that help us override some

parameters
e.g. init – overrides the process that is run by the kernel after
it has finished loading,
“init=/bin/bash” – is used to by pass login prompt in
case password is forgotten.
24
101: system Architecture
1. Boot the System … contd
Init Process overview
 After loading the kernel, init process is started,
 Init is responsible for checking and mounting file systems,

and starting up configured services.


 Init starts services after entering default run level

e.g. default run level looks like this (in /etc/inittab)


id : 3 : initdefault:
 Where, id= a 4 character name, 3=run level,

initdefault=action
25
101: system Architecture
1. Boot the System … contd
Actions
 wait – init will wait till process starting is completed
 respawn – init restarts even when process terminates, usual used

for getty processes


 ** getty, short for "get teletype", is a Unix program running on a

host computer that manages physical or virtual terminals (TTYs).


When it detects a connection, it prompts for a username and runs
the 'login' program to authenticate the user. It is usually called by
init.
 Ctrl-Alt-Del – traps key combination

 powerfail, pwerokawait – used to respond to notifications to UPS


26
101: system Architecture
1. Boot the System … contd
The /etc/inittab
 You can configure your system to easily capture the Alt-Ctrl-Del

key, by adding a line to /etc/inittab

Inittab taken from fedora


27
101: system Architecture
1. Boot the System … contd
The /etc/inittab … contd
28
101: system Architecture
1. Boot the System … contd
The /etc/inittab .. contd
As usual, lines starting with # are comments. Other lines have several
fields with the following format:
 id:runlevels:action:process

 id is a unique identifier of one to four characters. Older versions

limited this to two characters, so you will often see only two characters
used.
 runlevels lists the runlevels for which the action for this id should be

taken. If no runlevels are listed, do the action for all runlevels.


 action describes which of several possible actions should be taken
 process tells which process, if any, should be run when the action on

this line is performed.


29
101: system Architecture
1. Boot the System … contd
The /etc/inittab .. contd
 Initialization scripts

 In this example, init will run the /etc/rc.d/rc script (or


command) with the parameter of 5 whenever runlevel 5 is
entered.
 init will wait until this command completes before doing

anything else.
30
101: system Architecture
1. Boot the System … contd
Troubleshooting Boot Process
dmesg
 Contents of ring buffer (memory location) can be read with dmesg tool
 It can also tell us screen outputs during bootup

/var/log/syslog or /var/log/messages
 These two files are additional locations where we have to look at to

examine what happened during boot process


Failure to boot
 “Root device cannot be found, ctrl + D to perform maintenance”
 “Kernel Panic” – Incorrectly configured initrd image or missing root

device
 Maintain through Live CD, with out mounting Root file system
31
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Introduction
 Linux has 7 run-levels [0 – 6]
 Run-levels are assigned to the following configurations
 1) single user mode
 2) multi-user, text mode, no servers
 3) multi-user, text mode, servers
 4) multi-user, GUI mode, no servers
 5) multi-user, GUI mode, servers.
32
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Introduction … contd
 Run levels on Red hat server
 # Default runlevel. The runlevels used by RHS are:
 # 0 - halt (Do NOT set initdefault to this)
 # 1 - Single user mode
 # 2 - Multiuser, without NFS (The same as 3, if you do not have
networking)
 # 3 - Full multiuser mode
 # 4 - unused
 # 5 - X11
33
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Introduction … contd
 Run levels specific scripts are stored in /etc/init.d/rc?.d

or /etc/rc?.d/, where ? Represents run levels [0 – 6]


 Original scripts stored in /etc/rc.d, /etc/init.d or

/etc/rc.d/init.d
 Symbolic links: must have S – for start at run level entry

K – killed at run level


entry
34
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Debian based systems
#update-rc.d disable 3 apache2

#update-rc.d enable 3 apache2


RPM based systems Remove apache service from rc3
#chkconfig –del httpd
#chkconfig –add httpd Add service: apache2 to rc3
Or
#chkconfig –level 3 httpd on
35
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Changing run levels
 Single-user mode
 Linux is inherently a multiuser system.
 However, there are times when that can be a problem, such as when you need

to recover a major filesystem or database, or install and test some new


hardware.
 Runlevel 1, or single-user mode, is your answer for these situations. As it start

in a shell with only a minimal system.


 Usually there will be no networking and no (or very few) daemons running. On

some systems, you must authenticate by logging in, but on others you go
straight into a shell prompt as root.
 Single-user mode can be a lifesaver, but you can also destroy your system, so

always be careful whenever you are running with root authority. Reboot to
normal multiuser mode as soon as you are done.
36
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Changing run levels
 Single-user mode
 As with switching to regular multiuser runlevels, you can also switch to

single-user mode using telinit 1


#telinit 1
Clean shutdown
 telinit or init to stop multiuser activity and switch to single-user mode, this

can be rather abrupt and cause users to lose work and processes to
terminate abnormally.
 The preferred method to shut down or reboot the system is to use the

shutdown command,
 Shutdown first sends a warning message to all logged-in users and blocks

any further logins. It then signals init to switch runlevels.


37
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Clean shutdown
 The init process then sends all running processes a SIGTERM signal,

(process termination signal)


 giving them a chance to save data or otherwise properly terminate.

After 5 seconds, or another delay if specified, init sends a SIGKILL


signal to forcibly end each remaining process.
 By default, shutdown switches to runlevel 1 (single-user mode).

 You may specify the -h option to halt the system, or the -r option to

reboot.
 A standard message is issued in addition to any message you specify.

The time may be specified as an absolute time in hh:mm format


38
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Clean shutdown
Thus,
#shutdown –h } just shutdown the system
#shutdown –h +10 } shutdown in 10 minutes
#shutdown –r 14:30 } reboot at 14:30
#shutdown –c } cancel any schedules shutdown process
39
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Halt, reboot, and poweroff
 The halt command halts the system, system temporary suspension
 The poweroff command is a symbolic link to the halt command,

which halts the system and then attempts to power it off.


 The reboot command is another symbolic link to the halt

command, which halts the system and then reboots it.


 For additional options that you may use with these commands, as

well as more detailed information on their operation, consult the


man page.
40
101: system Architecture
3. Runlevels, Rebooting, Shutting Down System
Starting | stopping services
Debian based
#/etc/init.d/apache2 stop|start|restart|reload

RPM based
#service httpd start|stop|reload

You might also like