BREAKDOWN:
1. WHAT IS LVM
2. KEY FEATURES OF LVM
3. BASIC LVM TERMINOLOGY
4. COMMON LINUX FOR DISK MANAGEMENT
5. LVM COMMANDS IN CONTEXT
1) What is LVM?
LVM (Logical Volume Manager) is a tool for managing storage on Linux systems. It
allows you to create, resize, and manage storage flexibly. Instead of dealing with fixed
partitions, LVM lets you create logical volumes that can be resized or moved without
affecting the data.
2) Key Features of LVM:
Flexibility: You can expand or shrink storage easily.
Snapshots: Capture the current state of your data for backups.
Scalability: Manage multiple disks as one logical storage.
Basic LVM Terminology:
Physical Volume (PV): Represents physical storage (like disks or partitions).
o Example: /dev/sda1
Volume Group (VG): Combines multiple physical volumes into one storage pool.
o Example: vg_data
Logical Volume (LV): Acts like a partition but is flexible.
o Example: /dev/vg_data/lv_app1
Common Linux Commands for Disk Management:
1. lsblk (List Block Devices):
Displays information about block devices (disks and partitions).
• Usage: lsblk
• Details:
o Shows the device name, size, and mount point.
o Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 10G 0 part /
├─sda2 8:2 0 20G 0 part /data
└─sda3 8:3 0 20G 0 part /backup
2. lsblk -l (List Block Devices in Long Format):
Provides detailed, line-by-line information about block devices.
• Usage: lsblk -l
• Details: Each block device is listed in a tabular format.
3. free (Show Memory Usage):
Displays memory usage (RAM and swap).
• Usage: free
• Details:
o Columns: Total, Used, Free, Shared, Buff/Cache, Available.
o Example:
total used free shared buff/cache available
Mem: 3882968 1240964 1791068 122352 850936 2239988
4. free -h (Human-Readable Format):
Displays memory usage in a more understandable format (e.g., GB/MB).
• Usage: free -h
• Details:
o Example:
total used free shared buff/cache available
Mem: 3.7G 1.2G 1.8G 120M 850M 2.2G
5. df (Disk Free):
Shows available and used disk space for file systems.
• Usage: df
• Details:
o Example:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 41943040 2048000 39995040 5% /
6. df -h (Human-Readable Disk Usage):
Same as df but displays sizes in GB/MB.
• Usage: df -h
7. mount (List Mounted File Systems):
Shows file systems currently mounted and their mount points.
• Usage: mount
• Details:
o Example:
/dev/sda1 on / type ext4 (rw,relatime)
8. umount (Unmount a File System):
Used to unmount a mounted file system.
• Usage: umount <mount_point>
9. more (View File Contents):
Allows you to view large files one screen at a time.
• Usage: more <file>
10. fdisk (Partition Manager):
Used to create, delete, or modify disk partitions.
• Usage: sudo fdisk /dev/sda
• Details:
o Type m for help inside the fdisk menu.
11. mkfs (Make File System):
Used to format a disk or partition.
• Usage: sudo mkfs.ext4 /dev/sda1
12. blkid (Block ID):
Displays UUID and type of file systems on block devices.
• Usage: sudo blkid
13. pvcreate (Create Physical Volume):
Initializes a disk or partition for use with LVM.
• Usage: sudo pvcreate /dev/sdb
14. vgcreate (Create Volume Group):
Combines physical volumes into a volume group.
• Usage: sudo vgcreate vg_data /dev/sdb
15. lvcreate (Create Logical Volume):
Creates a logical volume within a volume group.
• Usage: sudo lvcreate -L 1G -n lv_app1 vg_data
LVM Commands in Context:
1. Initialize LVM:
sudo pvcreate /dev/sdb
sudo vgcreate vg_data /dev/sdb
sudo lvcreate -L 1G -n lv_app1 vg_data
2. Format and Mount:
mkdir /mnt/app1
sudo mkfs.ext4 /dev/vg_data/lv_app1
sudo mkdir /mnt/app1
sudo mount /dev/vg_data/lv_app1 /mnt/app1
3. Check Mounted Devices:
df -h
lsblk