π Volume Management in Linux & AWS EBS π½
3 min read
Volumes in Linux and AWS Elastic Block Store (EBS) are essential for managing storage. Letβs explore how to create, manage, and mount volumes step-by-step.
ποΈ Introduction to Linux Volumes and AWS EBS
-
AWS EBS: Elastic Block Store provides external block storage for AWS instances.
Key Commands:
lsblk
: Lists all available block devices.df
-h
: Displays disk space usage.
π οΈ Creating and Attaching Volumes
Steps to Create Volumes in AWS EBS
Go to AWS Management Console and navigate to EC2.
Select "Elastic Block Store" under storage.
Create three volumes: ( For Example )
10 GB
12 GB
14 GB
Note: Your Instance volume already show in Dashboard.
Set volume size and choose the same availability zone as your instance.
Click "Create Volume".
Note: Snapshot ID is optional unless restoring from a backup.
Attaching Volumes to an Instance
Go to the "Volumes" section and select the volume ID.
Click on "Actions" > "Attach Volume".
Choose the instance and specify the device name (e.g.,
/dev
/sdf
).Repeat for other volumes, using
/dev/sdg
and/dev/s
dh
for the second and third volumes.
Verify Attachment:
Attached volumes appear as
xvdf
,xvdg
, andxvdh
.
π Physical vs. Logical Volumes & Volume Groups
Physical Volume (PV)
Multiple physical volumes can be grouped into a Volume Group (VG).
Volume Groups (VG)
Example: Combine 10 GB, 12 GB, and 14 GB volumes into a 36 GB group.
Logical Volume (LV)
- Logical partitions created from volume groups for specific needs.
π Using LVM (Logical Volume Manager)
Creating Physical Volumes
lvm> pvcre
ate /dev/xvdf
/dev/xvd
g /de
v/xvdh
lvm
>
pvs
Detailed info on physical volumes
lvm> p
vdisplay
Creating Volume Groups
l
vm> vgcrea
te <grou
p_nam
e>_
vg /dev/
x
vdf
/dev/xvdg
lvm> vgs
( List volume groups )
lvm> vgdisplay
( Detailed info on volume groups )
Creating Logical Volumes
lvm> lvcreate -L 10G -n <
logical_
volum
e_name>_lv <
v
olume_gr
oup_n
ame>_vg
lv
m> lvdisplay
( Detailed info on logical volumes )
π Mounting Volumes
Steps to Mount Volumes
Create a directory for mounting:
mkdi
r /mnt/<logi
c
al_volum
e_nam
e>_mount
Format the volume:
mk
fs.ext4 /dev
/<volume_group_na
me>/<log
ical_
volume_
name>
Mount the volume:
mount /dev/<volume_group_name>/<
logical_
volum
e_name
> /mnt/<
logic
al_volume_na
me>_mount
Verify Mounting:
Run
lsblk
anddf -h
to check mounted volumes.
Unmounting Volumes:
umoun
t /mnt/<logical_volume_na
me>_moun
t
π AWS EBS Management on EC2 Instances
Format and Mount EBS Volume
Create a directory:
mkdir /m
nt/<v
olume_name>
Format the disk:
mkfs -t ext
4 /dev/xvdh
Mount the disk:
mount
/dev/xvdh /
mnt/<disk_name>
Verify with:
df -h
π Dynamic Storage Management with LVM
Extending Logical Volumes
lvm> lvex
tend -L +5G -n
<logical
_volu
me_name> <vo
lu
me_group
_name
>
Resizing Filesystem
Sometimes errors occur. To fix:
lvm>
lvres
ize -L +
5G /dev/
<volu
me_group_pat
h>/<logi
cal_volu
me_na
me>
Verification
- Use
df -h
andlsblk
to confirm changes.
β‘ Difference Between Volume Attach and Volume Mount
Volume Attach: Adding a block or disk to an instance.
Volume Mount: Binding the block or disk for usability in the system.
π Conclusion
Managing volumes using Linux and AWS EBS is crucial for storage efficiency. From creating and attaching to logical grouping and dynamic resizing, mastering these steps empowers you to handle data with ease. Start exploring volume management today!