Saturday, December 10, 2016

Linux Interview Question - LVM

Q:  What is LVM ID
8e

Q. What is SWAP Space?
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. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.

Q. what is swap id
82

Q. What are the steps to create SWAP files or Partition?
- Create swap partition or file
- Write special signature using “mkswap”
- Activate swap space by “swapon –a” command
- Add swap entry into /etc/fstab file

Q.  How you will create swap file of size 4 GB and explain swap file entry in /etc/fstab file?
Use “dd” command to create swap file.
dd if=/dev/zero  of=/SWAPFILE  bs=1024  count=4
mkswap /SWAPFILE
swapon –a
Entry into /etc/fstab file.
/SWAPFILE   swap   swap   defaults   0   0

Q.  Tell me the steps to remove the swap file?
Firstly disable the swap file by “swapoff” command.
Remove Swap file entry from /etc/fstab file.
Now remove the swap file by “rm” command.

Q. What can we do with “parted” command or utility?
- View the existing partition table
- Add partitions from free space or additional hard drives
- Change the size of existing partitions

Q. How we will check free space on drive /dev/sda with parted command?
#parted /dev/sda
print

Q.  Can we resize the size of a partition?
Yes, we can resize the size of partition by “parted” command.
#parted /dev/sda
print
To resize the partition, use the resize command followed by the minor number for the partition, the starting place in megabytes, and the end place in megabytes. For example:
resize 3 1024 2048
After resizing the partition, use the print command to confirm that the partition has been resized correctly, is the correct partition type, and is the correct file system type.

Q.  What is LVM?
LVM stands for Logical Volume Manager. LVM, is a storage management solution that allows administrators to divide hard drive space into physical volumes (PV), which can then be combined into logical volume groups (VG), which are then divided into logical volumes (LV) on which the filesystem and mount point are created.

Q. What are the steps to create LVM?
- Create physical volumes by “pvcreate” command
#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 VLG0
Now create file system on /dev/sda2 partition by “mke2fs” command.
#mke2fs -j /dev/VLG0/LVM1

Q.  What is the difference between LVM and RAID?
RAID provides redundancy but LVM doesn’t provide Redundancy.

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

Q. What is Volume group (VG)?
The Volume Group is the highest level abstraction used within the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit.

Q. What is physical extent (PE)?
Each physical volume is divided chunks of data, known as physical extents; these extents have the same size as the logical extents for the volume group.

Q. What is logical extent (LE)?
Each logical volume is split into chunks of data, known as logical extents. The extent size is the same for all logical volumes in the volume group.

Q.  Explain LVM snapshot?
LVM snapshots allow the administrator to create a new block device which presents an exact copy of a logical volume, frozen at some point in time.

Q. How you will check on Your server or system device-mapper is installed or not?
Check the following file.
#cat /proc/misc
if this file contains "device-mapper" term it means device mapper is installed on your system.

Q. How are snapshots in LVM2 different from LVM1?
In LVM2 snapshots are read/write by default, whereas in LVM1, snapshots were read only.

Q. 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.
Q. If a volume group named as VG0 already exists but i need to extend this volume group up to 4GB.Explain all steps?
Firstly create Physical volume (/dev/sda7) of size 4GB.
Now run following command.
vgextend VG0 /dev/sda7

Q. If a volume group VG0 have 3 PV's (/dev/sda6, /dev/sda7, /dev/sda8) but i want to remove /dev/sda7 pv from this VG0?
vgreduce VG0 /dev/sda7

Q. Which command is used to extend a logical volume?
lvextend --size +<addsize> /dev/<vgname>/<lvname>
resize2fs /dev/<vgname>/<lvname>

Q.  Tell me all steps to remove a LVM?
To remove a logical volume from a volume group, first unmount it with the umount command:
umount /dev/<vgname>/<lvname>
and then use the lvremove command:
lvremove /dev/<vgname>/<lvname>

Q.  Which command is used to create LVM Snapshot?
lvcreate --size <size> -s -n <snapshotname> <lvname>
The lvcreate command is used to create a new logical volume, meaning there must be
free physical extents in the logical volume group to create a snapshot. The -s option
means that the LV is a snapshot, <snapshotname> is the name of the new LV created, and
<lvname> is the name of the LV from which to create the snapshot.


Q. What is LVM Snapshot ?
 An LVM snapshot is an exact copy of an LVM partition that has all the data from the LVM volume from the time the snapshot was created. The big advantage of LVM snapshots is that they can be used to greatly reduce the amount of time that your services/databases are down during backups because a snapshot is usually created in fractions of a second. After the snapshot has been created, you can back up the snapshot while your services and databases are in normal operation.

Q. How many volume groups can be created in Linux ?
Answer :256. 
I feel this question is unnecessary and In day to day operation,you will never reach this limit.
I feel that the below interview questions can  help you to find the right candidate.
This articles just covers the LVM part.

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

Answer: Yes.We can increase the logical volume without umount it. 

Q..How to reduce the logical volume ? is it possible to reduce on fly ?

Answer: No.You can’t reduce the logical volume on fly. Here is the steps to reduce the logical volume on redhat Linux.
·            Un-mount the filesystem
·            Run e2fsck on the volume device
·            Reduce the Filesystem.(resize2fs) 
·            Reduce the logical Volume(lvreduce)
·            Mount the filesystem back for production.
 The detailed step by step guide is available here.

Q..How to do you scan the new LUN or disk for LVM  physical volume ?
Answer:Use “pvscan” to scan existing physical volume from newly connected SAN or DISKS.

Q..How to scan disks for existing volume group ? 

Answer:Use “vgscan” to scan existing volume group from newly connected SAN or DISKS.
But you should use “pvscan” prior to executing this command.

Q..How to scan a logical volume from exising volume group? 

Answer: lvscan

Q..How to stop the logical volume ? or deactivate the logical volume ?

Answer: “lvchange -an /dev/vg_name/lv_name” 

Q..How to activated the logical volume which in deactivated state ?

Answer: “lvchange -ay /dev/vg_name/lv_name” .

Q..How to disable the volume group ? or Deactivate the volume group ?

Answer:”vgchange -an volume_group_name” .

Q..How to enable the volume group ? or Activate the volume group ?

Answer:”vgchange -ay volume_group_name” .

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

Answer: use “lvs -a -o +devices” 

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

Answer:
·               Extend the logical volume
·               Increase the Filesystem size
·               Verify the status using df command or lvs command.

Q..How to list the imported volume groups ?
Answer: Use “vgs” command to display the imported volume group.

Q..How to list the available logical volumes on the system?

Answer: Use “lvs” command to list the available logical volumes on the system.

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

Answer: Use “pvs” command to list the available physical volumes.

Q..How to see the detailed volume group information ?

Answer: Use “vgdisplay  vg_name”

Q..How to see the detailed logical volume information ?

Answer: Use “lvdisplay  /dev/vg_name/lv_name”

Q..How to see the detailed physical volume information ?

Answer: Use “pvdisplay /dev/disk_name”    Ex: pvdisplay /dev/sde

Q..How to rename volume Group ? can we rename the VG on fly ? 

Answer:Yes.Its 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.

Q..How to take a LVM configuration backup ?

Answer:Use “vgcfgbackup vg_name” to take the latest configuration backup of volume group.The default volume group backup location is “/etc/lvm/backup” .
Refer:http://www.unixarena.com/2013/08/linux-lvm-volume-group-operations.html

Q..How to re-create the device files for LVM volumes ?
Answer:Run “vgmknodes” to recreate the LVM devices files.

Q..What is lvmdump ? 

Answer: “lvmdump” is tool for LVM2 to collect the various information for diagnostic purposes.By default, it creates a tarball suitable for submission along with a problem report

Q..How to replace the failed hard disk in LVM ? 


Q..How to create a mirrored logical volume ? 


Q..How to create a striped Logical volume ? 


Q..How to convert the linear volume to mirror volume ?


Q..How are snapshots in LVM2 different from LVM1 in Redhat Linux?

Answer:LVM1 snapshots are  readonly by default where LVM2 snapshots were read/write.

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

Answer: 
     i.Create a physical volume using pvcreate command.
       #pvcreate /dev/sdc
    ii.Create a volume group using “vgcreate” command 
       #vgcreate vg02 /dev/sdc
   iii.Create a logical volume using “lvcreate” command
       #lvcreate -L 100M -n vol1 vg02 
    iv.Create a filesystem on logical volume using mkfs command.
        #mkfs -t ext4 /dev/vg02/vol1
     v.Mount the filesystem using mount command for use.
        #mount -t ext4 /dev/vg02/vol1 /vol1

Q..How to extent the volume group ? 

Answer:Using “vgextend” we can increase the volume group.

Q..Assume Volume group “vg02” is already exists.How do you extend the volume group with 50GB ? Provide all the steps with commands.

Answer:
      1.Get the 50GB lun from SAN team.(/dev/sdd)
      2.Create physcical volume ( # pvcreate /dev/sdd )
      2.Extend the volume group (# vgextend vg02 /dev/sdd)

Q..If the vg02 has two physical volumes called /dev/sdc/ & /dev/sdd. How do you remove /dev/sdd from vg02. 

Answer: “vgreduce vg02 /dev/sdd/”

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

Answer:
          1.Un-mount all the logical filesystems
          2.Remove the logical volumes using “lvremove” command.
          3.Destroy the volume group using “vgremove”  command.
          4.Use “pvremove” command remove the physical volumes from the system.

Q: Why LVM is required ?
Ans: LVM stands for Logical Volume Manager , to resize filesystem’s size online we required LVM partition in Linux. Size of LVM partition can be extended and reduced using the lvextend & lvreduce commands respectively.

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

Q: What does Sar provides and at which location Sar logs are stored ?
Ans: Sar Collect, report, or save system activity information. The default version of the sar command (CPU utilization report) might be one of the first facilities the  user  runs  to  begin system  activity investigation, because it monitors major system resources. If CPU utilization is near 100 percent (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 the dd parameter indicates the current day.

Q: How to increase the size of LVM partition ?
Ans: Below are the Logical Steps :
– 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

Q: 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,
-use resize2fs command , e.g resiz2fs /dev/mapper/myvg-mylv 10G
-Now use the lvreduce command , e.g lvreduce -L 10G /dev/mapper/myvg-mylv
Above Command will shrink the size & will make the filesystem size 10GB.

 Q: How to create partition from the raw disk ?
Ans: Using fdisk utility we can create partitions from the raw disk.Below are the steps to create partition from the raw dsik :
– fdisk  /dev/hd* (IDE) or /dev/sd* (SCSI)
– Type n to create a new partition
–  After creating partition , type w command to write the changes to the partition table.

 Q: Where the kernel modules are located ?
Ans: The ‘/lib/modules/kernel-version/’ directory stores all kernel modules or compiled drivers in Linux operating system. Also with ‘lsmod’ command we can see all the installed kernel modules.

Q: What is umask ?
Ans: umask stands for ‘User file creation mask’, which determines the settings of a mask that controls which file permissions are set for files and directories when they are created.

Q: How to set the umask permanently for a user?
Ans: To set this value permanently for a user, it has to be put in the appropriate profile file which depends on the default shell of the user.

Q: How to change the default run level in linux ?
Ans: To change the run level we have to edit the file “/etc/inittab” and change initdefault entry ( id:5:initdefault:). Using ‘init’ command we change the run level temporary like ‘init 3’ , this command will move the system in runlevl 3.

Q: How to share a directory using nfs ?
Ans: To share a directory using nfs , first edit the configuration file ‘/etc/exportfs’ , add a entry like
‘/<directory-name>  <ip or Network>(Options)’ and then restart the nfs service.

Q: How to check and mount nfs share ?
Ans: Using ‘showmount’ command we can see what directories are shared via nfs e.g ‘showmount -e <ip address of nfs server>’.Using mount command we can mount the nfs share on linux machine.

Q: What are the default ports used for SMTP,DNS,FTP,DHCP,SSH and squid ?
Ans: Service      Port
SMTP          25
DNS            53
FTP             20 (data transfer) , 21 ( Connection established)
DHCP         67/UDP(dhcp server) , 68/UDP(dhcp client)
SSH            22
Squid         3128

Q: What is Network Bonding ?
Ans: Network bonding is the aggregation of multiple Lan cards into a single bonded interface to provide fault tolerance and high performance. Network bonding is also known as NIC Teaming.

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

Q: How to check and verify the status the bond interface.
Ans: Using the command ‘cat /proc/net/bonding/bond0’ , we can check which mode is enabled and what lan cards are used in this bond. In this example we have one only one bond interface but we can have multiple bond interface like bond1,bond2 and so on.

Q: How to check default route and routing table ?
Ans: Using the Commands ‘netstat -nr’ and ‘route -n’ we can see the default route and routing tables.

Q: How to check which ports are listening in my Linux Server ?
Ans:  Use the Command ‘netstat –listen’ and ‘lsof -i’

Q: List the services that are enabled at a particular run level in linux server ?
Ans: With the help of command ‘chkconfig –list | grep 5:on’ we can list all the service that are enabled in run level5. For other run levels just replace 5 with the respective run level.

Q: How to enable a service at a particular run level ?
Ans: We can enable a service using the Command ‘chkconfig <Service-Name> on –level 3’

Q: How to upgrade Kernel in Linux ?
Ans: We should never upgrade Linux Kernel , always install the new New kernel using rpm command because upgrading a kenel can make your linux box in a unbootable state.

Q: How To scan newly asssigned luns on linux box without rebooting ?
Ans: There are two ways to scan newly assigned luns :
Method:1 if sg3 rpm is installed , then run the command ‘rescan-scsi-bus.sh’
Method:2 Run the Command ,  echo ” – – – ” > /sys/class/scsi_host/hostX/scan

Q: How  to find WWN numbers of HBA cards in Linux Server ?
Ans: We can find the WWN numbers of HBA cards using the command ‘systool -c fc_host -v | grep port_name’

Q: How to add & change the Kernel parameters ?
Ans: To Set the kernel parameters in linux , first edit the file ‘/etc/sysctl.conf’ after making the changes save the file and run the command ‘sysctl -p’ , this command will make the changes permanently without rebooting the machine.

Q: What is Puppet Server ?
Ans: Puppet is an open-source & enterprise software for configuration management toll in UNIX like  operating system.  Puppet is a  IT automation software used to push configuration to its clients (puppet agents) using code. Puppet code can do a variety of tasks from installing new software, to check file permissions, or updating user accounts & lots of other tasks.

Q: What are manifests in Puppet ?
Ans: Manifests in Puppet are the files in which the client configuration is specified.

Q: Which Command is used to sign requested certificates in Puppet Server ?
Ans: ‘puppetca  –sign hostname-of-agent’ in (2.X)  & ‘puppet ca  sign hostname-of-agent’ in  (3.X)

Q:  At which location  Puppet Master Stores Certificates ?
Ans:  /var/lib/puppet/ssl/ca/signed

Q: How to find all the regular files in a directory  ?
Ans: using the command ‘find /<directory -type f’.

Q: What is load average in a linux ?
Ans: Load  Average is defined as the average sum of the number of process waiting in the run queue and number of process currently executing over the period of 1,5 and 15  minutes. Using the ‘top’ and ‘uptime’ command we find the load average of a linux sever.