Linux Q&a1
Linux Q&a1
Linux Q&a1
GNU GRUB is a Multiboot boot loader. It was derived from GRUB, the GRand Unified
Bootloader,
which was originally designed and implemented by Erich Stefan Boleyn.
Briefly, a 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
(such as the Hurd or Linux). The kernel, in turn, initializes the rest of the operating
system (e.g. GNU)
2) Explain Linux Boot Process
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
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 dont 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
didnt understand filesystem).
<span style="background-color
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/
1
2
3
4
5
6
7
8
9
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
0 halt
4 unused
5 X11
6 reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all
appropriate program.
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.
o
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
4) Which file needs to update if srequired to change default runlevel 5 to 3
File is /etc/inittab and required to change below lines:
id:5:initdefault: to id:3:initdefault:
5) What command used for showing user info like Login Name, Canonical
Name, Home Directory,Shell etc..
FINGER command can be used i.g; finger username
6) What is inode number
An inode is a data structure on a traditional Unix-style file system such as UFS or
ext3. An
inode stores basic information about a regular file, directory, or other file system
object
iNode number also called as index number, it consists following attributes:
File type (executable, block special etc)
Permissions (read, write etc)
Owner
Group
File Size
File access, change and modification time (remember UNIX or Linux never stores file
creation
time, this is favorite question asked in UNIX/Linux sys admin job interview)
File deletion time
Number of links (soft/hard)
Extended attribute such as append only or no one can delete file including root user
(immutability)
Access Control List (ACLs)
Following command will be used to show inodes of file and folders:
ls -i
Following command will show complete info about any file or folders with inode
number
stat file/folder
Files/Folders can also be deleted using inode numbers with following command:
find out the inode number using ls -il command then run below command
find . -inum inode_number -exec rm -i {} \;
7) How can we increase disk read performance in single command
blockdev command
This is sample output yours may be different.
# Before test
$ blockdev getra /dev/sdb
256
$ time dd if=/tmp/disk.iso of=/dev/null bs=256k
2549+1 records in
2549+1 records out
Ans lspci
29) What is the difference between cron and anacron
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 )
3) Cron expects system to be running 24 x 7. If a job is scheduled, and
system is down during that time, job is not executed
4) Ideal for servers
5) Use cron when a job has to be executed at a particular hour and minute
Anacron :
1) Minimum granularity is only in days
2) Anacron can be used only by super user ( but there are workarounds to
make it usable by normal user )
3) Anacron doesnt expect system to be running 24 x 7. If a job is scheduled,
and system is down during that time, it start the jobs when the system
comes back up.
4) Ideal for desktops and laptops
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
Use ssh-keygen -t dsa or rsa at local system for creating public and private
keys
Then copy /root/.ssh/id_dsa.pub to remote_server by name
/root/.ssh/authorized_keys
Change permissions of /root/.ssh/authorized_keys file at remote_server chmod
0600 ~/.ssh/authorized_keys
Now try to login from local system to remote_server ssh root@remote_server
39) Command to see default kernel image file
grubby default-kernel
40) How to create lvm mirror
lvcreate -L 50G -m1 -n LVMmirror vg0
41) Command to check last runlevel
who -r
42) What do you mean by File System?
File System is a method to store and organize files and directories on disk. A file
system can have different formats called file system types. These formats
determine how the information is stored as files and directories.
43) What is the requirement of udev daemon?
Create and remove device nodes or files in /dev/ directory
44) What are block and character devices?
Both the devices are present in /dev directory
Block device files talks to devices block by block [1 block at a time (1 block = 512
bytes to 32KB)].
Examples: USB disk, CDROM, Hard Disk (sda, sdb, sdc etc.)
Character device files talk to devices character by character.
Examples: Virtual terminals, terminals, serial modems, random numbers
(tty{0,1,2,3})
45) How to Convert ext2 to ext3 File System?
tune2fs -j /dev/{device-name}
46) File required to modify for setting up kernel parameters permanent
/etc/sysctl.conf
47) Commands used to install, list and remove modules from kernel
Installing/adding a module:
insmod mod_name
modprobe mod_name
List installed modules : lsmod
Removing a module
: modprobe -r mod_name
swap
swap
defaults
00
Deleting Swap :
Run swapoff /opt/myswap command
Remove the entry from /etc/fstab file
Remove /opt/myswap file (using rm command)
49) What vmstat show
vmstat (virtual memory statistics) is a computer system monitoring tool that
collects and displays summary information about operating system memory,
processes, interrupts, paging and block I/O
50) What is tmpfs File System
Reference : http://en.wikipedia.org/wiki/Tmpfs
tmpfs is a common name for a temporary file storage facility on many Unix-like
operating systems. It is intended to appear as a mounted file system, but stored in
volatile memory instead of a persistent storage device. A similar construction is a
RAM disk, which appears as a virtual disk drive and hosts a disk file system.
Everything stored in tmpfs is temporary in the sense that no files will be created on
the hard drive; however, swap space is used as backing store in case of low
memory situations. On reboot, everything in tmpfs will be lost.
The memory used by tmpfs grows and shrinks to accommodate the files it contains
and can be swapped out to swap space.
51) What is the difference between screen and script commands?
Screen is an screen manager with VT100/ANSI terminal emulation and used to take
GNU screen session remotely or locally and while Script make typescript of terminal
session
Screen : needs to be detached, should not be exited to access remotely/locally
Script : creates a file and store all the terminal output to this file
52) How can we check which process is assigned to which processor?
Ans Run ps -elFL and find out the PSR column which is showing the processor
number to the process
53) How can we check vendor, version, release date, size, package
information etc of any installed rpm?