Labels

hpunix (63) marathi kavita (52) linux (21) solaris11 (11) AWS (5) numerology (5)

Friday, March 24, 2017

Linux Query or Interview question - 9

Query 1. If you remove initrd or initramfs image or kernel from server what will happen?

Ans: If you remove initrd or initramfs image or kernel (vmlinuz) from running server then server will run in good condition till the reboot. Because the kernel or initrd image is present on memory (RAM). 

When we give reboot signal on server the kernel/initrd image will get loaded back to HDD via RAM. And after reboot while the server coming up, it (boot loader) will try to search kernel or iinitrd image to load on to RAM from HDD but it will not get so the server will not come up.

The kernel (vmlinuz) or initrd image is present under /boot directory or mountpoint.

[root@testmachine boot]# ls -lrt |egrep -i "initrd|vmlinuz"
-rwxr-xr-x. 1 root root  4128944 Nov 11  2013 vmlinuz-2.6.32-431.el6.x86_64
-rwxr-xr-x  1 root root  4223504 Aug 10  2015 vmlinuz-2.6.32-573.3.1.el6.x86_64
-rw-------  1 root root  5965847 Aug 17  2015 initrd-2.6.32-431.el6.x86_64kdump.img
-rw-------  1 root root  5953546 Oct  8  2015 initrd-2.6.32-573.3.1.el6.x86_64kdump.img

In older version we were having initrd (init ram disk) image and in newer version we have initramfs image. The main purpose of this file is to mount / partition in read only mode.

*************************************************************


Query 2: How to view initramfs image?

Ans: We can find the initramfs file under /boot partition.

[root@testmachine boot]# ls -lrt |grep -i initramfs
-rw-------. 1 root root 17551982 Jun 24  2015 initramfs-2.6.32-431.el6.x86_64.img
-rw-------  1 root root 28095966 Aug 17  2015 initramfs-2.6.32-573.3.1.el6.x86_64.img

In older version we were having initrd (init ram disk) image and in newer version we have initramfs (init ram filesystem) image. The main purpose of this file is to mount / partition in read only mode. After mounting the / partition, it calls /sbin/init program which is father of all processes in user space having PID=1 & start the system initialization.

[root@testmachine ~]# pidof init
1

We can view content of initramfs file by lsinitrd command.

[root@testmachine ~]# lsinitrd /boot/initramfs-2.6.32-573.3.1.el6.x86_64.img |more
Image: /boot/initramfs-2.6.32-573.3.1.el6.x86_64.img: 27M
========================================================================
dracut-004-388.el6
========================================================================
drwxr-xr-x  26 root     root            0 Aug 17  2015 .
drwxr-xr-x   2 root     root            0 Aug 17  2015 bin
lrwxrwxrwx   1 root     root            4 Aug 17  2015 bin/awk -> gawk
-rwxr-xr-x   1 root     root        23720 Aug 17  2015 bin/basename
-rwxr-xr-x   1 root     root       906152 Aug 17  2015 bin/bash
-rwxr-xr-x   1 root     root        45224 Aug 17  2015 bin/cat
-rwxr-xr-x   1 root     root       116824 Aug 17  2015 bin/cp
-rwxr-xr-x   1 root     root       109672 Aug 17  2015 bin/dash


Thanks & Regards,
Kirann Jadhav




Tuesday, March 21, 2017

Linux Query or Interview question - 8

Query 1. Why only 4 primary partitions can be created on HDD?

Ans: The MBR (Master Boot Record) contains boot information & partition table information. MBR is located in 1st sector of HDD or 0th cylinder of HDD. The size of MBR is 512 bytes in that 446 bytes is used for boot sector and 46 bytes is allocated for partition table. The remaining 2 bytes are nothing but magic number which shows “YES” or “NO” value.




 
MBR is a small program created by using Assembly language. MBR gets stored in HDD at the time of installation.  In layman language the MBR will be present only on that disk on which OS is installed.
The partition table is divided into different programs which manages particular partition.
1 program = 16 bytes = /dev/sda1 = manages 1st partition
2 program = 16 bytes = /dev/sda2 = manages 2nd partition
3 program = 16 bytes = /dev/sda1 = manages 3rd partition
4 program = 16 bytes = /dev/sda1 = manages 4th partition
So the partition table of size 64 bytes is divided into 4 programs of size 16 bytes each to manage the 4 primary partitions & that is the reason we can create only 4 primary partitions.


*************************************************************
Query 2: what is “SHUTDOWN PROCESS”?

Ans: Maximum interviewers ask you boot process to explain but sometime they may ask you to explain shutdown and reboot process/sequence.

Run below command for shutting down server.

[root@ testmachine ~]# poweroff
Or
[root@ testmachine ~]# shutdown –h now

Both commands calls #init 0 in background; the init0 run level is for halting the machine.

To get run level details refer post:

The init0 will call to /etc/rc scripts.

Process tree:
/etc/rc = script responsible for stopping or starting the services.
| --  check run level
| -- /etc/rc$.d/k* = all k=kill files from specific run level
| -- /etc/rc$.d/s* = all s=start files from specific run level
| -- /etc/rc.local = use this file, if you want to run any command or script before login

So now the /etc/rc will check runlevel and it finds the run level 0 so it will call /etc/rc0.d/ and will run all the k* related scripts present under this directory.

And will start two processes i.e S00killall – this process will start and kill if any pending process which is still running on server. After this, S01halt process will start and this process will send signal to BIOS to halt/poweroff/shutdown the machine.

[root@testmachine rc0.d]# ls -lrt |egrep -i "killall|halt"
lrwxrwxrwx  1 root root 14 Aug 17  2015 S01halt -> ../init.d/halt
lrwxrwxrwx  1 root root 17 Aug 17  2015 S00killall -> ../init.d/killall

*************************************************************
Query 3: what is “REBOOT PROCESS”?

Ans: For rebooting the server run below command:
[root@ testmachine ~]# reboot
Or
[root@ testmachine ~]# shutdown –r now

Both commands calls #init 6 in background; the init6 run level is for rebooting the machine.

The init6 will call to /etc/rc scripts.

So now the /etc/rc will check runlevel and it finds the run level 6 so it will call /etc/rc6.d/ and will run all the k* related scripts present under this directory.

And will start two processes i.e S00killall – this process will start and kill if any pending process which is still running on server. After this, S01reboot process will start and it will send signal to BIOS to reboot/restart the machine.

[root@testmachine rc6.d]# ls -lrt |egrep -i "killall|reboot"
lrwxrwxrwx  1 root root 14 Aug 17  2015 S01reboot -> ../init.d/halt
lrwxrwxrwx  1 root root 17 Aug 17  2015 S00killall -> ../init.d/killall

Note: The only difference is that, in shutdown process OS send halt signal (S01halt) from /etc/rc0.d to BIOS and in reboot process we send reboot signal (S01reboot) from /etc/rc6.d to BIOS.

Thanks & Regards,

Kiran Jadhav 

Friday, March 10, 2017

Linux Query or Interview question - 7

Query 1. Which output to take from server if doing any activity like patching, reboot, kernel upgrade?

Ans: If you are doing any activity on server, it is always better to have backup of important files, in IT term we call it as “pre activity output”. So in case of any issue happened on server then we will be able to resolve it by comparing the pre and post activity output.

You should take below output as pre-activity output, as there are chances that below files/parameters may get change after reboot.

a. #df –h = to see mounted FS details including NFS
b. #cat /etc/fstab = to see all FS details
c.  #cat /etc/hosts = all hosts entries added on server
d. #cat /etc/resolv.conf = to get nameserver details, FQDN etc..
e. #ifconfig –a = to get all IP information including binding IP, virtual IP etc.., MAC ID
f. #netstat –rn = to get routing information
g. #ntpq –p = ntp server information

[root@testmachine kijadhav]# df -h > pre_activity_op.`date +"%d%m%y"`
[root@testmachine kijadhav]# ls -lrt pre*
-rw-r--r-- 1 root root 845 Mar 10 09:15 pre_activity_op.100317
[root@testmachine kijadhav]# cat /etc/fstab >> pre_activity_op.100317
[root@testmachine kijadhav]# cat /etc/hosts >> pre_activity_op.100317
[root@testmachine kijadhav]# cat /etc/resolv.conf >> pre_activity_op.100317
[root@testmachine kijadhav]# ifconfig -a >> pre_activity_op.100317
[root@testmachine kijadhav]# netstat -rn >> pre_activity_op.100317
[root@testmachine kijadhav]# ntpq -p >> pre_activity_op.100317

Don’t save this output on server itself, incase server is not up then what will you see J So better mail this output to your outlook to keep it handy.

[root@ testmachine ~]# mail –a pre_activity_op.100317 –s “pre activity out_testmachine” kiran.jadhav@abc.com

Query 2: How to scan new Luns/disks by using for loop.

Ans: If we are having multiple hosts under /sys/class/scsi_host then we will run echo command for discovering luns/disks for multiple times. To avoid this just use for loop and by running one command you can scan all luns which are coming from different different hosts (host0, host1…..)

[root@ testmachine boot]# for i in `ls /sys/class/scsi_host`;do echo "- - -" > "/sys/class/scsi_host/$i/scan";done

Thanks & Regards,
Kiran Jadhav




Wednesday, March 8, 2017

Linux Query or Interview question - 6

Query 1. What is boot loader?

Ans: A boot loader is a small program which loads OS/kernel into memory (RAM). It is stored in the 1st sector of HDD i.e. MBR (Master Boot Record) partition table.
When your machine is powered-up or restarted, the BIOS perform some initial tests and then transfers control to the MBR where boot loader resides.

Note: The MBR contains boot loader information and the partition table information.

Without boot loader your OS will not be loaded in memory.

In Linux we use below two types of boot loader.
a.LILO – In older version
b. GRUB (GRand Unified Bootloader)

Grub configuration files and supported files are stored under /boot/grub/grub.conf and its symlink is /etc/grub.conf.
[root@ testmachine ~]# ls -l /etc/grub.conf
lrwxrwxrwx. 1 root root 22 Mar 26  2015 /etc/grub.conf -> ../boot/grub/grub.conf

You will see kernel information in your grub.conf file. The latest kernel in our case is “initrd /initramfs-2.6.32-573.3.1.el6.x86_64.img”
[root@ testmachine ~]# cat /etc/grub.conf|grep -i initrd
        initrd /initramfs-2.6.32-573.3.1.el6.x86_64.img
        initrd /initramfs-2.6.32-431.el6.x86_64.img


Query 2: What is load average cpu?

Load average shows the amount of traffic/load on your CPU in past 1, 5, 15 minutes. It is totally depend on how many CPU core you have in your machine.

If you are having 3 logical CPU in your machine and having load average value is less than 3 then your load average is OK means there is no processes in waiting or queued state in your CPU. 

1 CPU and 1 load average means there is 100% load on your CPU.

[root@ testmachine boot]# cat /proc/loadavg
2.54 1.73 1.53 3/368 25745

You can get CPU load average details from #top and #uptime command as well.

[root@ testmachine ~]# uptime
 14:49:34 up 455 days, 21:33,  5 users,  load average: 2.54, 1.73, 1.53

Thanks & Regards,

Kiran Jadhav 

Monday, March 6, 2017

Linux Query or Interview question - 5

Query 1. How to check run level of your system. Can we change runlevel and how?

Ans: A run level is a software program which tells your machine to run/process/allows defined group of processes. The default run level can be checked by below command:

[root@ testmachine ~]# who -r
         run-level 5  2015-12-08 16:39

Here we are having run level 5.

USe of runlevel:

#   0 - halt (Do NOT set initdefault to this); otherwise system will be in halt/power-down state permanently
#   1 - Single user mode - for administrative purpose
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this); otherwise system will keep on rebooting.

We can get default run level information from /etc/inittab as well.

[root@ testmachine ~]# grep initdefault /etc/inittab |grep -v reboot |grep -v halt
id:5:initdefault:

If we want keep default run level 3 means after reboot the system should come in run level 3 then edit /etc/inittab.

[root@ testmachine ~]# vi /etc/inittab
id:3:initdefault:

And then reboot the machine to re read the inittab file & see the changes.

[root@ testmachine ~]# reboot
Or
[root@ testmachine ~]# init 6

So if in your project, if someone ask you to reboot the machine then you can use either #reboot command or #init 6 command because

init 6 = reboot in /etc/inittab file

Or if someone asked you to halt/powerdown your machine then use below command:

[root@ testmachine ~]# init 0

Note: Please take necessary output (like #ifconfig –a, /etc/hosts etc..) before rebooting/halting machine. 

I will cover this point in next post J

Query 2. Is root account is main administrator account?

Ans: This kind of tricky question interviewer may ask you. The answer is “No”. root is not the main administrator.

The user who is having UID=0 will be your admin user.

By default, root has UID=0 which we can change and can assign different or any UID to him.

We can create user kiran with UID=0 and then user kiran will act as admin user.
[root@ testmachine ~]# grep root /etc/passwd
kiran:x:0:0:root:/kiran:/bin/bash


Thanks & Regards,
Kiran Jadhav 

Friday, March 3, 2017

Linux Query or Interview question - 4

Query 1. Why we put ‘- - -‘ in echo command which we use for scanning the lun.

Ans: We use below command to scan the new luns/disks.

[root@ testmachine~]# cd /sys/class/scsi_host/
[root@ testmachine scsi_host]# ls
host0  host1  host2
[root@ testmachine scsi_host]# echo “- - -“ > /sys/class/scsi_host/host0/scan
[root@ testmachine scsi_host]# echo “- - -“ > /sys/class/scsi_host/host1/scan
[root@ testmachine scsi_host]# echo “- - -“ > /sys/class/scsi_host/host2/scan

“- - -“ means we are echoing wild card entries of “Channel, SCSI targe ID & LUN” respectively and scanning it. So the OS will scan the device path connected to that particular host.

If the Luns are coming from HBA (fiber channel) then the echo command will slightly get differ.
[root@ testmachine~]# cd /sys/class/fc_host/
[root@ testmachine scsi_host]# ls
host0  host1 
[root@ testmachine fc_host]# echo “- - -“ > /sys/class/fc_host/host0/scan
[root@ testmachine fc_host]# echo “- - -“ > /sys/class/fc_host/host1/scan

After scanning of luns, if you still unable to see them then use below command.

[root@ testmachine fc_host]# echo 1 > /sys/class/fc_host/host/issue_lip

issue_lip refreshes the scsi bus (fiber channel interconnect).

Query 2. How to indentify CPU & core information.

1.a. Run lscpu command.
Socket =1 shows we have 1 CPU socket, nothing but 1 CPU
Core per socket = 4 shows that we are having 4 core in 1 socket.
Thread per core = 2 shows multithreading is there

CPU 8 = show logical cpu. We are having 8 logical CPU. (1*4*2 = 8)

[root@ testmachine:/root]lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1

1.b.To see CPU which are online in extended readable format.

[root@ testmachine:/root]lscpu -b -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
0   0    0      0    0:0:0:0       yes
1   0    0      1    1:1:1:0       yes
2   0    0      2    2:2:2:0       yes
3   0    0      3    3:3:3:0       yes
4   0    0      0    0:0:0:0       yes
5   0    0      1    1:1:1:0       yes
6   0    0      2    2:2:2:0       yes
7   0    0      3    3:3:3:0       yes

2.In /proc/cpuinfo, the “Physical ID” shows number of CPU’s. 
In our case,
Physical id = 0 means we are having   only 1 CPU.

[root@ testmachine:/root]grep -i "physical id" /proc/cpuinfo
physical id     : 0
physical id     : 0
physical id     : 0
physical id     : 0
physical id     : 0
physical id     : 0
physical id     : 0
physical id     : 0


Thanks & Regards,
Kirann Jadhav




Thursday, March 2, 2017

Linux Query or Interview question - 3

Query 1. What is primary partitions on HDD.

We can create only 4 partition on HDD called as "Primary Partition" or "Physical Partition" & it is defined in partition table. 
There are two type of partition table.
a. MSDOS/MBR – Where limit is set as 4 for primary partitions
b. GPT – Where you can create 128 primary partitions

so the limit of creation of primary partitions is set in partition table type.
[root@testmachine ~]# parted -l /dev/sda
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   21.5GB  20.9GB  primary               lvm
 3      21.5GB  31.1GB  9665MB  primary

In our example, we are having 3 partitions like /dev/sda1, /dev/sda2, /dev/sda3 etc.  

 [root@testmachine ~]# fdisk /dev/sda
Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       20480    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/sda3           20481       29697     9438208   83  Linux

If we want to create more than 4 partitions then we have to make 1 partition as extended out of 4 partitions. The use of extended partition is that it will create a boundary for extended and in that we can create multiple logical partitions.

Take example that our 4th partition is extended partition. Then /dev/sda4 will be used for that but it is just for name sake. It will not have data. The exact logical partition will start form /dev/sda5, /dev/sda7 etc…

If we want to create primary partition more than 4 then we have to use partition table type GPT where we can create 128 primary partitions.

We can change the partition table type from MSDOS to GPT by using “parted” command. Better to have a backup so data loss may not happen.


Query 2. Why we see HDD size less in OS.

The HDD manufacturers (like IBM, EMC, Dell, HP etc..) use the universal method of calculation . They divide the disk size by 1000.

Like 1GB= 1000MB

But in OS we divide the disk size by 1024. So the disk size is actually same but we may see less disk size when we use it in OS (Linux, windows etc..)

5GB = 5000MB (as per manufacturer)
5000MB/1024 = 4.88GB so in OS you will see disk size 4.88GB.


Thanks & Regards,
Kiran Jadhav