Sunday, April 27, 2014

Become a Master Linux

LINUX Interview Questions
Hi Friends...i planned to update interview questions and answers for LINUX admins. Hope this will help you to refresh your knowledge at the time of interview preparation.
Few points before start,

1.Be Clear and Frank while prepare resume. Since mostly question will be asked based on Ur resume.
2. Try to focus more about Ur day to day job in resume.
3. Make sure you are clear in basic Linux such as booting, LVM, Architecture, server model which you worked.
4. Before give interview write down your day to day work, server model information, and your current environment details and review yourself.
5. Don’t prepare up to last minute it will spoil your mood and confidence.
6. Once interview over note down the Question which they asked. It will help for next interview.

For L1 & L2 Admin Interview:


Maximum the Question will be on below area

1.Booting procedure of linux server
2.user administration
3.LVM -FS creation/ extend / FS issues & recover
4.Software install / remove / update - RPM or YUM 
5.Basic services config /troubleshoot - E.G : NFS ,FTP , SAMBA , DNS , DHCP 
6.Utilization issues - CPU , MEMORY , DISK 
7.Hardware errors and troubleshoot
8.PAtch installation / roll back


Ok Now we can start look into questions and answers 


Question 1: Explain Booting procedure or steps in Linux?


1. Once System powered on, it automatically invokes BIOS 

2. BIOS will start the processor and perform a POST [power on self test] to check the connected device are ready to use and are working properly.

3. After POST ,  BIOS will check for the booting device. The boot sector is always the first sector of the hard disk and BIOS will load the MBR into the memory. 
   MBR holds the boot loader of the OS.

4. Then boot loader takes the control of the booting process.

5. GRUB is the boot loader for Linux. 

6. Depending on the boot option selected the kernel is loaded first.

7. After kernel is loaded the kernel will take the control of the booting process

8. Initrd will be loaded which contains drivers to detect hardware (its called Initialization of RAM Disk)

9. Then it will initialize all the hardware including I/O processors etc.

10. Kernel will mounts the root partition as read-only

11. INIT is loaded as the first process.

12. INIT will mount the root partition and other partitions as read/write and checks for file system errors.

13. Sets the System Clock, hostname etc..

14. Based on the Runlevel, it will load the services and runs the startup scripts which are located in /etc/rcX.d/ (Network, nfs, SSH etc.)

15. Finally it runs the rc.local script & Now the login prompt will appear.



Question 2: What is stage 1.5 boot loaded in linux?


The great thing about GRUB is that it includes knowledge of Linux file systems. Instead of using raw sectors on the disk, as LILO does, 
GRUB can load a Linux kernel from an ext2 or ext3 file system. It does this by making the two-stage boot loader into a three-stage boot loader.

A. Stage 1.5 boot loader , it contains extra coe to allow cylinders above 1024, or LBA type drives, to be read.
B. It will be stored on MBR or Boot partition .
C. Stage 1 (MBR) boots a stage 1.5 boot loader that understands the particular file system containing the Linux kernel image.
D. Basically this module will load the knowledge of Filesystem to Grub to read the kernel

so ,

Stage 1 Boot loaded is : MBR
Stage 1.5 Boo loader : e2fs_stage1_5 
Stage 2 Boot loader is  : GRUB

   

Question 3:  How to reinstall GRUB?


A.Boot up using RHEL4 disk.

B.Enter into rescue mode

 #linux rescue  (hit ok)

C. Then follow below commands

 # chroot /mnt/sysimage

 # grub
  
 # find /boot/grub/stage1 or find /grub/stage1

    root(hd0,0) //example o/p

Now install the GRUB

 # setup (hd0) 

 # EXIT 

Another Method

 #linux rescue

 # chroot /mnt/sysimage

 # /sbin/grub-install /dev/hda  



Question 4:  Linux Booting Issues : How to solve ??


Option 1: init not found error
Option 2: Run fsck on all FS in rescue mode
Option 3: Reinstall GRUB
Option 4: Recover grub.conf / grub configuration

Option 1: For normal panic and "init not found" error.

Error : "init not found" displayed

1) Launch the system to Bash shell prompt 

Reboot the server and interrupt to edit the GRUB.

Edit grub and enter the below in last 

init=/bin/bash 

Then save and exit and boot the server. This will launch you straight into a Bash shell prompt.Then you can remount “/” file system and check /var/log/messages for any error.

Note :  init=/bin/bash (Grub boot loader) or linux init=/bin/bash (if Lilo boot loader). 

2) Once server booted and if it is in Bash shell prompt 

 #mount -o remount,rw /

3) Now  you can check the log messages and try to find the reason for server pacnic or error.

#more /var/log/messages


Option 2:  If the above option not helped then follow the next

1) Boot from the Linux First CD (boot CD).

2) Type “boot rescue” at Linux boot prompt.

3) After the bash shell prompt show up, type the below command 

   # chroot /mnt/sysimage

a) Run fsck and Check for any disk error

  #fdisk -l /dev/sda  //check how many partion you have 

   then run fsck on each partition
     
  #fsck -y /dev/sda2'

Option 3: If the above also not helped then reinstall grub and retry.

 In rescue mode.

   #  chroot /mnt/sysimage

   # /sbin/grub-install /dev/hda





Option 4: If a system has issues with the GRUB configuration 


(possibly caused by incorrect changes to the the GRUB configuration file, installation of another OS, changes to device ordering due to hardware or BIOS changes, etc.) 

   # grub> find /boot/grub/grub.conf (or) grub>find /grub/grub.conf  (or) find /boot/grub/stage1
    (hd0,1)
    (hd1,2)

    >> This tells us that we have two /boot partitions. Then we have to reinstall the GRUB config on disk (one by one) and try.

   #grub> root (hd0,1)    //Write the GRUB bootloader on the MBR of the first disk
    grub> setup (hd0)
    grub>quit

  If you have doubt as to where the root partition is located then try to find a file in /etc. 
  
    #grub> find /etc/fstab
      (hd0,1)


Note: You must pay attention to your devices, for me "hd0" is the root disk and (hd0,1) is /boot partition , and (hd0,1) is my ROOT (/) partition. mostly / "root" partion will be on LVM.
       You might not even have "hd0" mapped out. Review your "/boot/grub/device.map" file

      #cat /boot/grub/device.map




Question 5 :  How to recover or rest Root password in LINUX?


While booting 

   

   1. Select the kernel
   2. Press the "e" key to edit the entry
   3. Select second line (the line starting with the word kernel)
   4. Press the "e" key to edit kernel entry so that you can append single user mode
   5. Append the letter "S" (or word Single) to the end of the (kernel) line
   6. Press ENTER key
   7. Now press the b key to boot the Linux kernel into single user mode
   8. At prompt type passwd command to reset password:

You need to mount at least / and other partitions:
# mount -t proc proc /proc
# mount -o remount,rw /

Change the root password,

# passwd

thenreboot system:
# sync
# reboot




Question 6: What is super Block and how will u recover it ?


The blocks used for two different purpose:

   1. Most blocks stores user data aka files (user data).
   2. Some blocks in every file system store the file system's metadata. 


So what the hell is a metadata?

    File system type
    Size
    Status
    Information about other metadata structures


To find super block

#dumpe2fs /dev/sda3|grep -i superblock

or 

# mke2fs -n /dev/sda3



To repair file system by alternative-superblock use command as follows:

# e2fsck -f -b 8193 /dev/sda3

Question 7:  What is hard link and soft link? How to create symbolic link?

     

A.  Hard links cannot link directories.
    Cannot cross file system boundaries.

B.  Soft or symbolic links are just like hard links. It allows to associate multiple filenames with a single file. However, symbolic links allows:

    To create links between directories.
    Can cross file system boundaries.



How do I create symbolic link?

You can create symbolic link with ln command:

#ln -s /path/to/file1.txt /path/to/file2.txt

(inode number will be same for hard linked file )

#ln /mades/file1 /mades/file2 - ( create hard link)


Question 8: What is INODE ? How to reduce inode utilization?


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.

=> 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)


How to reduce inode usage in File system?


For examble /opt filesystem's inode usage is high means we have to do below steps

# bdf -i /opt : check the FS usage

Create a test directory on your filesystem;

# mkdir /opt/test

Create a script that will create 10000 null files.

# cd /opt/test
# i=1
# while [ $i -lt 10000 ]
> do
> touch $i
> i=`expr $i + 1`
> done

Else you will be watching the terminal for years to get you the prompt or else CTRL + C will do :-D

once files are created do

#bdf -i /opt

Question 9 : What is HARD and SOFT mount in NFS ?



In HARD mount ...

If the NFS file system is hard mounted, the NFS daemons will try repeatedly to contact the server. The NFS daemon retries will not time out, will affect system performance, and you cannot interrupt them

If you just mount a file system without specifying hard or soft, the default is a hard mount. Hard mounts are preferable because of the stateless nature of NFS.

If a client sends an I/O request to the server (such as an ls -la), and the server gets rebooted, in client machine the process will keep on running.
This preserves data transfers in the event of a server failure

IN SOFT Mount :

A soft mount allows the client to stop trying an operation after a period of time. If the NFS server goes down at the time of data transfer , it will alert and the process will do down.Thsi may cause the data corruption.
A soft link will return with an error and fail.

you should only use soft mounts in the cases where client responsiveness is more important than data integrity.

In another word ..soft mount will allow automatic unmount if the filesystem is idle for a specified time period 


Question 10 : Explain NFS mount options ?


Syntax to mount NFS FS:

#mount -t vfstype [-o options] NFS Servername:/exporteddirectory /mount point

or

#mount -t nfs -o options host:/remote/export /local/directory



Mount options explained below :

1. -0 initr

This option is used in non reliable network, or network having more network congestion. NFS request will be interrupted when server is not reachable.

2. -o hard 

If hard option is specified during nfs mount, user cannot terminate the process waiting for NFS communication to resume. For ex ..if u ran ls -a command on ur NFS mounted directory but that time ur NFS server went down means .
The process wont get killed or stopped ..it will wait until the NFS server and mount poit become available.

3. -o soft 

If soft option is specified during nfs mount, user will get error alert when NFS server is not reachable. This is just inverse of hard mount option. It wont wait for reply if the NFS server went down , it will alert us and the process will go down.

4. -o Nfsvers=value

If this option is specified during nfs mount NFS client uses particular NFS protocol version to communicate. 

For example - TCP 

# mount -t nfs -o tcp 192.168.1.4:/mnt/array1/RHEL5 /data/
# mount | grep -i tcp
 192.168.1.4:/mnt/array1/RHEL5 on /data type nfs (rw,tcp,addr=192.168.1.4)

The Difference between HARD and SOFT mount option explained in another POST. 




Question 11:  Explain TOP command output / Various states of CPU


# us -> User CPU time: The time the CPU has spent running users’ processes that are not niced.
# sy -> System CPU time: The time the CPU has spent running the kernel and its processes.
# ni -> Nice CPU time: The time the CPU has spent running users’ process that have been niced.
# wa -> iowait: Amount of time the CPU has been waiting for I/O to complete.
# hi -> Hardware IRQ: The amount of time the CPU has been servicing hardware interrupts.
# si -> Software Interrupts.: The amount of time the CPU has been servicing software interrupts


Question 12: How to check architecture of Linux OS


We can use below commands to check the architecture of server OS,


1. #getconf LONG_BIT

2.#uname -a

3.#grep flags /proc/cpuinfo

4.#arch

5.#file /bin or file bc

13. What is swap ? Why we need swap partition?


Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, 
inactive pages in memory are moved to the swap space.

Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.

Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB. 



14. How to Create / extend / remove swap partition?


A.Create a SWAP Partition:

1. Create a file system on disk

#fdisk /dev/cciss/c?d?

Note : Make the new partition as swap. Change toggle id to 82 (for swap).


2. Make the FS as Swap partition

#mkswap /dev/cciss/c?d?p?


3. Run swapon commad to enable swap space

#swapon /dev/cciss/c?d?p?


4.Verify the new swap partition

    #cat /proc/swap

    or

    #swapon -s

5. Add this new swap partion entry to /etc/fstab

vi /etc/fstab

/dev/cciss/c?d?p? swap swap defaults 0 0



B.How to increase / extend SWAP partition ?

Follow the below steps to increase the Swap for LVM

    # swapoff -v /dev/rootvg/swapvol
    # lvm lvresize /dev/rootvg/swapvol -L +8G  or lvextend -L +8G /dev/rootvg/swapvol
    # mkswap /dev/rootvg/swapvol
    # swapon -va


C.How to remove the swap partition ?

1.swapoff -v /dev/VolGroup00/swap_vol

2.lvremove /dev/VolGroup00/swap_vol

3. Remove the entry from /etc/fstab



15. Why does kernel need IO scheduler?



Without an I/O scheduler, the kernel would basically just issue each request to disk in the order that it received them. This could result in massive HardDisk 
thrashing: if one process was reading from one part of the disk, and one writing to another, the heads would have to seek back and forth across the disk for 
every operation. The scheduler’s main goal is to optimise disk access times.


16. How to view Current Disk i/o scheduler ? How to change I/o Scheduler for hard disk?


Assuming that we have a disk name /dev/sda, type :

# cat /sys/block/{DEVICE-NAME}/queue/scheduler
# cat /sys/block/sda/queue/scheduler



How to set I/O Scheduler For A Hard Disk ?

To set a specific scheduler, simply type the command as follows:

# echo {SCHEDULER-NAME} > /sys/block/{DEVICE-NAME}/queue/scheduler
For example, set noop scheduler, enter:
# echo noop > /sys/block/hda/queue/scheduler

OR

Edit /boot/grub/grub.conf and enter in kernel line "elevator=noop" or any other scheduler available.

There are currently 4 available IO schedulers :

* No-op Scheduler
* Anticipatory IO Scheduler (AS)
* Deadline Scheduler
* Complete Fair Queueing Scheduler (CFQ)


Changing Scheduler:

The most reliable way to change schedulers is to set the kernel option “elevator” at boot time. You can set it to one of “as”, “cfq”, “deadline” or “noop”, to set the appropriate scheduler. 

elevator=cfq


17. How to restore the default system permission on  Linux ?


We can recover or restore the defualt file / folder permission and ownership using rpm command with the options -setperms and --setugids.  
This is very usefull option which i found in RPM command.

1) To reset uids and gids on files and directories :

 # for i in $(rpm -qa); do rpm --setugids $i; done


2) To permissions on files and directories

 #for i in $(rpm -qa); do rpm --setperms $i; done

1.What are Daemons ??

Daemons are services that provide several functions that may not be available under the base operating system. 

Its main task is to listen for service request and at the same time to act on these requests. After the service is done, 
it is then disconnected and waits for further requests.

2.What are environmental variables?


Environmental variables are global settings that control the shell’s function as well as that of other Linux programs. 

Another common term for environmental variables is global shell variables

3.What are the different modes when using vi editor?


There are 3 modes under vi:
- Command mode – this is the mode where you start in
- Edit mode – this is the mode that allows you to do text editing
- Ex mode – this is the mode wherein you interact with vi with instructions to process a file
4.How can we change speed and make full duplex settings for eth0

Ans We can do this with below given 2 methods:


ethtool -s eth0 speed 100 duplex full

ethtool -s eth0 speed 10 duplex half

OR


mii-tool -F 100baseTx-HD

mii-tool -F 10baseT-HD


5.What are the process states in Unix?


As a process executes it changes state according to its circumstances. Unix processes have the following states:

Running : The process is either running or it is ready to run .

Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.


6.Explain /proc filesystem?


/proc is a virtual filesystem that provides detailed information about Linux kernel, hardware’s and running processes. Files under /proc directory named as Virtual files. 
Because /proc contains virtual files that’s why it is called virtual file system. These virtual files have unique qualities. 

Most of them are listed as zero bytes in size. Virtual files such as /proc/interrupts, /proc/meminfo, /proc/mounts, and /proc/partitions provide an up-to-the-moment glimpse of the system's hardware. Others, like the /proc/filesystems file and the /proc/sys/ directory provide system configuration information and interfaces.



7.What is the difference between hardware RAID and Software RAID?


The hardware-based RAID is independent from the host. A Hardware RAID device connects to the SCSI controller and presents the RAID arrays as a single SCSI drive. 

An external RAID system moves all RAID handling "intelligence" into a controller located in the external disk subsystem. The whole subsystem is connected to the host via a normal SCSI controller and appears to the host as a single disk.


Software RAID is implemented under OS Kernel level. The Linux kernel contains an MD driver that allows the RAID solution to be completely hardware independent.


 The performance of a software-based array depends on the server CPU performance and load.


8.What is the difference between cron and anacron


Ans  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 doesn’t 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


9.What is CUPS?


CUPS stands for "Common UNIX Printing System". CUPS is a open source printing system developed by Apple Inc. CUPS uses the Internet Printing Protocol (IPP) to allow local printing and print sharing.
The log files for the CUPS printing system are located in the /var/log/cups/ directory.

10.How Many Run Levels present in Linux?


There are 7 run levels, with each having its own properties.
- 0: Halt the system
- 1: Single-user mode 
- 2: Not used
- 3: Multi-user mode with text login
- 4: Not used
- 5: Multi-user mode with graphical login
- 6: Reboot

How to view UUID values and print block device attributes in linux?



Option 1 : Using blkid command

Option 2 : Using dumbe2fs command
Option 3: using  #ls -l /dev/disk/by-uuid



To view UUID values and block device attributes:



[root@serverA ~]# blkid

/dev/cciss/c0d0p1: LABEL="/boot" UUID="0e811819-43e9-44dc-b63d-2fb8f74a9793" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-0: UUID="1607f7e2-330f-49cc-bbbb-56dbc7153bd9" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-1: UUID="605c8097-e59f-4f42-a63f-4668d457a9b2" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-2: UUID="9c6abcac-dbc8-4512-a36f-98fad866032d" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-3: UUID="ff42077e-1b86-423b-948c-c69b98b404da" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-4: UUID="51ed13d1-e0ea-430b-8dc4-a30ffdd3ca22" SEC_TYPE="ext3" TYPE="ext2"
/dev/dm-5: TYPE="swap" UUID="32e63d41-d037-49c0-9864-654d968e4436"
/dev/dm-6: UUID="4014b540-6809-4d72-aa30-588031e5c37c" TYPE="swap"
/dev/dm-7: UUID="de51f7a8-7dca-4551-b02b-8f6123349085" SEC_TYPE="ext3" TYPE="ext2"




Gather information about I/O limits:



[root@serverA ~]# blkid -i /dev/sda1

MINIMUM_IO_SIZE=70825883316781568
PHYSICAL_SECTOR_SIZE=70825883316781568
LOGICAL_SECTOR_SIZE=51169347011346944


Option2: dumpe2fs command


[root@serverA ~]# dumpe2fs  /dev/sda3 | grep UUID

dumpe2fs 1.41.12 (17-May-2010)
Filesystem UUID:          7b84a8a0-08cb-48f0-9d80-a0d2a52990d9

OR


Option 3 : ls -l /dev/disk/by-uuid/


[root@serverA ~]# ls -l /dev/disk/by-uuid/

total 0
lrwxrwxrwx 1 root root 10 Jul 18 19:42 54BC9BC5BC9B9FD2 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 18 19:41 7b84a8a0-08cb-48f0-9d80-a0d2a52990d9 -> ../../sda3
lrwxrwxrwx 1 root root 10 Jul 18 19:41 a5808574-4c35-4f13-86ae-706668ac3e3b -> ../../dm-1
lrwxrwxrwx 1 root root 10 Jul 18 19:42 E0987DB6987D8BB2 -> ../../sda5
lrwxrwxrwx 1 root root 10 Jul 18 19:41 f29e8378-5850-47ad-b02f-803e928abff4 -> ../../dm-0

UMASK  : Permission Set When New File / Folder Created


UMASK known as User Mask or it is also called User File creation MASK. This is a kind of base permission or default permission given when new file or folder is created in Linux box. Most of the distribution of Linux gives 022 as default UMASK.

So 022 is the default permission for files and folders

while create any file or directory in Linux, they are governed by umask setting. In case, any system administrator does not set the default umask will be 0000. This means that the new files created will have read and write permissions for each user and new directories will have read, write and execute permissions. 

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNirWiBmPxurQ6ZGuzhxaUT0QLqiAPKlIb4At2Y5YB4u5N7p-L68QOljnpSTr3zxUx_TNq7qclADuRgMAiBeJu_yVDjrt3exUXZYe_syvPES1XsOFIev42C1dVyEVFWydYHG6wgfWdRtJf/s1600/umask.jpg



How can we calculate UMASK in Linux?

One thing is umask value is generally same for files and folders but the calculation of these values based on the permissions on files and directories are different.


Minimum UMASK value for directory : 000 and Maximum : 777
Minimum UMASK value for file: 000 and Maximum : 666


Reason of keeping maximum value 666 for files is because script files and binary files in Linux should only have execute permissions. Normal files in Linux should only have read and write permissions. Normally, umask are calculated through bitwise AND operator. Some of the common octal notations are:


0 – Read, Write and Execute
1 – Read and Write
2 – Read and Execute
3 – Read Only
4 –Write and Execute
5 –Write Only
6 –Execute Only
7 –No Permissions


Now, we can easily make use of the above mentioned table to calculate permission for files. For instance, if an umask is set to 077 means the permission is generally calculated as below:

Bit
Targeted at
File permission
0
Owner
read, write and execute
7
Group
No permissions
7
Others
No permissions


To set the above umask, you should type the command

$ umask 077
$ mkdir folder3
$ touch testfile3
$ ls –ld folder3  testfile3


Output:
drwx—— 2 demo demo 4096 2013-07-04 01:34 folder3
-rw——- 2 demo demo 0 2013-07-04 01:34 testfile3


Display current umask value

If you run umask command without any argument it will display the current mask value.

$ umask
0022


How can we set umask with Symbolic Values?

Below mentioned are the symbolic values we can use:
r: read, w: write, x: execute, u: user ownership, g: group ownership and o: other ownership

Example
$ umask u=rwx, g=, o=
$ mkdir folder1
$ touch testfile
$ ls –ld folder1 testfile

 

Procedure To Setup Default umask


You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:



# vi /etc/profile
OR
$ vi ~/.bashrc
Append/modify following line to setup a new umask:
umask 022

Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, 

~/.profile (Korn / Bourne shell) 
~/.cshrc file (C shells), 
~/.bash_profile (Bash shell)
 or 
~/.login file (defines the user's environment at login).

umask and level of security:

The umask command be used for setting different security levels as follows:


umask value
Security level
Effective permission (directory)
022
Permissive
755
026
Moderate
751
027
Moderate
750
077
Severe
700

What are the Limitations of umask?



1.    The umask command can restricts permissions.
2.    The umask command cannot grant extra permissions beyond what is specified by the program that creates the file or directory. If you need to make permission changes to existing file use the chmod command.

 

What is semaphore ?(This question asked accenture )


Semaphore can be described as counters used to control access to shared resources by multiple processes, They are most often used as a locking mechanism to prevent processes from accessing a particular resource while another process is performing operations on it.

Semaphore can be used when number of processes try to access the shared resource or same file,Semaphore stored in kernel, so that it can be accessed by all the processes,

·          Semaphore can be identified unique id in linux kernel and it can be deleted using semdelete function,
·         semaphore values can be incremented or decremented by using functions wait and signal,   
·         If we are using ONFS (Oracle over network file system) in linux, we need to increase the kernel.sem value to improve system performance

How to Increase semaphore value in linux?

To increase semaphore value we need to increase the value of kernel.sem.

[root@server ~]# sysctl -A | grep kernel.sem

kernel.sem = 250        32000   32      128

[root@server ~]# ipcs -ls


------ Semaphore Limits --------

max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

Increase semop value from 32 to 100, it can be increased upto 250 which is equal to semaphores per array,


Add the following line into /etc/sysctl.conf file,


#vi /etc/sysctl.conf


kernel.sem = 250 32000 100 128

or 


#sysctl -w "kernel.sem = 250 32000 100 128"


or

#sysctl -w "kernel.sem=4096 512000 1600 2048" 

   

kernel.sem: max_sem_per_id max_sem_total max_ops_sem_call max_sem_ids


Now we have modified the kernel.sem value,


Please run the following command to update the changes 


[root@server ~]# sysctl -p


Now semaphore value got changed on server.you can verify using ipcs command.

Linux LVM Interview Questions (This is mandatory question for every company) 1.What are LVM1 and LVM2?

LVM1 and LVM2 are the versions of LVM. 

LVM2 uses device mapper driver contained in 2.6 kernel version.
LVM 1 was included in the 2.4 series kernels.

2.What is the maximum size of a single LV?

For 2.4 based kernels, the maximum LV size is 2TB. 

For 32-bit CPUs on 2.6 kernels, the maximum LV size is 16TB.
For 64-bit CPUs on 2.6 kernels, the maximum LV size is 8EB. 

3.List of important LVM related files and Directories?

## Directories

/etc/lvm                - default lvm directory location
/etc/lvm/backup         - where the automatic backups go
/etc/lvm/cache          - persistent filter cache
/etc/lvm/archive        - where automatic archives go after a volume group change
/var/lock/lvm             - lock files to prevent metadata corruption

# Files

/etc/lvm/lvm.conf       - main lvm configuration file
$HOME/.lvm              - lvm history 


4.What is the steps to create LVM in Linux?

Create a physical volume by using pvcreate command


consider the disk is local.


#fdisk -l 


#fdisk /dev/sda


Press "n" to create new partition. And mention the size / allocate whole disk to single partition. and assign the partition number also.


#press "t" to change the partition as LVM partition. 


#enter "8e" ( 8e - is Hex decimal code for LVM ) 


#Enter "w" to write tghe information on Disk.


#fdisk -l ( Now you will get newly created disk numbers)


#pvcreate /dev/sda2


Add physical volume to volume group by “vgcreate” command


#vgcreate VLG0 /dev/sda2


Create logical volume from volume group by “lvcreate” command.


#lvcreate -L 1G -n LVM1 VG0


Now create file system on /dev/sda2 partition by “mke2fs”  or "mkfs.ext3" command.


#mke2fs -j /dev/VG0/LVM1


or 


#mkfs.ext3 /dev/vg0/LVM1


How to mount this as file system


#mkdir /test


#mount /dev/VG0/LVM1 /test  


5.How to extend a File system in Linux?

Check the free space on vg 


#vgdisplay -v VG1


Now extend the FS


# lvextend -L+1G /dev/VG1/lvol1


# resize2fs /dev/VG1/lvol1


6.How to reduce the File system size  in Linux?

1.First we need to reduce the file system size using "resize2fs"

2.Then reduce the lvol size using "lvreduce"

#resize2fs -f /dev/VolGroup00/LogVol00 3G


#lvreduce -L 5G /dev/VG1/Lvol1

Logical Volume in LVM: Interview Questions


Display:

#lvdisplay -v lvname

#lvs

To view mirror volumes

#lvs -a -o +devices
#lvs -a -o +seg_pe_ranges --segments

lvs attributes are:

1. volume type: (m)irrored, (M)irrored without initail sync, (o)rigin, (p)vmove, (s)napshot, invalid (S)napshot, (v)irtual, mirror (i)mage
                      mirror (I)mage out-of-sync, under (c)onversion
2. permissions: (w)rite, (r)ead-only
3. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
4. fixed (m)inor
5. state: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid (S)uspended snapshot, mapped (d)evice present with-out tables,
             mapped device present with (i)nactive table
6. device (o)pen (mounted in other words) 

Scan: 

#lvscan -v
#lvmdiskscan




Create / Extend / Reduce / Remove:

Create a Lvol

#lvcreate -L 10M -n lvol1 VGNAME  // To create plain lvol

#lvcreate -i 3 -I 32 -L 24M -n lvol1 vg01  //To create striped lvol

#lvcreate -L 10M -m1 -n lvol1 vg01  // To Create mirror lvol

Extend a Lvol 

#lvextend -L 20M /dev/VolData00/lvol01 

#fsadm resize /dev/VolData01/data01
#resize2fs -p /dev/mapper/VolData01-data01 [size] 

Reduce Lvol

#lvreduce -L 5M /dev/VolData00/lvol01 (or)
#lvresize -L 5M /dev/VolData00/lvol01

#fsadm resize /dev/VolData01/data01 [size]
#resize2fs -p /dev/mapper/VolData01-data01 [size] 


Rename / Snapshot / change attribute 


# lvrename /dev/VolData00/vol_old /dev/VolData00/vol_new    //Rename

# lvcreate --size 100M --snapshot -name snap /dev/vg01/data01    //Snapshot

#lvchange -a n /dev/VolData00/vol01   //Changing attribute

VG Related command tips in Linux


This post will help you to keep remember Volume Group - VG related commands in Linux at the time of interview Preparation. 

Display Volume Group


vgdisplay -v
vgs -v
vgs -a -o +devices

vgs flags:


#PV - number of physical devices
#LV - number of configured volumes        

vgs attributes are:
1. permissions (r)|(w)
2. resi(z)eable
3. e(x)ported
4. (p)artial
5. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
6. (c)luster 

Create VG : 


vgcreate VolData00 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgcreate VolData00 /dev/sdb[123]

## Use 32MB extent size

# vgcreate VGName -s 32 /dev/sdb1

Common Attributes that you may want to use:

-l  maximum logical volumes
-p maximum physical volumes
-s physical extent size (default is 4MB)
-A autobackup 


Extend / Reduce / Remove  Volume Group :

vgextend VGName /dev/sdb3 

vgreduce VGName /dev/sdb3

vgreduce --removemissing --force VolData00 

vgremove VGName

Change in VG : 


vgchange -a n VolData00

Common Attributes that you may want to use:

-a control availability of volumes within the group
-l  maximum logical volumes
-p maximum physical volumes
-s physical extent size (default is 4MB)
-x resizable yes or no (see VG status in vxdisplay) 

Check and rename Volume Group :


#vgrename VGName VGName_New   //no LV should be activate at the time of rename

#vgck VolData00       //checking consistency of Meta data


Convert / Merge / Split  Volume Group:


#vgconvert -M2 VGName  //convert one type to anothe type (lvm1 to lvm2)

#vgmerge New_Vol_Group Old_Vol_Group  /old vg will be merged to new VG

#vgsplit Old_Vol_Group New_Vol_Group [physical volumes] [-n logical volume name] 


Import / Export Volume Group


#vgimport VGName

#vgexport VGName

Backup and Restore:

# vgcfgbackup VGname

# vgcfgrestore -f /var/backup/VGname_bkup VGName

PV related commands in Linux LVM :


Directories and Files :

## Directories
/etc/lvm                    - default lvm directory location
/etc/lvm/backup         - where the automatic backups go
/etc/lvm/cache          - persistent filter cache
/etc/lvm/archive        - where automatic archives go after a volume group change
/var/lock/lvm             - lock files to prevent metadata corruption

# Files
/etc/lvm/lvm.conf       - main lvm configuration file
$HOME/.lvm               - lvm history 


Diagnostics :


#lvmdump
#lvmdump -d 


# dmsetup [info|ls|status]    

// Note: by default the lvmdump command creates a tar ball




PHYSICAL VOLUME

 
Display :

  # pvdisplay -v
  # pvs -v
  # pvs -a 

Scanning : 


#pvscan -v

Note: scans for disks for non-LVM and LVM disks 


Add / Remove  / Check PV:


 # pvcreate /dev/sdb1
 # pvremove /dev/sdb1 
  #pvck -v /dev/sdb1 

Change physical attributes:  


## do not allow allocation of extents on this drive
 

#pvchange -x n /dev/sdb1

- Common Attributes that you may want to use:

      --addtag add a tag
      -x allowed to allocate extents
       -u change the uuid 

Move  PV        : 


# pvmove -v /dev/sdb2 /dev/sdb3

Note: moves any used extents from this volume to another volume, in readiness to remove that volume. However you cannot use this on mirrored volumes, you must convert back to non-mirror using "lvconvert -m 0"






7.How to add new LUN from storage to Linux server?

Step 1: Get the list of HBA and exisiting disk details.


#ls /sys/class/fc_host


#fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l


Step 2: Scan the HBA ports (Need to scan all HBA port)


#echo "1" > /sys/class/fc_host/host??/issue_lip


# echo "- - -" > /sys/class/scsi_host/host??/scan


Do this above steps for all HBA cards

Step3 : Check the newly added Lun     


# cat /proc/scsi/scsi | egrep -i 'Host:' | wc -l


# fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l



Once found the disk then do below steps to add to VolumeGroup


#pvcreate /dev/diskpath


#vgextend /dev/vg1 /dev/diskpath


#vgs or #vgdisplay /dev/vg1



8.How to resize root file system on RHEL 6?


Here is the list of steps to reduce the  root file system (lv_root) on a RHEL 6 Linux server:


Boot the system into rescue mode. Do not mount the file systems (select the option to 'Skip' in the rescue mode and start a shell)


Bring the Volume Group online


#lvm vgchange -a -y


Run fsck on the FS


#e2fsck -f /dev/vg_myhost/lv_root


Resize the file system with new size


#resize2fs -f /dev/vg00/lv_root 20G


Reduce the Logical Volume of the FS with the new size


#lvreduce -L20G /dev/vg00/lv_root


Run fsck to make sure the FS is still ok


#e2fsck -f /dev/vg00/lv_root


Optionally mount the file system in the rescue mode


#mkdir -p /mnt/sysimage/root

#mount -t ext4 /dev/mapper/vg00-lv_root /mnt/sysimage/root
#cd /mnt/sysimage/root

Unmount the FS


#cd

#umount /mnt/sysimage/root

Exit rescue mode and boot the system from the hard disk

#exit

Select the reboot option from the recue mode


9.How to find server is configured with LVM RAID ? 


1.How to check linux LVM RAID ?


 check the RAID status in /proc/mdstat


 #cat /proc/mdstat 

 or
 # mdadm --detail /dev/mdx
  or
 # lsraid -a /dev/mdx

2.Check the Volume group disks 


 #vgdisplay -v vg01


 In disk we will get the device names like /dev/md1 , /dev/md2 . It means LVM RAID disks are configured and its added to Volume Group.



10.How to check Linux server is configured with power path disks?


1.Check power path is installed on server?


#rpm -qa |grep -i emc


2.Check the power path status on server?


#/etc/init.d/PowerPath status


#chkconfig --list PowerPath


# lsmod |grep -i emc


3.Check the Volume group disks 


 #vgdisplay -v vg01


 In disk we will get the device names like /dev/emcpowera , /dev/emcpowerb . It means powerpath disks are configured and its added to Volume Group.


4.Check the power path disk status using below command


 #powermt display dev=all



11.How to check server is configured with Multipath disks??


# ls -lrt /dev/mapper  //To View the Mapper disk paths and Lvols


#dmsetup table 


#dmsetup ls 


#dmsetup status


2.Using Multipathd Command ( Daemon ) 



#echo 'show paths' |multipathd -k


#echo 'show maps' |multipathd -k


3.Check multipath Daemon is running or not 


#ps -eaf |grep -i multipathd


4.check the VG disk paths


#vgs or vgdisplay -v vg01 


If multipath disks are added and configured with VG then we will get disk paths like /dev/mpath0 , /dev/mpath1.


5.If you want to check the disk path status u can use below command also


#multipathd -k


#multipathd> show multipaths status


#multipathd> show topology


#multipathd> show paths

Explained NFS mount options (TCS)
Syntax to mount NFS FS:

#mount -t vfstype [-o options] NFS Servername:/exporteddirectory /mount point

or

#mount -t nfs -o options host:/remote/export /local/directory



Mount options explained below :

1. -0 intr

This option is used in non reliable network, or network having more network congestion. NFS request will be interrupted when server is not reachable.

2. -o hard 

If hard option is specified during nfs mount, user cannot terminate the process waiting for NFS communication to resume. For ex ..if u ran ls -a command on ur NFS mounted directory but that time ur NFS server went down means .
The process wont get killed or stopped ..it will wait until the NFS server and mount poit become available.

3. -o soft 

If soft option is specified during nfs mount, user will get error alert when NFS server is not reachable. This is just inverse of hard mount option. It wont wait for reply if the NFS server went down , it will alert us and the process will go down.

4. -o Nfsvers=value

If this option is specified during nfs mount NFS client uses particular NFS protocol version to communicate. 

For example - TCP 

# mount -t nfs -o tcp 192.168.1.4:/mnt/array1/RHEL5 /data/
# mount | grep -i tcp
 192.168.1.4:/mnt/array1/RHEL5 on /data type nfs (rw,tcp,addr=192.168.1.4)
The Difference between HARD and SOFT mount option explained
In HARD mount :

If the NFS file system is hard mounted, the NFS daemons will try repeatedly to contact the server. The NFS daemon retries will not time out, will affect system performance, and you cannot interrupt them

If you just mount a file system without specifying hard or soft, the default is a hard mount. Hard mounts are preferable because of the stateless nature of NFS.

If a client sends an I/O request to the server (such as an ls -la), and the server gets rebooted, in client machine the process will keep on running.
This preserves data transfers in the event of a server failure


In SOFT Mount :

A soft mount allows the client to stop trying an operation after a period of time. If the NFS server goes down at the time of data transfer , it will alert and the process will do down.Thsi may cause the data corruption.
A soft link will return with an error and fail.

you should only use soft mounts in the cases where client responsiveness is more important than data integrity.

In another word ..soft mount will allow automatic unmount if the filesystem is idle for a specified time period

Linux Booting Issues: How to solve??

Here we are going to see how to resolve the common booting issues in Linux. Hope this may help you bit.

Option 1: init not found error
Option 2: Run fsck on all FS in rescue mode
Option 3: Reinstall GRUB
Option 4: Recover grub.conf / grub configuration

Option 1: For normal panic and "init not found" error.

Error : "init not found" displayed

1) Launch the system to Bash shell prompt 

Reboot the server and interrupt to edit the GRUB.

Edit grub and enter the below in last 

init=/bin/bash 

Then save and exit and boot the server. This will launch you straight into a Bash shell prompt.Then you can remount “/” file system and check /var/log/messages for any error.

Note :  init=/bin/bash (Grub boot loader) or linux init=/bin/bash (if Lilo boot loader). 

2) Once server booted and if it is in Bash shell prompt 

 #mount -o remount,rw /

3) Now  you can check the log messages and try to find the reason for server pacnic or error.

#more /var/log/messages


Option 2:  If the above option not helped then follow the next

1) Boot from the Linux First CD (boot CD).

2) Type “boot rescue” at Linux boot prompt.

3) After the bash shell prompt show up, type the below command 

   # chroot /mnt/sysimage

a) Run fsck and Check for any disk error

  #fdisk -l /dev/sda  //check how many partion you have 

   then run fsck on each partition
     
  #fsck -y /dev/sda2'



Option 3: If the above also not helped then try to reinstall grub and retry.

 In rescue mode.

   #  chroot /mnt/sysimage

   # /sbin/grub-install /dev/hda


Option 4: If a system has issues with the GRUB configuration 

(possibly caused by incorrect changes to the the GRUB configuration file, installation of another OS, changes to device ordering due to hardware or BIOS changes, etc.) 

   # grub> find /boot/grub/grub.conf (or) grub>find /grub/grub.conf  (or) find /boot/grub/stage1
    (hd0,1)
    (hd1,2)

    >> This tells us that we have two /boot partitions. Then we have to reinstall the GRUB config on disk (one by one) and try.

   #grub> root (hd0,1)    //Write the GRUB boot loader on the MBR of the first disk
    grub> setup (hd0)
    grub>quit

  If you have doubt as to where the root partition is located then try to find a file in /etc. 
  
    #grub> find /etc/fstab
      (hd0,1)


Note: You must pay attention to your devices, for me "hd0" is the root disk and (hd0,1) is /boot partition , and (hd0,1) is my ROOT (/) partition. mostly / "root" partion will be on LVM.


       You might not even have "hd0" mapped out. Review your "/boot/grub/device.map" file

      #cat /boot/grub/device.map
How to disable IPTABLES??
# service iptables save
# service iptables stop
# chkconfig iptables off


To clear IP rules use below commands:
=====================================

# iptables -F
# iptables -X
# iptables -t nat -F
# iptables -t nat -X
# iptables -t mangle -F
# iptables -t mangle -X
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT ACCEPT

How to Enable IPTABLES??
===================

#/etc/init.d/iptables start

#chkconfig iptables on

#iptables-save > /root/working.fw


To restore Rules:
=============

#iptables-restore < /root/firewall.rules

#iptables-save > /root/firewall.rules


To List the iptable Rules:

# iptables --list

#iptables -L

To delete iptable rules

# iptables --flush

# iptables --flush OUTPUT  //To delete particular CHAIN


some basic Rules:
=============


Interface level:

Allow incomming packets at interface level

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT

# Accept packets from trusted IP addresses

 iptables -A INPUT -s 192.168.0.4 -j ACCEPT # change the IP address as appropriate

# Accept packets from trusted IP addresses

 iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT   //using standard slash notation
 iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT // using a subnet mask


# Accept tcp packets on destination port 6881 (bittorrent)

 iptables -A INPUT -p tcp --dport 6881 -j ACCEPT


# Accept tcp packets on destination ports 6881-6890

 iptables -A INPUT -p tcp --dport 6881:6890 -j ACCEPT


Rules for SSH:
===========

# Accept tcp packets on destination port 22 (SSH)

 iptables -A INPUT -p tcp --dport 22 -j ACCEPT


# Accept tcp packets on destination port 22 (SSH) from private LAN
 iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 22 -j ACCEPT

How can recover or restore the default file
We can recover or restore the default file / folder permission and ownership using rpm command with the options -setperms and --setugids.  

This will help system admin to recover file permissions in easy way. But the below command will take time to change the permission for entire system files and directories. But you have to tolerate .... 

This is very useful option which i found in RPM command.

1) To reset uids and gids on files and directories :

 # for i in $(rpm -qa); do rpm --setugids $i; done


2) To permissions on files and directories

 #for i in $(rpm -qa); do rpm --setperms $i; done

Can you Explain Kick Start Process

Kick start - Tips for network interface selection:

Use a specific network interface for kickstart:

When your system has more than one network interface anaconda asks you which one you'd like to use for the kickstart process. 
This decision can be made at boot time by adding the ksdevice paramter and setting it accordingly. 



1.ksdevice=eth?? - To run kickstart via eth0 simply add ksdevice=eth0 to the kernel command line.

2.ksdevice=link  -  second method is using ksdevice=link. In this case anaconda will use the first interface it finds that has a active link.

3.ksdevice=bootif -  third method works if you are doing PXE based installations. Then you add IPAPPEND 2 to the PXE configuration file and use ksdevice=bootif. In this case anaconda will use the interface that did the PXE boot (this does not necessarily needs to be the first one with a active link).

Within the kickstart config itself you need to define the network interfaces using the network statement. If you are using method 2 or 3 then you don't know which device actually will be used. If you don't specify a device for the network statement anaconda will configure the device used for the kickstart process and set it up according to your network statement.


Forcing kickstart to ask for network configuration

There is a undocumented option that enable a prompt asking for network configuration during the installation. At the network statement, put the query keyword at the --bootproto= networking configuration, as we see below:


network --device=eth0 --bootproto=query

And a dialog box will appear asking for IP addressing, as well the hostname configuration.

The Difference between ext2/ext3/ext4 features in Linux (we will get most of the times this question)

EXT2
·         Ext2 does not have journal feature.
·         Speed of file system(read-write) bit faster than ext3
·         Require fsck to recover data after unplanned reboot
·         By default there is no Online file system growth.
·         mkfs.ext2 or mke2fs Commands to format

EXT3
·         The main benefit of ext3 is that it allows journaling.
·         Bit slower than ext2 file-system
·         Does not require manual fsck (automatic file recovery is done at booting time)
·         Online file system growth
·         mkfs.ext3 or mke2fs -j commands to format


Ext4
·         # Supports huge individual file size and overall file system size.
·         # Maximum individual file size can be from 16 GB to 16 TB
·         # Overall maximum ext4 file system size is 1 EB (exabyte).
·         Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
·         You can also mount an existing ext3 fs as ext4 fs
·         In ext4, you also have the option of turning the journaling feature “off”.


FSCK : 

If you want to run a fsck for any file system , please run the below command .

#umount /filesystem ; fsck -y /filesystem ; mount /filesystem ; mount -o remount,rw /filesystem ; exit