DEV Community

loading...
AWS Community Builders

How to increase/decrease FileSystem under LVM

Arun Kumar
AWS Community Builder
・2 min read

Steps

a. Before starting, ensure the following packages are installed

e2fsprogs
lvm2
Enter fullscreen mode Exit fullscreen mode

b. Run pvdisplay to check which EBS is under LVM.

sudo pvdisplay
Enter fullscreen mode Exit fullscreen mode

c. Run vgdisplay to check unallocated space available for a volume group

sudo vgdisplay
Enter fullscreen mode Exit fullscreen mode

d. Find the lvm fs that you want to increase/decrease.

sudo lvscan
Enter fullscreen mode Exit fullscreen mode

e. Example: Increase vol17 size from 5Gb to 15Gb

>>lvextend -L15G /dev/vgs1/vol17 --resizefs
Enter fullscreen mode Exit fullscreen mode

f. Example: Reduce vol17 size from 5Gb to 1Gb ( you can only do this if no process is holding to the fs. Best is to unmount the fs)

  • Important to ensure package e2fsprogs is installed, else the below command can cause superblock/partition table corruption.
>>lvreduce -L1G /dev/vgs1/vol17 --resizefs
Enter fullscreen mode Exit fullscreen mode

g. If the EBS is resized, then need to do the following, example /dev/xvdg was resize from 950Gb to 1150Gb

lsblk
> growpart /dev/xvdg 1
Enter fullscreen mode Exit fullscreen mode

h. Resize the physical volumes using the pvresize command.

pvresize /dev/xvdg1
Enter fullscreen mode Exit fullscreen mode

i. Use vgdisplay to see the increased free size. To see what fs type that the LVM fs is run,

lsblk -f
Enter fullscreen mode Exit fullscreen mode

j.
i. If you are restoring an EBS snapshot with LVM, after mounting the restored EBS volume, then you need to do the below.

sudo yum install lvm2 (if lvm command not found )
sudo vgchange -ay
Enter fullscreen mode Exit fullscreen mode

ii. If doing pvdisplay shows an unknown physical volume, then run command

vgreduce — removemissing <VG NAME>
Enter fullscreen mode Exit fullscreen mode

k. To increase swap space under LVM, do the following

>>swapoff -v /dev/vgs1/vol54swap
Enter fullscreen mode Exit fullscreen mode

Disable the vol that contain the swap, might need to stop appls if swap is in-use and free memory not available.

>>lvextend -L32G /dev/vgs1/vol54swap
>>mkswap /dev/vgs1/vol54swap
>>swapon -va
>>cat /proc/swaps
Enter fullscreen mode Exit fullscreen mode

l. If the disk increased is greater than 2Tb and is using MBR partition type, you need to convert to GPT partition type.

gdisk /dev/nvme1n1
Enter fullscreen mode Exit fullscreen mode

[https://superuser.com/questions/1250895/converting-between-gpt-and-mbr-hard-drive-without-losing-data]

Discussion (0)