Linux LVM Concept
Linux LVM Concept
In simple terms, LVM (Logical Volume Manager) is a tool in Linux that helps you manage your
computer’s storage. It lets you create, resize, and organize your storage space without being
stuck with the size of your hard drives or partitions.
Imagine LVM as a flexible storage organizer. You can move, resize, and even combine storage
from different hard drives to create one big storage space that’s easy to manage. It helps you
make the most of your storage and avoid running out of space.
Don’t worry if this sounds a bit complicated right now. As you read on, we’ll explain how
volumes work and how LVM fits into the picture.
volumes in Linux are like containers that hold your data. They represent storage space on your
computer or server, and you can use them to store files and programs.
These volumes can be physical (like an SSD or HDD), partitioned sections of a physical disk, or
even logical/virtual disks managed by a tool called LVM (Logical Volume Manager).
Types of Volumes
● A physical volume is the actual storage device, like an HDD (Hard Disk Drive) or SSD
(Solid State Drive).
Example: Creating a 10GB Logical Volume (LV) from a 20GB Volume Group (VG)
📌 Key Point: LVs allow for dynamic storage management, including resizing and moving.
What is AWS EBS?
AWS EBS (Elastic Block Store) is a block storage service that provides persistent storage for
Amazon EC2 instances. It behaves like a physical volume (PV) in Linux, offering block-level
storage that can be attached to instances.
I already have an EC2 instance running, but you can launch one yourself—it's a simple process.
By default, AWS provides an 8GB EBS volume with your instance unless you customize the
storage settings during creation.
`1- Lsblk -This command in Linux shows a clear list of all storage devices and their partitions.
Think of it as a map of your system's disks—it tells you what storage is available, how it's
divided, and where it's mounted.
Breaking it Down
📌 If a volume is attached but not mounted, the "MOUNTPOINT" column will be empty.
📌 If a volume is mounted, it will show the directory where it is accessible.
Difference between Attached and mounted
1️⃣ Attached:
2️⃣ Mounted:
📌 Example in AWS:
● When you attach an EBS volume to an EC2 instance, it's connected, but not usable until
you mount it to a folder (e.g., /mnt/data).
● Key Point: You can't store data on the volume until it’s mounted.
2- Df -h - This command helps monitor your filesystem(volumes) space usage and provides a
warning when storage is running low, so you can take action before running out of space.
📌 Key Point: You can see i have used filesystem and volumes interchangeably in this context
Here's why:
2️⃣ File System refers to the way data is organized and stored on that volume.
So, while "filesystem" technically refers to how data is organized on a volume, it's common to
use the term "filesystem" when talking about volumes in this context, because that's what the
df-h command reports on.
Let's roll out some additional EBS volumes and attach to our EC2 instance
I manually created volumes of sizes 10GB, 12GB, and 14GB, while the 8GB volume was
automatically created when I launched the EC2 instance.
Now that we've created the volumes, we can proceed to attach them to our EC2 instance.
📌 Key Point: Ensure you use the correct device name as per the recommended naming
conventions. I’ve named my 10 GB EBS volume as /dev/sdf, but Linux may automatically
rename it to /dev/xvdf as mentioned .
Similarly, I've attached all the volumes, and you can do the same.
Now that we've successfully attached the volumes
We previously added new volumes and named them sdf, sdg, and sdh. However, Linux
renamed them to xvdf, xvdg, and xvdh. While the volumes are present as we can see , their
mount points are empty because they have only been attached, not mounted yet .
ubuntu@ip-172-31-5-208:~$ sudo su
root@ip-172-31-5-208:/home/ubuntu#
EBS volumes, by default, are just raw devices that the operating system sees. To manage them
with LVM (Logical Volume Manager), you need to initialize them as Physical Volumes (PVs)
using the pvcreate command.
📌 Key Point: We can see that a 10GB logical volume has been created, which is currently
allocated from xvdf. In the future, if we create more logical volumes, they might be allocated
from xvdg as well.
Check Disk Space Usage with df -h
📌 Key Point :But surprisingly We can't see xvdf, xvdg, and xvdh because they are not
Before mounting, we need to create a directory where the logical volume will be accessible.
You can format any logical volume by specifying its correct path, which follows the format:
Replace <VG_NAME> and <LV_NAME> with your actual volume group and logical volume
names.
After running this command, the contents of /dev/tws_vg/tws_lv will be available inside
/mnt/tws_lv_mount.
📌
Key Point : To confirm that the logical volume has been successfully mounted, use the
df -h command:
We can see our logical volume tws_lv successfully mounted at /mnt/tws_lv_mount
Now that the logical volume is mounted, the space is ready for use.
To mount an AWS EBS volume to an EC2 instance, first, you need to create a mount point
directory where the volume will be attached.
To format an AWS EBS volume disk , you can use the following syntax:
Use the following command to mount the EBS volume (/dev/xvdh) to the mount point
(/mnt/ebs_volume)
📌 Key Point : To confirm that the logical volume has been successfully mounted, use the
df -h command:
You can see that all mounted filesystems are listed, and /dev/xvdh (the AWS EBS volume) is
mounted at /mnt/tws_diskmount. Now, you can make use of this space for storing files and
directories.
Conclusion
I hope this guide helped you understand how to efficiently manage storage on AWS EC2 using
LVM. From creating Physical Volumes to formatting and mounting AWS EBS volumes, we've
covered it all. With this knowledge, you're now equipped to manage scalable and flexible
storage effectively. Keep learning and growing!
Hare krishna 🙏