Add an EBS to a running EC2 instances with logical volume.
We are familiar with the technology LVM and we have hands on experience with LVM. Here I am explaining the steps that helps you to attach a disk (EBS) to an already running instance with LVM enabled.
You need to upgrade the disk space on your instance, once your business grows, data increases; so the better option is keeping the disk as logical volume.
If it’s LVM based, we can simply increase the disk without shutting down the machine, which means with zero down time.
How to check the storage device management technology is LVM?
Yeah, we need the current disk running as logical volume, so that we can add more disk to that volume group. We can find out this from the server CLI by using the df command.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.8G 6.3G 1.5G 82% / devtmpfs 3.9G 68K 3.9G 1% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/mapper/vg1-lv1 79G 44G 32G 59% /mnt/data
Consider the case your disk is running out of space. Please follow the steps pasted below to create and attach a new disk to this volume group.
Step 1. Log into AWS console.
Step 2. Create a new volume and attach that volume to your running EC2 instance.
Step 3. Now you can list the new disk from the server using fdisk -l command.
Step 4. To check the current volume group details you can use the command vgdisplay.
Step 5. Format the newly added disk.
Step 6. Create physical volume on newly added disk.
Next we will use the pvcreate command to create a physical volume for later use by the LVM.
Step 7. Extend the current volume group with new disk.
To extent the current volume group you can use the following command:
vgextend vg-name /dev/xvdg
Step 8. Now execute the vgdisplay again to change the disk change.
Step 9. Confirm the physical volumes status using pvscan.
Step 10. Increase logical volume size.
Yeah, now your volume group has enough size, so we can increase the size of logical volume. Use the following command to list logical volume name and details:
Then we need to increase the logical volume size.
lvextend /dev/vg1/lg1 /dev/sdg
Step 11. Resize logical volume using resize2fs.
That’s it. Now check the df -h command, you can see the difference now.
1. How to redirect non www request to www domain – AWS route 53
2. Automated backup job using AWS Lambda
4 thoughts on “Attach new disk (EBS) to a running EC2 instance with LVM enabled”
Thank you So much bro, it helps a lot.one thing is worked with you awesome experience…..Miss you bro….
Very much happy to know Veera 🙂
I miss you guys too..