Tuesday, October 30, 2018

AWS EC2 LVM Expansion !



LVM Expansion on AWS EC2 Instance


SCENARIO #1

In this scenario, the EC2 instances has EBS Storage 400G attached. But only 50G is being use by LVM for different LVM partitions. We are extending the Partition sizes to bigger sizes. 
Please see the below steps 


If you look at the below screenshot, It has two disks attached. 
1. Root disk - 400G
2. EBS volume - 400G
    
Which got multiple partitions but only 50G is being used from 400G. so we are extending the LVM partitions to bigger size. Especially /home, /tmp and /var which are more important to have a good available space. since it will fill it very fast with data and log file. which might cause the OS to freeze so forth.
#lsblk  - It will list out all the block devices attached to the instance



If you look at the below screenshot - it has following filesystems mounted. Please look at the /dev/mapper* these are coming from EBS Volume as LVM partitions. so we will be expanding these partitions to be of bigger size. 



Here are the steps: 
Since LVM Works on 3 different Things 
PV - Physical volume 
VG - Volume Group
LV - LVM Volume 

Before Extending the LVM partitions, we need to make sure the "vgdisplay" show enough available/free space, so that we can do the lvextend. if vgdisplay shows there is no available/free space, then we might have to increase the size of "volume group" by adding Physical Volumes (PV) or pvresize. pvresize facilitate if any free space available on the EBS disk, it will add it to the volume group. 


1. pvresize --setphysicalvolumesize 100G /dev/xvdb
     or
    pvresize /dev/xvdb 
2.pvdisplay 
3. vgextend RootVG /dev/xvdb
   note: Here in my case Volume Group name is "RootVG"
4. vgdisplay 
   note: you should see available blocks 
5. lvextend -L+20G /dev/RootVG/varlv
6. xfs_growfs /var

It should expand the /var partition by 20G more. You can confirm by using df -h command. same fashion you can continue which ever partitions you would like to expand.


SCENARIO #2 

Let say your current EBS volume there is not enough free Space but you would like to expand your LVM partitions to bigger size. In this case we can consider following cases

1. Resizing our Current EBS Volume to bigger size by creating snapshot 
a. stop an EC2 instance to which volume is attached
b. right-click the volume and choose create snapshot
c. right-click the volume and choose detach volume
d. Go to the snapshots section and right click the snapshot. choose create volume and then specify new volume size
Note: Make sure that new volume and your ec2 instance are within the same "Availability Zones"
e. Go back to the volumes, right click your volumes. choose attach volumes and click the EC2 instance you wish to attach the volume
Then you can follow the  "pvresize" and vgextend and lvextend.

2. Let's say you don't want to resize the current EBS volume, then you can create a whole new EBS volume and attach it to the Ec2 instance
New EBS volume to EC2 linux instance
a. Go over the Ec2 -> volumes and create a new volume of your preferred size and type
b. select the created volume, right-click and select the "attach-volume" option
c. select the instance from the instance text box and specify the device name
d. now login to the Ec2 instance and list the available disks
#lsblk
You would be able to see the new disk.

now using fdisk /dev/device name you can create a LVM partition then you can do
#pvcreate /dev/device_name
#vgextend vol_group pv_device
#vgdisplay
#lvextend
#lvdisplay 



Thursday, October 11, 2018

Linux Helpful One Liners !




find / sed / search / replace 


find /opt/test/ -type f -exec sed -i -e 's/hello/gyani/g' {} \;