Linux Interview Questions On Boot Process and Other Stuff
Linux Interview Questions On Boot Process and Other Stuff
GNU GRUB is a Multiboot boot loader. It was derived from GRUB, the GRand
Unified Bootloader.Boot loader is the first software program that runs when a
computer starts. It is responsible for loading and transferring control to the
operating system kernel software. The kernel, in turn, initializes the rest of the
operating system (e.g. GNU)
Press the power button on your system, and after few moments you see the Linux
login prompt.Have you ever wondered what happens behind the scenes from the
time you press the power button until the Linux login prompt appears?
The following are the 6 high level stages of a typical Linux boot process.
a. BIOS
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.
b. MBR
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.
So, in simple terms MBR loads and executes the GRUB boot loader.
c. GRUB
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).
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
root (hd0,0)
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.
d. Kernel
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 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.
e. Init
Looks at the /etc/inittab file to decide the Linux run level.
0 – halt
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all
appropriate program.
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.
f. 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.
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.
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.
There you have it. That is what happens during the Linux boot process.
3) Which files are called for user profile by default when a user gets login
$HOME/.bash_profile, $HOME/.bash_bashrc
id:5:initdefault: to id:3:initdefault:
5) What command used for showing user info like Login Name, Canonical Name,
Home Directory,Shell etc..
inode stores basic information about a regular file, directory, or other file system
object
Group
File Size
find out the inode number using ‘ls -il’ command then run below command
blockdev command
# Before test
256
2549+1 records in
real 0m6.845s
user 0m0.004s
sys 0m0.865s
# After test
2435+1 records in
real 0m0.370s
user 0m0.001s
sys 0m0.370s
CHAGE command
usermod -L username
10) How many default number of Shells available and what are their names?
11) Which file defines the attributes like UID, PASSWORD expiry, HOME Dir
create or not while adding user
/etc/login.defs
authconfig
chattr
/etc/sysconfig/network-scripts/ethX
15) How can we change speed and make full duplex settings for eth0
OR
mii-tool -F 100baseTx-HD
mii-tool -F 10baseT-HD
/etc/resolve.conf
17) Main configuration file and command used for exporting NFS directories and
it’s deamons
/etc/exports and exportfs -av , deamons are quotad, portmapper, mountd, nfsd
and nlockmgr/status
netstat -antp
22) Restricting insertion into file if full permission are assigned to all
chattr +i filename
23) Display or Kill all processes which are accessing any folder/file
killall -u username
25) How can we have daily system analysis and reports over mail
Use logwatch
26) How can we rotate logs using logrotate without performing any operation
like move and gzip’ng over original file and then creating new file (which is
very lengthy process)
We can use “logrotate”‘s “copytruncate” option which will simply copy original file
and truncate original file.
27) Command to collect detailed information about the hardware and setup of
your system
dmidecode , sysreport
Ans : lspci
Cron :
1) Minimum granularity is minute (i.e Jobs can be scheduled to be executed every
minute)
2) Cron job can be scheduled by any normal user ( if not restricted by super user )
Anacron :
2) Anacron can be used only by super user ( but there are workarounds to make it
usable by normal user )
5) Use anacron when a job has to be executed irrespective of hour and minute
30) Default Port numbers used by ssh, ftp, http, https, telnet, smtp, pop3,
pop3s, imap,imaps
SSH 22, ftp 20/21, http 80, https 443, SMTP/SMPTS 25/465, POP3/POP3S 110/995,
IMAP/IMAPS 143/993
Run test on device [TEST: offline short long conveyance select,M-N pending,N
afterselect,[on|off] scttempint,N[,p] : smartctl -t /dev/sda
or
SYN Flood : A SYN flood occurs when a host sends a flood of TCP/SYN packets,
often with a fake/forged sender address. Each of these packets is handled like a
connection request, causing the
because the sender address is forged, the response never comes. These half-open
connectionssaturate the number of available connections the server is able to
make, keeping it from responding tolegitimate requests until after the attack ends