============================================================
             LVM SNAPSHOT GUIDE (/dev/sdf - 15G)
============================================================
Author      : Tushar Sonawane
Date        : 09 September 2026
============================================================

--- PART 1: PREPARE THE PHYSICAL DISK ---

1. Partitioning the Disk:
   fdisk /dev/sdf
   (Inside fdisk: 'g' for GPT, 'n' for new, 't' for type 8e/8e00, 'w' to save)
   > MEANING: Prepares the raw disk hardware and flags it specifically 
     for LVM (Logical Volume Manager) use.

2. Verify Disk Layout:
   lsblk /dev/sdf
   > MEANING: Confirms the partition table was written correctly 
     before applying LVM layers.


--- PART 2: LVM STRUCTURE SETUP ---

1. Create Physical Volume (PV):
   pvcreate /dev/sdf1
   > MEANING: Initializes the partition so LVM can recognize it 
     as "usable space" for its pool.

2. Create Volume Group (VG):
   vgcreate vg_data /dev/sdf1
   > MEANING: Creates a "storage pool" called 'vg_data'. You can 
     combine multiple physical disks into one VG.

3. Create Logical Volume (LV):
   lvcreate -L 1G -n lv_data vg_data
   > MEANING: Carves out a 1GB "virtual partition" named 'lv_data' 
     from the storage pool. This acts like a standard drive.


--- PART 3: FILESYSTEM & INITIAL DATA ---

1. Format and Mount:
   mkfs.ext4 /dev/vg_data/lv_data
   mkdir /mnt/lv_data
   mount /dev/vg_data/lv_data /mnt/lv_data
   > MEANING: Creates a Linux filesystem (EXT4) on the LV and 
     links it to a folder so you can store files.

2. Add Test Data:
   echo "ORIGINAL DATA" > /mnt/lv_data/file1.txt
   dd if=/dev/zero of=/mnt/lv_data/bigfile bs=1M count=200
   > MEANING: Creates sample files to track changes during 
     the snapshot process.


--- PART 4: SNAPSHOT OPERATIONS ---

1. Create Snapshot:
   lvcreate -L 300M -s -n lv_data_snap /dev/vg_data/lv_data
   > MEANING: Creates a 300MB "frozen moment" of the original LV. 
     Only changes made after this point will consume the 300MB space.

2. Mount and Modify Snapshot:
   mkdir /mnt/lv_data_snap
   mount -t ext4 /dev/vg_data/lv_data_snap /mnt/lv_data_snap
   echo "SNAPSHOT CHANGE" > /mnt/lv_data_snap/file1.txt
   > MEANING: You are now working in a "parallel universe." Changes 
     here do not affect the original files in /mnt/lv_data.

3. Monitor Usage:
   lvs -a -o +lv_size,data_percent
   > MEANING: Checks how much of that 300MB snapshot space is used. 
     If it hits 100%, the snapshot breaks!

--- PART 5: ROLLBACK OR MERGE ---

1. Option A: Rollback (Discard Changes):
   umount /mnt/lv_data_snap
   lvremove /dev/vg_data/lv_data_snap
   > MEANING: Deletes the snapshot and all changes made in it. 
     The original data remains exactly as it was.

2. Option B: Merge (Keep Changes):
   umount /mnt/lv_data
   umount /mnt/lv_data_snap
   lvconvert --merge /dev/vg_data/lv_data_snap
   > MEANING: "Folds" the snapshot changes back into the original LV. 
     The 'original' file now becomes the 'modified' file permanently.


--- PART 6: SYSTEM CLEANUP ---

1. Remove LVM Layers:
   umount /mnt/lv_data
   lvremove vg_data/lv_data
   vgremove vg_data
   pvremove /dev/sdf1
   wipefs -a /dev/sdf
   > MEANING: Completely wipes the LVM configuration and signatures 
     from /dev/sdf, returning it to a blank state.
============================================================