70 Linux Interview Questions

1. What is the maximum length for a filename in Linux?

Ans: 255 characters.

2. Which command is used to uncompress gzip files?

Ans: “gunzip” command is used to uncompress gzip files.

3. How to delete information from a file in vi?

Ans: The following commands are used to delete information from vi editors.
• x deletes a current character.
• dd deletes the current line.

4. How to reduce or shrink the size of LVM partition?

Ans: Below are the logical steps to reduce size of LVM partition:
• Unmount the filesystem using unmount command.
• Use resize2fs command, e.g # resiz2fs /dev/mapper/MYVG-MYLV 10G
• Now use the lvreduce command as # lvreduce -L 10G /dev/mapper/MYVG-MYLV
• The above Command will shrink the size of LVM partition by 10GB.

5. What are the different modes of Network bonding in Linux?

Ans: Below are list of modes used in Network Bonding:
• balance-rr or 0 – round-robin mode for fault tolerance and load balancing.
• active-backup or 1 – Sets active-backup mode for fault tolerance.
• balance-xor or 2 – Sets an XOR (exclusive-or) mode for fault tolerance and 
load balancing.
• broadcast or 3 – Sets a broadcast mode for fault tolerance. All transmissions 
are sent on all slave interfaces.
• 802.3ad or 4 – Sets an IEEE 802.3ad dynamic link aggregation mode. Creates
aggregation groups that share the same speed & duplex settings.
• balance-tlb or 5 – Sets a Transmit Load Balancing (TLB) mode for fault tolerance
& load balancing.
• balance-alb or 6 – Sets an Active Load Balancing (ALB) mode for fault tolerance
& load balancing.

6. Is SUID by default set to cron?

Ans: SUID is set to crontab command by default
     [[email protected] ~]# ll `which crontab`
     -rwsr-xr-x. 1 root root 57552 Mar 31 2016 /usr/bin/crontab

7. Syslog server and client configuration, package name, port number for both.

Ans: In RHEL-6 rsyslog is default logging daemon.

--> To configure the remote server to accept remote log messages using TCP.
1. Uncomment the following lines in the MODULES section of /etc/rsyslog.conf:
$ModLoad imtcp
$InputTCPServerRun 514
2. Restart rsyslog service.

--> Configure the rsyslog to send rsyslog events to another server using TCP.
1. Add the following line to the RULES section of /etc/rsyslog.conf:
  # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
  #*.* @remote-host:514
  *.* @@10.10.10.1:514
2. Restart rsyslog.
--> Configure the remote server to accept remote log messages using UDP.
1. Uncomment the following lines in the MODULES section of /etc/rsyslog.conf:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
2. Restart rsyslog service.

--> Configure the rsyslog server to send rsyslog events to another server using UDP.
1. Add the following line to the RULES section of /etc/rsyslog.conf:
   # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
   #*.* @remote-host:514
   *.* @10.10.10.1:514
2. Restart rsyslog.
  
Test the configuration:
On server2 (rsyslog sending out the messages):
  [[email protected] ~]# logger Test from system
  [[email protected] ~]# tail /var/log/messages
Dec 25 00:00:01 server2 root: Test from system
  On server1 (rsyslog receiving the messages)
  [[email protected] ~]# tail /var/log/messages
Dec 25 00:00:01 server2 root: Test from system

8. What is kernel panic? Reasons for kernel panic.

Ans: A kernel panic is an error from which the operating system (OS) cannot quickly
 or easily recover. Kernel panics are generally caused by bad drivers, overtaxed memory,
 software bugs, hardware failure (Incompatible hardware, Hard disk corruption, 
 including bad sectors, directory corruption, and other hard-disk ills), etc.

9. How will you troubleshoot if server is stuck at booting?

Ans:
• If you hit the "esc" key if server is stuck at booting, it will show you where it's stuck.
This commonly happens if an NFS mount point is offline. You have to boot into single
user mode, and make changes or restart whatever service is stuck.
• If it shows out of memory error, we may have to remove any erroneous hugepage 
  allocation vm.nr_hugepages from /etc/sysctl.conf.
• Check for any other error that you will get at screen. It may be because of any 
  hardware failure as well. We need to look into it further accordingly as per the error.

10. How will you troubleshoot if server is stuck at grub prompt?

Ans: Go to rescue mode and reinstall or upgrade the GRUB boot loader.
>> Go to rescue mode.
>> Type chroot /mnt/sysimage to mount the root partition.
>> Type /sbin/grub-install /dev/hda to reinstall the GRUB boot loader, 
where /dev/hda is the boot partition.
>> Reboot the system.

Or

Follow below steps (you don't need a live cd to solve this):
grub> ls ( here you should see a list of devices/partitions )
now we must find the partition that contains /boot
grub> ls (hd0,gpt1)/ # you may see msdos instead of gpt and the slash is necessary
if this is the right partition we should see :
boot etc root bin ....
grub> set root=(hd0,gpt1)
grub> linux /boot/vmlinuz....(press tab and choose the last working version) 
ro root=/dev/sda1
grub> initrd /boot/init.....(press tab and select the same version as above)
grub> boot
This is just an example, you should modify it accordingly.

11. Troubleshoot and identify the IO waits are high.

Ans: We can troubleshoot and identify IO weights by using below commands:
    # sar –u 2 5             -->  It will show IO waits
To install iotop on CentOS or RHEL, use yum command.
    # yum install iotop
To monitor disk I/O with iotop:
    # iotop
Running iotop without any argument like above shows a list of all existing processes
regardless of their disk I/O activities. If you want iotop to only show processes 
that are actually doing disk I/O, run the following instead.
    # iotop -o
Monitor disk I/O on per-disk basis
If you are interested in monitoring disk read/write rates of individual disks,
you can use iostat. This tool allows you to monitor I/O statistics for each
device or partition. To use this tool, you need to install sysstat package.
To install sysstat on CentOS, RHEL or Fedora:
    # yum install sysstat
To monitor disk I/O of individual disk devices:
    # iostat -xd <update interval in seconds>
The above iostat command will report per-device I/O statistics, 
including # of read/write requests per second (noted as r/s, w/s), 
average read/write speed (in KB/s), average read/write wait time (in milliseconds), 
average size of requests (in sectors), and percentage of CPU time spent for I/O requests.
The statistics are refreshed every time interval specified.

12. Write a command that will do the following:

• Look for all files in the current and subsequent directories with an extension c,v

• Strip the ,v from the result (you can use sed command)

• Use the result and use a grep command to search for all occurrences of the word ORANGE in the files.

Ans: # find ./ -name "*.c,v" | sed 's/,v//g' | xargs grep "ORANGE"

13.  How can you find out how much memory Linux is using?

Ans: From a command shell, use the "concatenate" command: cat /proc/meminfo for 
memory usage information. You should see a line starting something like 
Mem: 64655360, etc. This is the total memory Linux thinks it has available to use.
You can also use commands to find current memory usage:
# free - m
# vmstat
# top
# htop

14.What is a typical size for a swap partition under a Linux system?

Ans: The preferred size for a swap partition is twice the amount of physical memory
 available on the system. If this is not possible, then the minimum size should be 
 the same as the amount of memory installed.

15.What are daemons?

Ans: 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.

16. Write a command that will display all .txt files, including its individual permission.

Ans: # ls -al *.txt

17. How can you append one file to another in Linux?

Ans: To append one file to another in Linux you can use command 
cat file2 >> file 1. The operator ">>" appends the output of file2 to 
file1. Note: it'll create file1 if it is not created already. While another command 
cat file 1 file 2 > file 3 appends two or more files to one.

18. How to create a new file and modify an existing file in vi editor? Also, enlist the commands used to delete information from vi editor?

Ans: Find below the commands with the description
vi filename: This is the command used to create a new file as well as modify an existing file.
view filename: This command opens an existing file in read-only mode.
x: This command deletes the character which is under the cursor or before the cursor location.
dd: This command is used to delete the current line.

19. What is a zombie?

Ans: Zombie is a process state when the child dies before the parent process.
 In this case the structural information of the process is still in the process table.
 Since this process is not alive, it cannot react to signals. Zombie state can finish
 when the parent dies. All resources of the zombie state process are cleared
 by the kernel.

20. How do you list files in a directory?

Ans: # ls - list directory contents
        # ls -l (-l use a long listing format)

21. How do you list all files in a directory, including the hidden files?

Ans: # ls -a (-a, do not hide entries starting with .)

22. How do you find out all processes that are currently running?

Ans: # ps -f (-f does full-format listing.)

23. How do you find out the processes that are currently running on a particular user?

Ans: # ps -au Myname (-u by effective user ID (supports names)) (a - all users)

24. How do you kill a process?

Ans: 
# kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
# kill -9 -1 (Kill all processes you can kill.)
# killall - kill processes by name most (useful - killall java)

25.What is the difference between home directory and working directory?

Ans: Home directory is the directory you begin at when you log into the system.
 Working directory can be anywhere on the system and it is where you are currently working.

26. What does sar provide? Where are sar logs stored?

Ans: # sar collects, reports, or saves system activity information, sar serves 
to log and evaluate a variety of information regarding system activity. With 
performance problems, sar also permits retroactive analysis of the load values 
for various sub-systems (CPUs, memory, disks, interrupts, network interfaces and so forth)
and limitation of problems in this manner. If CPU utilization is near 100 % 
(user + nice + system), the workload sampled is CPU-bound.
By default, log files of sar command is located at /var/log/sa/sadd file, where
dd parameter indicates the current day.

27. How to check Memory stats and CPU stats as a Linux admin?

Ans: Using ‘free’ & ‘vmstat’ command, we can display the physical and virtual 
memory statistics, respectively. With the help of ‘sar’ command, we can see the 
CPU utilization & other stats.

28. How to check and verify the status of the bond interface?

Ans: Using the command ‘cat /proc/net/bonding/bond0,’ we can check what mode 
is enabled and what LAN cards are used in this bond.

    29. Is there any relation between modprobe.conf file and network devices?

    Ans: Yes, this file assigns a kernel module to each network device.
    For Example :-
    # cat /etc/modprobe.conf
    alias eth0 b44
    Here, b44 is the kernel module for network device eth0.
    
    We can confirm whether this module “b44” is present or not by the following command
    # lsmod |grep b44
    b44 29005 

    30. How to Enable ACLs for /home partition?

    Ans: Add following entry in /etc/fstab
         LABEL=/home /home ext3 acl 1 2
         Now remount /home partition with acl option.
         # mount -t ext3 -o acl /dev/sda3 /home

    31. What is LVM?

    Ans: LVM stands for Logical Volume Manager. LVM, is a storage management solution 
    that allows administrators to divide hard drive space into physical volume (PV),
    which can then be combined into volume group (VG), which is then divided into
    logical volumes (LV) on which the FS and mount points are created. We can extend 
    and reduce LVM as per our requirement.

    32. Why LVM is required?

    Ans: LVM plays a very important role in production environment. We can extend the 
    size of a FS on running servers without un-mounting the partitions so that our 
    production is not impacted. We can also reduce the size of a FS.

    33. What is the difference between LVM and Raid?

    Ans: A RAID device is a physical grouping of disk devices in order to create a 
    logical presentation of one device whereas LVM is a logical layer that can be 
    manipulated in order to create or expand a logical presentation of a disk device
    to an OS.

    34 Explain LVM Snapshot?

    Ans : LVM snapshot allows the administrator to create a new block device
    which present exact copy of a logical volume, frozen at some point in time.

    35. How are snapshots in LVM2 different from LVM1?

    Ans: In LVM2 snapshots are read/write by default, whereas in LVM1, snapshots 
    were read only.

    36.  What is the partition type number for SWAP, Raid and LVM?

    Ans: SWAP (82), RAID (fd) and LVM (8e)

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

    Ans: 
    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.

    38. Is it possible to increase the logical volume on fly?

    Ans: Yes, LVM has the feature to increase the volume without un-mounting it.

    39. How to reduce the logical volume? Is it possible to reduce on fly?

    Ans: No, we can't reduce the logical volume on fly. Here is the steps to reduce 
    the logical volume.
              • Un-mount the FS. 
              • Run e2fsck on the volume device 
              • Reduce the FS using resize2fs 
              • Reduce the logical Volume using lvreduce
              • Mount the FS back for production.

    40. How to stop or deactivate the logical volume?

    Ans: # lvchange -an /dev/vg_name/lv_name

    41. How to start or activate the logical volume which is in deactivated state?

    Ans: # lvchange -ay /dev/vg_name/lv_name

    42. How to disable or deactivate the volume group?

    Ans: # vgchange -an volume_group_name

    43. How to enable or activate the volume group?

    Ans: # vgchange -ay volume_group_name

    44. How do you find the disks which are used for logical volume mirroring?

    Ans: # lvs -a -o +devices

    45. How to list the imported volume groups?

    Ans: # vgs --> is used to display the imported volume group.

    46. How to see the detailed physical volume information?

    Ans: # pvdisplay /dev/disk_name 
    Example: # pvdisplay /dev/sda

    47. How to see the detailed logical volume information?

    Ans: # lvdisplay /dev/vg_name/lv_name

    48. How to see the detailed volume group information?

    Ans: # vgdisplay vg_name

    49.How to list the available physical volumes in LVM?

    Ans: # pvs ---> is used to list the available physical volumes.

    50. How to remove a disk from a volume group?

    Ans: # vgreduce <vgname> <disk>

    51. How do you find what are the disks used for logical volume mirroring?

    Ans: # lvs -a -o +devices

    52. How to re-create the device files for LVM volumes?

    Ans: Run “vgmknodes” to recreate the LVM devices files.

    53. How many volume groups can be created in Linux?

    Ans: 256

    54. Tell me all steps to remove a LVM?

    Ans: Follow below steps to remove a logical volume from a volume group:
    1. First unmount it with the umount command:
        # umount /dev/<vgname>/<lvname>
    2. Then use the lvremove command:
        # lvremove /dev/<vgname>/<lvname>

    55. How to rename Volume Group? Can we rename the VG on fly?

    Ans: Yes, it’s possible to rename the volume group on fly. But the mounted volumes
    will not reflect the same unless you re-mount the volume with new VG name.
    Need to update the /etc/fstab with new VG name to mount the volumes across
    the system reboot.

    56. How to backup new LVM data structures?

    Ans: # vgcfgbackup /dev/vgname

    57. How to scan a logical volume from existing volume group?

    Ans: # lvscan

    58. What are steps to perform in order to increase the logical volume on fly?

    Ans: Follow below steps: 
    1. Extend the logical volume # lvextend -L +10G /dev/<vg-name>/<lv-name> 2. Re-size the file-system using # resize2fs /dev/<vg-name>/<lv-name> 3. Verify the status using df command or lvs command
     # df -h
     # lvs

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

    Ans: Below are the 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
      # umount /mnt/sysimage/root 
    • Exit rescue mode and boot the system from the hard disk 
      # exit
    • Select the reboot option from the rescue mode

    60. How to create partition from the raw disk?

    Ans: Using fdisk command we can create partitions from the raw disk.
    Below are the steps to create partition from the raw disk:
     • # fdisk /dev/hd* (IDE) or /dev/sd* (SCSI) 
     • Type n to create a new partition (follow the on screen instructions).
     • After creating partition, type w command to write the changes to the partition table.

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

    Ans: Check the RAID status in /proc/mdstat 
       # cat /proc/mdstat (Or) 
       # mdadm --detail /dev/mdx (Or)
       # lsraid -a /dev/mdx 
     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 it’s added to Volume Group. 

    62. How to reduce or shrink the size of LVM partition?

    Ans: Below are the logical Steps to reduce size of LVM partition:
    • Umount the filesystem using umount command, 
    • Then run resize2fs command 
       e.g. # resiz2fs /dev/mapper/myvg¬mylv 10G
    • Now use the lvreduce command 
       e.g. # lvreduce ¬L 10G /dev/mapper/myvgmylv 
    • Above Command will shrink the size & will make the filesystem size 10GB.

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

    Ans: Below are the steps to check how 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 added to Volume Group.
    4. Check the power path disk status using below command 
        # powermt display dev=all

    64. How to run file system check on a logical volume in rescue mode?

    Ans: Below are the steps to run file system check on an LV in rescue mode:
    • Boot into rescue mode (“linux rescue nomount”) 
    • Don’t mount any file systems, so “Skip” mounting.
    • First make the logical volumes available by running these commands:
      # lvm pvscan 
      # lvm vgscan 
      # lvm lvscan 
      # lvm lvchange -ay 
    • Next, run the file system check on the respective lvm. 
      # e2fsck -fy /dev/vgname/lvname

    65. How to increase the size of LVM partition?

    Ans: Below are the steps to increase an LVM partition: 
    • Use the lvextend command 
      # lvextend L +100M /dev/<Name of the LVM Partition>
    In this example we are extending the size by 100MB.
      # resize2fs /dev/<Name of the LVM Partition> 
    Check the size of partition using ‘df h’ command.
      # df -h

    66. How to check server is configured with multipath disks?

    Ans: 
    1. To View the Mapper disk paths run:
      # ls -lrt /dev/mapper
      # 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 you can also use below command:
      # multipathd -k 
      # multipathd> show multipaths status 
      # multipathd> show topology
      # multipathd> show paths

    67. How to decommission/remove LVM completely from the host?

    Ans: Follow below steps remove LVM: 
    • Un-mount all the logical filesystems 
    • Remove the logical volumes using "lvremove" command. 
    • Destroy the volume group using "vgremove" command.
    • Run "pvremove" command remove the physical volumes from the system.

    68. What are the steps involved to create the logical volume from scratch?

    Ans: Follow below steps:
    • Create a physical volume using pvcreate command: 
      # pvcreate /dev/sdc
    • Create a volume group using "vgcreate" command:
      # vgcreate VG02 /dev/sdc 
    • Create a logical volume using "lvcreate" command:
      # lvcreate -L 100M -n LV1 VG02 
    • Create a filesystem on logical volume using mkfs command:
      # mkfs -t ext4 /dev/VG02/LV1
    • Mount the filesystem using mount command for use: 
      # mount -t ext4 /dev/vg02/LV1 /root/mount_point

    69.What are the risks of LVM?

    Ans: Risks of using LVM:
    • Vulnerable to write caching issues with SSD or VM hypervisor 
    • Harder to recover data due to more complex on-disk structures 
    • Harder to resize filesystems correctly 
    • Snapshots are hard to use, slow and buggy 
    • Requires some skill to configure correctly given these issues 
      The first two LVM issues combine: if write caching isn't working correctly and you have
      a power loss (e.g. PSU or UPS fails), you may well have to recover from backup, 
      meaning significant downtime. A key reason for using LVM is higher uptime (when
      adding disks, resizing filesystems, etc), but it's important to get the write caching setup
      correct to avoid LVM actually reducing uptime. 
    LVM can still work well if you: 
    • Get your write caching setup right in hypervisor, kernel, and SSDs 
    • Avoid LVM snapshots
    • Use recent LVM versions to resize filesystems 
    • Have good backups.

    70. What does Sar provides and at which location Sar logs are stored?

    Ans: sar collects, reports and save system activity information. The default version
    of the sar command monitors major system resources. By default log files of sar
    command are located at /var/log/sa/sadd file, where the dd parameter indicates 
    the current day.

    That’s it in this article, hope you enjoyed it. Please share it across if you think it’s good.

    One thought on “70 Linux Interview Questions

    Leave a Reply

    Your email address will not be published. Required fields are marked *