1. What is LVM in Linux?
A) LVM (Logical Volume Manager) is a disk management system in Linux that allows flexible disk storage by creating logical volumes on top of physical storage devices.
2. What are the main components of LVM?
A)
- PV (Physical Volume): A physical storage device (disk/partition).
- VG (Volume Group): Pool of storage created from PVs.
- LV (Logical Volume): Virtual partition created from a VG.
- PE (Physical Extent): Smallest unit of PV allocation.
- LE (Logical Extent): Smallest unit of LV allocation (maps to PE).
3. What is the advantage of using LVM over traditional partitioning?
A)
- Resize volumes easily.
- Combine multiple disks into one volume group.
- Create snapshots.
- Add/remove storage without downtime.
- Better storage management flexibility.
4. How do you create an LVM setup?
A)
- Create PV → pvcreate /dev/sdb
- Create VG → vgcreate myvg /dev/sdb
- Create LV → lvcreate -L 5G -n mylv myvg
- Format LV → mkfs.ext4 /dev/myvg/mylv
- Mount → mount /dev/myvg/mylv /mnt
5. What is the default extent size in LVM?
A) The default extent size is 4 MB, but it can be changed during VG creation.
6. What is the difference between PE and LE in LVM?
A)
- PE (Physical Extent): Smallest unit of space in a PV.
- LE (Logical Extent): Smallest unit of space in an LV.
Each LE maps directly to a PE.
7. How do you extend a logical volume?
A)
- Extend LV → lvextend -L +2G /dev/myvg/mylv
- Resize filesystem → resize2fs /dev/myvg/mylv
8. How do you reduce a logical volume?
A)
- Unmount the filesystem.
- Run e2fsck -f /dev/myvg/mylv
- Resize filesystem → resize2fs /dev/myvg/mylv 5G
- Reduce LV → lvreduce -L 5G /dev/myvg/mylv
- Remount the filesystem.
9. How do you create an LVM snapshot?
A)
- lvcreate -L 1G -s -n mysnap /dev/myvg/mylv
10. How do you remove an LVM logical volume?
A)
- Unmount the LV.
- Run → lvremove /dev/myvg/mylv
11. How do you display all LVM volumes?
A)
- PVs → pvs or pvdisplay
- VGs → vgs or vgdisplay
- LVs → lvs or lvdisplay
12. Can you extend a Volume Group? How?
A) Yes, by adding a new physical volume:
- Create PV → pvcreate /dev/sdc
- Extend VG → vgextend myvg /dev/sdc
13. How do you shrink a Volume Group?
A)
- Move data → pvmove /dev/sdc
- Remove PV → vgreduce myvg /dev/sdc
14. What happens when a disk in LVM fails?
A)
- If the disk is part of a linear LV, data is lost.
- If striped, only partial data is accessible.
- Snapshots and backups are recommended for recovery.
15. How do you remove a Volume Group?
A)
- Remove LVs → lvremove /dev/myvg/mylv
- Remove VG → vgremove myvg
16. What is the command to check free space in a Volume Group?
A)
- vgs or vgdisplay → Look for “Free PE / Size”.
17. What are the real-time use cases of LVM?
A)
- Growing storage for databases without downtime.
- Creating test environments using snapshots.
- Consolidating multiple small disks into one logical pool.
- Expanding storage dynamically in virtualized/cloud setups.