Monday, October 14, 2013

Linux Administrator Interview Questions and Answers

1. What are the run levels?

There are total seven run levels as follows:
   0 – halt
   1—single user mode
   2—multiuser mode without NFS
   3—Multiuser with NFS
   4-Unused
   5 -- Multiuser mode with X11.
   6 – Reboot.

2. Explain Booting Procedure?

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.


3.     What is command is used to set the default permission for the files created?
         Umask

4.     How do restrict the level of system resources available for a particular user?
         Ulimit

5.     How to see the background processes running in a shell?
        jobs –l

6.     What are the important values to be looked in iostat and vmstat
       Iostat:  %iowait, %idle vmstat:  swap in (si) and swap out (so)

7.   How do you replace all occurrences of a pattern in vi?
       s/pattern/pattern1/g

8.  How to check if a port is open in a remote system?
      telnet or nmap

9.   What port does SMTP use?
      25

10.  How to see the default gateway of a system?
      route –n, netstat –rn

11.  Get second column of a file which is separated by a colon
      cut –d “:” –f2

12.  What other services are needed for nfs to be running
      rpc.mountd, portmap

13.  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

14.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.

15. 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

16. What vmstat shows ? 

          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.

17.How to setup never expired user password

       chage -E never username

18. 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. 

19. 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


20.  ext2/ext3/ext4 features in Linux

EXT2
·  Ext2 does not have journal feature.
·  Speed of file system(read-write) bit faster then 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 then 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