Assuming that you are familiar with LVM technology. Let's see how to attach a disk (EBS) to an already running instance with LVM enabled. If it’s LVM based, we can simply increase the disk without shutting down the machine, which means with zero downtime.

How to check the storage device management technology is LVM?

Let's first check, current disk running as a "logical volume", so that we can add more disk to that volume group. We can find out that from the server CLI by using the "df" command:

df -h


For example:

# 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 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.

mkfs.ext4 /dev/xvdg


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.

pvcreate /dev/xvdg


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:

lvdisplay


Then we need to increase the logical volume size.

lvextend /dev/vg1/lg1 /dev/sdg


Step 11. Resize logical volume using resize2fs.

resize2fs /dev/mapper/vg1-lv1

 

Now check the df -h command, you can see the difference now. 

For example:

# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/xvda1           7.8G  6.3G  1.5G  82% /
devtmpfs             991M   68K  991M   1% /dev
tmpfs                1002M   0  1002M   0% /dev/shm
/dev/mapper/vg1-lv1   68M   44G   21G  68% /mnt/data


That's it !!!

Hjalp dette svar dig? 0 Kunder som kunne bruge dette svar (0 Stem)