Linux Volumes: A Comprehensive Guide for DevOps Engineer

Nenis RudaniNenis Rudani
4 min read

🟡Introduction to Linux Volumes and AWS & EBS

in simple term :-

  • Linux Volume: Think of it as an extra storage unit that you can add to your Linux server when needed. You can mount, unmount, resize, or move it dynamically without affecting the entire system.

  • AWS EBS (Elastic Block Store): It’s like an external SSD that provides persistent storage for AWS EC2 instances. You can attach it when you need extra space and detach it when not in use, just like plugging in and removing an external SSD from your computer.

To get hands-on experience with Linux volumes and AWS EBS, you need to know these prerequisites:

🟡Physical vs Logical Volumes vs Volume Groups in Linux

  • Physical Volumes (PVs): The actual storage device or disk (like a hard drive, SSD, or EBS volume).

  • Volume Groups (VGs):A collection of physical volumes combined into one storage pool.

  • Logical Volumes (LVs): A flexible, customizable storage space created from the volume group, which you can resize as needed.

For example(LV), you have a 512GB hard drive and divide it into:

  • C: Drive (312GB) for the operating system

  • D: Drive (200GB) for personal files

Logical Volume Management (LVM) enables flexible disk space allocation, making it easier to manage storage efficiently.

Here’s how you can practically understand Physical Volume, Volume Group, and Logical Volume using commands in Linux:

what you need before practical:-

  • first, you need to create an EC2 on AWS

  • and then create 3 EBS on AWS(you can take reference from the above link)(I create 3 EBC 10GB , 12 GB , 14 GB)

  • then install lvm using this command:-

  •   sudo apt install lvm2
      # ony for Ubuntu/Dabian
    
💥
The two most important commands for it:- lsblk(list of block) & df -h(show mount point)

Let’s do practical:-

1.For Physical Volume

  1. after attaching EBS to your EC2 run this command
  •   lsblk
    

output:-

now it’s attached with EC2 but not mounted with it

DIff between attach and mount:-

Attach: Connects storage to the system. (Like plugging in a USB drive)
Mount: Makes storage usable by the OS. (Like opening the USB drive to access files)

  1. write command:-

  2.  lvm
    
  3. Then create a physical volume

  4.   pvcreate /dev/xvdf /dev/xvdg /dev/xvdh
      pvc #show details of pv
    

  5. use this command to show more details about it

pvdisplay

2.For Logical group:-

  1. Let’s create a Logical group
vgcreate first_vg /dev/xvdf /dev/xvdg
vgdisplay #use this command for detailed information about a specific Volume Group.
vgs #shows a summary of all Volume Groups

3.For Logical volume:-

  1. Create Logical volume from logical group

     lvcreate -L 10G -n first_lv first_vg
     lvdisplay # shows all details about lv
     lvs #shows a summary of all lvs
    

Let’s understand what we have done till now using the diagram:-

🟡Mounting Volumes in Linux

  1. To mount the volume you need to create a directory

     mkdir /mnt/first_lv_mount
    
  2. then you need to format your lv

     mkfs.ext4 /dev/first_vg/first_lg
    
  3. then mount it

     mount /dev/first_vg/first_lg /mnt/first_ls_mount
    
  4. how to unmount volume

     umount /mnt/first_ls_mount
    

🟡Using LVM with EBS for dynamic storage management

  1. create directory

     mkdir /mnt/second_disk_mount
    
  2. Then format your volume

     mkfs -t ext4 /dev/xvdh
    
  3. let’s mount them

     mount /dev/xvdh /mnt/second_disk_mount
    
  4. let’s extend 5GB in the lv (using lvm with EBS for dynamic storage management)

     lvm
     #inside lvm
     lvextend -L +5G /dev/first_vg/first_lv
    

Conclusion

Understanding Linux volumes and AWS EBS is essential for effective storage management. Using LVM with EBS offers flexibility and scalability, ensuring optimal performance for cloud and on-premises environments.

15
Subscribe to my newsletter

Read articles from Nenis Rudani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nenis Rudani
Nenis Rudani

🌟 Hello , I am Nenis Rudani, a passionate tech enthusiast carving my path as a DevOps maven and cloud sorcerer. My journey blends curiosity, innovation, and an insatiable appetite for building scalable systems and automating the mundane.