BIOS initilization
Boot Loader
Kernel initilization
Init
Boot Loader
stage 1 resides in MBR its small 512bytes
(446 bytes of programme code, 64bytes of Partition table and 2 magic no (valid mbr)
stage 2 loaded from boot partition
for linux to boot min require
label
kernal location
root filesystem location
initial ram disk
Grub
/etc/grub/grub.conf (have these settings)
Kernal initilization
device detection, loads device drivers, mount filesystems read only, then load init.
/etc/inittab
specifies runlevel
0 : hault ( do not set init default to this)
1 : single user mode
2 : multi user mode without networking
3 : multi-user mode with networking
4 : unused
5 : X11 (Graphical)
6 : reboot
id:5:initdefault
/etc/rc.d/rc.sysinit
(selinux,kernal parameters (sysctl.conf),swap partitions, hostname, filesystem checking and remounting
RAID, LVM ,disk quotas)
/etc/rc.d/rc
/etc/rc.d/rc?.d/ (runlevel specific services )
/etc/rc.d/rc.local
1. Linux boot
process.
The following are
the 6 high level stages of a typical Linux boot process.
1.1. BIOS
- BIOS stands for Basic Input/output System
- Performs some system integrity checks
- Searches, loads, and executes the boot loader program.
- It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
- Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
- So, in simple terms BIOS loads and executes the MBR boot loader.
1.2. MBR
- MBR stands for Master Boot Record.
- It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
- MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
- It contains information about GRUB (or LILO in old systems).
- So, in simple terms MBR loads and executes the GRUB boot loader.
1.3. GRUB
- GRUB stands for Grand Unified Boot loader.
- If you have multiple kernel images installed on your system, you can choose which one to be executed.
- GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
- GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
- Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title
CentOS (2.6.18-194.el5PAE)
root
(hd0,0)
kernel
/boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd
/boot/initrd-2.6.18-194.el5PAE.img
- As you notice from the above info, it contains kernel and initrd image.
- So, in simple terms GRUB just loads and executes Kernel and initrd images.
1.4. Kernel
- Mounts the root file system as specified in the “root=” in grub.conf
- Kernel executes the /sbin/init program
- Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
- initrd stands for Initial RAM Disk.
- initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.
1.5. Init
- Looks at the /etc/inittab file to decide the Linux run level.
- Following are the available run levels
- 0 – halt
- 1 – Single user mode
- 2 – Multiuser, without NFS
- 3 – Full multiuser mode
- 4 – unused
- 5 – X11
- 6 – reboot
- Init identifies the default init level from /etc/inittab and uses that to load all appropriate programs.
- Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
- If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
- Typically you would set the default run level to either 3 or 5.
1.6. Runlevel programs
- When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
- Depending on your default init level setting, the system will execute the programs from one of the following directories.
- Run level 0 – /etc/rc.d/rc0.d/
- Run level 1 – /etc/rc.d/rc1.d/
- Run level 2 – /etc/rc.d/rc2.d/
- Run level 3 – /etc/rc.d/rc3.d/
- Run level 4 – /etc/rc.d/rc4.d/
- Run level 5 – /etc/rc.d/rc5.d/
- Run level 6 – /etc/rc.d/rc6.d/
- Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
- Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
- Programs starts with S are used during startup. S for startup.
- Programs starts with K are used during shutdown. K for kill.
- There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
- For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
2. Software
Package Administration
2.1 Querying
software packages
To list the
installed software:
rpm
-qa | less
rpm -qa {software-name}
yum list | less
yum list {software-name}
rpm -qa {software-name}
yum list | less
yum list {software-name}
For
Debian use
dpkg
--list
dpkg --list | less
dpkg --list | grep apache
dpkg --list | less
dpkg --list | grep apache
2.2:
Installing software packages
Note:
Please note that you need to log in as root to install the software
using rpm command:
Installing RPM in
Redhat/Fedora/CentOS
RPM is nothing but a
package management system. To install an rpm file, open a terminal
and then type the following command:
$rpm
-ivh xyz.rpm
$dpkg
-i xyz.deb (debian packages)
Installing
Packages from repositories (yum/apt)
$yum
install {package-name-1}
e.g
$yum install httpd
e.g
$apt-get install http
Installing
package from source (tar.bz,tar.bz2)
1)
Extract the package using
$tar
–xzvf xyz.tar.bz (.tar.bz)
$tar
–xjvf xyz.tar.bz2 (.tar.bz2)
2)
Go to the extracted directory $cd xyz/
3)
$./configure
4)
$make
5)
$make install
2.3 Upgrading the
software package
$rpm
-Uvh xyz.rpm
$yum
update <Package_name>
$apt-get
update <Package_name>
(for debian)
2.4 Removing the
software package
$rpm
-e {software-name}
$yum remove {software-name}
$yum remove {software-name}
$apt-get
remove {software-name}
3. User
and Group Administration
3.1 Creating and
deleting users from the systems
Note:
Please note that you need to log in as root to do this task
Creating:
$useradd
<user_name>
If you want to
assign a particular Home directory to the user you can do that using
this command.
$useradd
<user_name>
-d
/home/<user_name>
Command line options
for useradd are detailed below:
Add a new user to
primary group
$useradd
–g <Group-name>
<User-name>
Add a new user to
secondary group
$useradd
-G <Group-name>
<User-name>
Deleting:
$userdel
<user_name>
This will remove the
user. But if you want to remove all the files and its home folder
then use
$userdel
–r <user_name>
3.2 Creating and
deleting groups
To add a group to
the system, use the command groupadd:
$groupadd
<group-name>
Command line options
for groupadd are
detailed below:
To remove a group
from the system, use the command groupdel:
$groupdel
<group-name>
3.3 Modifying
users/group profile.
Changing the
password
$passwd
<user-name>
Changing the home
directory of user
$usermod
–d <path_of_new_home_directory>
<user_name>
To change the
directory as well as move the contents use –m option
$usermod
–m –d <path_of_new_home_directory>
<user_name>
Adding existing user
to a group
$usermod
-a -G <Group-name>
<User-name>
Changing existing
primary group
$usermod
–g <Group-name> <User-name>
Changing the user
name
$usermod
–l <new-name> <old-name>
3.4 Linux files
responsible for User managements
/etc/shadow
store all the Linux password in MD5 encryptions format
/etc/passwd
store all user related information's
/etc/group
store all group related information's
4. File
permissions/ownerships in Linux
4.1 Changing the
permissions of a file
Linux have three user classes as follows:
- User (u): The owner of file
- Group (g): Other user who are in group (to access files)
- Other (o): Everyone else
You can setup following mode on each files. In a Linux set of
permissions is called as mode:
- Read (r)
- Write (w)
- Execute (x)
However, above three modes or permission have different meaning for
file and directory:
Linux Read mode permissions
- Read access on a file allows you to view file
- Read access on a directory allows you to view directory contents with ls command
Write mode permissions
- Write access on a file allows you to write to file
- Write access on a directory allows you to remove or add new files
Execute mode permissions
- Execute access on a file allows to run program or script
- Execute access on a directory allows you access file in the directory
Octal representation
-rwx-rwx-rwx
1st rwx is for user
2nd rwx is for group
3rd rwx is for other
So if you want to give permissions use the below table
u g
o
r w x r w x r w
x
1 1 1 1 1 1 1 1
1 Permissions for read, write and execute
Now convert 111 in
decimal which is equal to 7
Similarly for read
only
u g
o
r w x r w x r w
x
1 0 0 1 0 0 1 0
0 Permissions for read only
Hence 4
777 (all can read
write and execute)
666 (all can read
and write)
700 (owner can
read, write and execute)
600 (owner can
read and write)
chmod
command :
$chmod
777 <file-name>
Or
$chmod
u+x <file-name>
- give user execute priviliges
$chmod
g+rx <file-name>
- gives group read and execute permission
Recursive (-R)
$
chmod -R g+rwx /u01 – gives group read write and execute to all the
files in /u10 directory
4.1 Changing the
ownership of a file
drwxr-xr-t
3 root root 4096 Jul 12 2001 admin
-rwxr-xr-x
1 msp ocadmin 1282580 Jun 13 11:14 asn1c-0.9.21.tar.gz
Here in the above
e.g. admin is owned by user root and group root and
asn1c-0.9.21.tar.gz is owned by user msp and rroup ocadmin
chown command :
$chown
<user-name>:<group-name>
<file-name>
e.g.
$chown
abdul:admin xyz.txt
If you want to
change the ownership of all the files in a specific directory use –R
option
e.g.
$chown –R abdul:admin /abc
5. Disk
Partitioning and Mounting File System
Thanking YouHope U Like it.....