Sunteți pe pagina 1din 9

Types of Device Files

Character device files


• writes to and from the device a character at a time.
• Indicated by a "c" in the first field.
• Very little preliminary processing required by the kernel
so the request is passed directly to the device.
Block device files
receives a request once
block buffering take place in the kernel.
Indicated by a "b" in the first field.
A filesystem is an example of a block buffering device.
Block devices generally have an associated
character device
For example if you format a diskette you would use the
character device file name, if backing up to that diskette
you would use the block device name where the blocking is
handled in the kernel buffer cache.

Hardlinks and Symbolic links


Symbolic links (also called symlinks or softlinks) most
resemble Windows shortcuts. They contain a pathname to a
target file.
Hard links are listings that contain information about the file.
Linux files don't actually live in directories. They are
assigned an inode number, which Linux uses to locate files.
So a file can have multiple hardlinks, appearing in multiple
directories, but isn't deleted until there are no remaining
hardlinks to it.
Hardlinks Vs Symlinks
Hardlink cannot be created for a directory.
If the original file of a hardlink is removed, the link will still
show the content of the file.
A symlink can link to a directory.
A symlink, is like a Windows shortcut, becomes useless
when original file is removed.

Hardlinks
Make a hardlink to FileA. Call the hardlink FileB.
$ ln FileA FileB
Use the "i" argument to list the inodes for both FileA and its hardlink.
$ ls -il FileA FileB
This is what you get:
1482256 -rw-r--r-- 2 bruno bruno
1482256 -rw-r--r-- 2 bruno bruno
21 May 5 15:55 FileA
21 May 5 15:55 FileB
Both FileA and FileB have the same inode number (1482256).
Also both files have the same file permissions and the same size.
Because that size is reported for the same inode, it does not consume any extra
space on HD!
Next, remove the original FileA:
$ rm FileA
And have a look at the content of the "link" FileB:
MAIT/Alok/Namita
128
$ cat FileB
You will still be able to read the contents of file.

Let's make a symlink to FileB. Call the symlink FileC:


$ ln -s FileB FileC
Then use the i argument to list the inodes.
$ ls -il FileB FileC
This is what you'll get:
1482256 -rw-r--r-- 1 bruno bruno 21 May 5 15:55 FileB
1482226 lrwxrwxrwx 1 bruno bruno 5 May 5 16:22 FileC -> FileB
You'll notice the inodes are different and the symlink got a "l" before the
rwxrwxrwx.
The link has different permissions than the original file because it is just a
symbolic
link.
Its real content is just a string pointing to the original file.
The size of the symlink (5) is the size of its string.
MAIT/Alok/Namita
129
09/05/2008
(The "-> FileB" at the end shows you where the link points to.)

Linux's boot process explained


Short history of the UNIX operating system
Linux is an implementation of the UNIX operating system concept. UNIX was
derived from AT&T's "Sys V" (System 5). The initialization process is meant to
control the starting and ending of services and/or daemons in a system, and
permits different start-up configurations on different execution levels ("run
levels").
Some Linux distribution, like SlackWare, use the BSD init system, developed at
the University of California, Berkeley.
Sys V uses a much more complex set of command files and directives to
determine which services are available at different levels of execution, than th
e
BSD's do.
Booting the Linux operating system
The first thing a computer does on start-up is a primer test (POST - Power On
Self Test). This way several devices are tested, including the processor, memory
,
graphics card and the keyboard. Here is tested the boot medium (hard disk,
floppy unit, CD-ROMs). After POST, the loader from a ROM loads the boot
sector, which in turn loads the operating system from the active partition.
The boot blocks is always at the same place: track 0, cylinder 0, head 0 of the
device from which we're booting. This block contains a program called loader,
which in Linux's case is LiLo (Linux Loader), or Grub (GNU Grub Unified Boot
Loader), which actually boots the operating system. These loaders in Linux , in
case of a multi-boot configuration (more operating systems on a computer),
permit the selection of the operating system to be booted. Lilo and Grub are
installed or at the MBR (Master Boot Record), or at the first sector of the acti
ve
partition.
In the following we will refer to LiLO as boot loader. This is usually installed
in
the boot sector, also known as MBR. If the user decides to boot Linux, LiLo will
try to load the kernel. Now I will present step-by-step LiLo's attempt to load t
he
operating system.
1. In case of a multi-boot config, LiLo permits the user two choose an operating
MAIT/Alok/Namita
151
09/05/2008
system from the menu. The LiLo settings are stored at /etc/lilo.conf. System
administrators use this file for a very detailed finement of the loader. Here ca
n be
manually set what operating systems are installed, as well as the method for
loading any of them. If on the computer there is only Linux, LiLo can be set to
load directly the kernel, and skip the selection menu.
2. The Linux kernel is compressed, and contains a small bit, which will
decompress it. Immediately after the first step begins the decompression and the
loading of the kernel.
3. If the kernel detects that your graphics card supports more complex text
modes, Linux allows the usage of them - this can be specified or during the
recompilation of the kernel, or right inside Lilo, or other program, like rdev.
4. The kernel verifies hardware configuration (floppy drive, hard disk, network
adapters, etc) and configures the drivers for the system. During this operation,
several informative messages are shown to the user.
5. The kernel tries to mount the file system and the system files. The location
of
system files is configurable during recompilation, or with other programs - LiLo
and rdev. The file system type is automatically detected. The most used file
systems on Linux are ext2 and ext3. If the mount fails, a so-called kernel panic
will occur, and the system will "freeze".
System files are usually mounted in read-only mode, to permit a verification of
them during the mount. This verification isn't indicated if the files were mount
ed in
read-write mode.
6. After these steps, the kernel will start init, which will become process numb
er
1, and will start the rest of the system.
The init process
It's Linux's first process, and parent of all the other processes. This process
is the
first running process on any Linux/UNIX system, and is started directly by the
kernel. It is what loads the rest of the system, and always has a PID of 1.
MAIT/Alok/Namita
152
09/05/2008
The initialization files in /etc/inittab
First time the initialization process (init) examines the file /etc/inittab to d
etermine
what processes have to be launched after. This file provides init information on
runlevels, and on what process should be launched on each runlevel.
After that, init looks up the first line with a sysinit (system initialization)
action and
executes the specified command file, in this case /etc/rc.d/rc.sysinit. After th
e
execution of the scripts in /etc/rc.d/rc.sysinit, init starts to launch the proc
esses
associated with the initial runlevel.
The next few lines in /etc/inittab are specific to the different execution (run-
)
levels. Every line runs as a single script (/etc/rc.d/rc), which has a number fr
om 1
to 6 as argument to specify the runlevel.
The most used action in /etc/inittab is wait, which means init executes the
command file for a specified runlevel, and then waits until that level is termin
ated.
The files in /etc/rc.d/rc.sysinit
The commands defined in /etc/inittab are executed only once, by the init process
,
every time when the operating system boots. Usually these scripts are running as
a succession of commands, and usually realise the following:
1. Determine whether the system takes part of a network, depending on the
content of /etc/sysconfig/network
2. Mount /proc, the file system used in Linux to determine the state of the dive
rse
processes.
3. Set the system time in fuction to the BIOS settings, as well as realises othe
r
settings (setting of time zone, etc), stabilized and configured during the
installation of the system.
4. Enables virtual memory, activating and mounting the swap partition, specified
in /etc/fstab (File System Table)
5. Sets the host name for the network and system wide authentication, like NIS
(Network Information Service), NIS+ (an improved version of NIS), and so on.
MAIT/Alok/Namita
153
09/05/2008
6. Verifies the root fily system, and if no problems, mounts it.
7. Verifies the other file systems specified in /etc/fstab.
8. Identifies, if case of, special routines used by the operating system to
recognize installed hardware to configure Plug'n'Play devices, and to activate
other prime devices, like the sound card, for example.
9. Verifies the state of special disk devices, like RAID (Redundant Array of
Inexpensive Disks)
10. Mounts all the specified file systems in /etc/fstab.
11. Executes other system-specific tasks.
The /etc/rc.d/init.d directory
The directory /etc/rc.d/init.d contains all the commands which start or stop
services which are associated with all the execution levels.
All the files in /etc/rc.d/init.d have a short name which describes the services
to
which they're associated. For example, /etc/rc.d/init.d/amd starts and stops the
auto mount daemon, which mounts the NFS host and devices anytime when
needed.
The login process
After the init process executes all the commands, files and scripts, the last fe
w
processes are the /sbin/mingetty ones, which shows the banner and log-in
message of the distribution you have installed. The system is loaded and
prepared so the user could log in.
Linux's execution levels
The execution levels represent the mode in which the computer operates. They
are defined by a set of available services at any time they are started. The
MAIT/Alok/Namita
154
09/05/2008
execution levels represent different ways Linux uses to be available to you, the
user, or eventually the administrator.
As daily user you don't have to bother with the execution levels, although the
multi-user level makes the services which you need while using Linux in a
network (though in a transparent mode) available.
In the next few sentences I'll present the execution levels, one by one:
0: Halt (stops all running processes and executes shutdown)
1: Known under the name "Single-user mode". In this case the system runs with
a reduced set of services and daemons. The root file system is mounted read-
only. This runlevel is used when the others fail while booting.
2: On this level run the most of the services, with the exception of network
services (httpd, named, nfs, etc). This execution level is ideal for the debug o
f
network services, keeping the file system shared.
3: Complete multi-user mode, with network support enabled.
4: Unused, in most of the distributions. In Slackware this level is equivalent w
ith
3, the only difference is that this has graphic login enabled.
5: Complete multi-user mode, with network and graphic subsystem support
enabled.
6: Reboot. Stops all running processes and reboots the system to the initial
execution level.
Modification of execution levels
The most used facility of init, and maybe the most confusing one, is the ability
to
move from an execution level to an other.
The system boots into a runlevel specified in /etc/inittab, or to a level specif
ied at
the LiLo prompt. To change the execution level, use the command init. For
example, to change the execution level to 3, type
init 3
MAIT/Alok/Namita
155
09/05/2008
This stops most of the processes and takes the system into a multi-user mode
with networking enabled. Attention, changing the init level might force several
daemons used at the moment to stop!
The directories of execution levels
Every execution level has a directory with a symbolic links (symlinks) pointing
to
the corresponding scripts in /etc/rc.d/init.d. These directories are:
/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
The name of the symlinks are semnificative. It specifies which service has to be
stopped, started and when. The links starting with an "S" are programmed to
start in various execution levels. The links also have a number in their name (0
1-
99). Now some examples of symlinks in the directory /etc/rc.d/rc2.d:
K20nfs -> ../init.d/nfs
K50inet -> ../init.d/inet
S60lpd -> ../init.d/lpd
S80sendmail -> ../init.d/sendmail
When operating systems change the execution level, init compares the list of the
terminated processes (links which start with "K") from the directory of the curr
ent
execution level with the list of processes which have to be started (starting wi
th
"S"), found in the destination directory.
Example:
When the system boots into runlevel 3, will execute all the corresponding links
MAIT/Alok/Namita
156
09/05/2008
starting with "S", in an order accorind to their number:
/etc/rc.d/rc3.d/S60lpd start
/etc/rc.d/rc3.d/S80sendmail start
(and so on)
If the system now changes to runlevel 1, will execute:
/etc/rc.d/rc3.d/K20nfs stop
/etc/rc.d/rc3.d/K50inet stop
(presuming that nfs and inet are NOT in /etc/rc.d/rc1.d)
After that it will start all the processes mentioned in /etc/rc.d/rc1.d except w
hich
are already running. In this example there's a single one only:
/etc/rc.d/rc1.d/S00single
Changing the current execution level
To change the current execution level for example to level 3, edit /etc/inittab
in a
text editor, and edit the following line:
id:3:initdefault:
(do not change the initial runlevel to 0 or 6!)
Booting into an alternative execution level
At the LiLo prompt you have to write the number of the wanted execution level,
before booting the operating system. This way to boot into the third level, type
for
example:
linux 3
Eliminating a service from an execution level
MAIT/Alok/Namita
157
09/05/2008
To disable a service from a runlevel, you might simply delete or modify the
corresponding symlink.
For example, to disable pcmcia, and don't start in the future, type:
rm /etc/rc.d/rc3.d/S45pcmcia
Adding a service to an execution level
To add a service, it is needed to create a symlink pointing to the corresponding
scripts in /etc/rc.d/init.d. After the symlink is created, be sure to assign it
a
number, so it would be started in the right time:
To add "lpd" to runlevel 3, type:
ln -s /etc/rc.d/init.d/lpd /etc/rc.d/rc3.d/S64lpd
Kernel Initialization
• The Kernel initialization activities take place so quickly
that if you don’t watch carefully during boot, you may
miss them.
• Device drivers compiled into kernel are called, and will
attempt to locate their corresponding devices. If
successful in locating the device, the driver will initialize
and usually log output to the kernel message buffer.
• After all the essential drivers are loaded, the kernel will
mount the root filesystem(read-only).
• The first process is then loaded (INIT) and control is
passes from the kernel to that process.
init Initialization
• init is the parent of all processes. This is easily shown by
running the pstree command.
• Because init is the first process, it will always have a PID
of number 1.
• The file /etc/inittab contains the information on how init
should set up the system in every run level, to use as
default.
• If the /etc/inittab file is missing or seriously corrupt, you
will not be able to boot to any of the standard levels (0-6)
and will need to use single or emergency mode instead.
init reads its config: /etc/inittab
• Initial run level
• System initialization scripts
• Run level specific script directories
• Trap certain key sequences
• Define UPS power fail / restore scripts
• Spawn gettys on virtual consoles
• Initialize X in run level 5

The Linux Boot process


When you start up a Linux system, a series of
events occurs after you power up and before
you receive a login prompt. This sequence is
referred to as the boot process. Although this
sequence can vary based on configuration, the
basic steps of the boot process can be summed
up as follows :
The Basic Input/Output (BIOS) starts and checks for
hardware devices. Stored in the computer’s ROM, the
BIOS is described as firmware because it is built into
hardware memory. The BIOS will automatically run when
the power is applied to the computer. The purpose of
the BIOS is to find the hardware devices that will be
needed by the boot process, to load and initiate the boot
program stored in the Master boot record (MBR), and
then pass off control to that boot program. In the case of
Linux, the BIOS performs its checks and then looks to
the MBR, which contains the first-stage boot loader,
such as GRUB or LILO. After finding the boot loader, the
BIOS initiates it.
Note : Sometimes, however, the MBR contains another
boot loader, which on turn finds the boot loader on the
first sector of a Linux partition.
The BIOS hands over control to the first-stage boot
loader, which then reads in the partition table and looks
for the second-stage boot loader on the partition
configured as bootable.
• The first-stage boot loader runs the second-stage boot
loader, which then finds the kernel image and runs it.
• The kernel image contains a small, uncompressed
program that decompresses the compressed portion of
the kernel and runs it. The kernel scans for system
information including the CPU type and speed. Its drivers
scan for other hardware and configure what they find.
The kernel then mounts the root filesystem in read-only
mode to prevent corruption during the boot process.
• The kernel starts the init process by running /sbin/init.
The init process starts up getty programs for the virtual
consoles and serial terminals and initiates other
processes as configured and monitors them until
shutdowm.
This general boot process can be affected by various
factors even within the same distribution. For instance,
the steps above assume the system has only one
bootable kernel image. That’s probably the case when
you install, but you might also have a bootable sector
installed with another operating system, like windows.
Later, if you install a different version of the kernel and
compile it, you’ll have to configure your boot loader to
see it. There are a number of parameters that you can
specify at the boot prompt.
The Master Boot Record
• The Master boot record (MBR) plays a crucial role in
bootup process. Located on the first disk drive, in the last
sector of the first cylinder of track 0 and head 0 (this
whole track is generally reserved for boot programs), it is
a special area on your hard drive that is automatically
loaded by computer’s BIOS. Since the BIOS is loaded on
an electronically erasable programmable read only
memory (EEPROM) chip, which is generally not
reprogrammed at the user/ administrator level, the MBR
is the earliest point at which a configured boot loader can
take control of the boot process.
Multiboot Systems
• Partitioning Issues
In order to run RHEL, it is necessary to create Linux swap and
native properties. It is usually advisable to install the other
operating systems first. While RHEL will not try to delete other
operating systems, other operating systems are not always so
courteous. When installing the other operating system unpartitioned
space must be left for the Linux partitions.
Sometimes another operating system already exists on a system
and occupies all the available disk space. In these cases, there are
two options:
• Back up the existing operating system(s) and files, repartition the drive
leaving space for RHEL, the reinstall the existing operating system(s)
from backup.
• Back up the existing operating system and files, then use the third
party tool Partition Magic to resize the existing partitions to make
space.
For Dos, Windows 3.x, 95, 98, NT or 2000 (if installed using a
Fat filesystem), there is an additional option: FIPS, a DOS utility
included on the RHEL installation CDROM. FIPS can non-
destructively split an existing FAT partition.
• Boot Process Issues
If a system will be booting multiple operating systems it will need
a boot loader that is capable of booting multiple operating
systems. Boot floppies are also an option, though not a
particularly convenient one. In general, boot process
configuration falls into one of the two categories:
• GRUB is the primary boot loader and will launch Linux and other
operating systems ( or their boot loaders): use this approach with
DOS, Windows 3.x, 9x, ME, NT, 2000, XP, 2003
• A boot loader such as System Commander or NTLDR is already on
the system and will launch GRUB as a secondary boot loader.

S-ar putea să vă placă și