Showing posts with label resize lvm online. Show all posts
Showing posts with label resize lvm online. Show all posts

Thursday, 4 January 2024

Extend LVM without partition table

 Extend LVM without partition table


This Blog is continuation of my previous blog Create LVM without partition table

In this scenario, we will extend the size of disk on VM instead of adding new disk.

Login to the VM and check if the increased size is visible. we can do this by rescanning the block device as shown below, 

#echo 1 > /sys/class/scsi_device/2:0:1:0/device/rescan --> where 2:0:1:0 is the scsi interface of  the device connected this can be identified using the lun number we have extended from vm portal and matching with lsscsi output.

#echo 1 > /sys/class/block/sdb/device/rescan --> Where sdb is the block device.

Now we will be able to see the new increased size for the disk using fdisk -l /dev/sdb or lsblk command. 

1.1 Disk Rescan

Next we can resize the PV since we have not used or created a partition table. 

Command to resize as below,
#pvresize /dev/sdb

1.2 Resize PV


Once we resize the PV, we can see the changes using pvs or pvdisplay command,

VG will be reflecting the free space available automatically we do not have to extend anything as we are using the same PV instead of new PV. 

We can see the VG status using vgs or vgdisplay.

1.3 vgs output

Lets proceed with resize of LV directly using below command, 

#lvresize -l +100%FREE lv_name

1.4 LV resize


Now we can see the lv has been resized with lvs or lvdisplay command.

Now the LV has required space, filesystem can be grown using below command, 

#xfs_growfs /mount_point_name

1.5 Resize Filesystem

Once the filesystem is extended, we can see the change using df -h and its usable now. 

1.6 Resized mount

We have increased the disk space without downtime and partition table. 

Caution: When we use a partitionless LVM, we also need to be careful at later point in time when we add more disk, where our old disk used as LVM may also show as no partition in fdisk or parted commands. So, its recommended to use pvdisplay or pvs command validate and confirm its usage. 



Wednesday, 3 January 2024

Create LVM without partition table

 Create LVM without partition table


Earlier I had written a blog to create LVM using partition table Create File system with Linux LVM

In this blog, I will show you how to create LVM without using partition table. This is useful when you want to use a full disk for the volume instead of portion of the disk. 
This procedure will be relevant to the data disk that you will add to your system rather than the OS Disk/Partition. Also its very helpful in later stage when you need to extend the same disk instead of adding new disk in the virtual environment/cloud, LVM without partition will be very easy to handle as you can directly resize your PV and LV instead of destroying and recreating the disk and partition table. 

Lets go with creating the disk after adding new disk on vm. We have covered about how to re-scan the scsi bus in the earlier blog - Create File system with Linux LVM

To rescan the new disk - my setup has the new disk in host2 adapter.
#echo "- - -" /sys/class/scsi_host/host2/scan

1.1 Scanning SCSI Host adapter

We have now got a new disk that we added on the VM that is /dev/sdb, Let's continue to create this disk as physical volume directly instead of create a partition table with parted or fdisk.

#pvcreate /dev/sdb
Syntax - pvcreate disk_name/partition_name

1.2 Create PV
Now you can see we have a physical volume (PV) created /dev/sdb as shown above,

To create Volume Group(VG) on this new PV, you need to use vgcreate command, 

#vgcreate data_vg /dev/sdb
Where data_vg is the volume group name. 
Syntax - vgcreate VG_new PV1 PV2 ...

1.3 Create VG

LV can be created on top of this VG using lvcreate comamnd, 

Syntax - lvcreate -l +100%FREE -n LV_name vg_name

1.4 Create LV

From lsblk you can see that lvm is created successfully. 

1.5 lsblk output


Now you can create Filesystem to this Logical volume and mount it as per your requirement. 

I have formatted with XFS and mounted to /data mount point. 

1.6 XFS Format


1.7 Mount FS

I will write procedure to extend same disk and LV without having downtime in another blog.  

Wednesday, 11 August 2021

Extend Logical volume using LVM

 Extend Logical volume using LVM


I am going to extend already created xfs file system using LVM by 1GB.
Currently i have no free space in pv / vg / lv to extend it to the File system.
So i will be adding a new 1 GB disk to the VM first and then extend vg / lv.
Adding disk and making partition is explained here.

Let's continue with our work to extend pv first. 
Current pv vg and lv output as below. and you can see i have no space for now. 

1.1 Current Physical volume

1.2 Current Physical volume free space detail

1.3 Current VG details

1.4 Current LV details

I have completed adding disk and got it on the server by scanning the scsi hosts.
Lets proceed creating a new pv using the newly added disk. 
Command to create pv - pvcreate 
Syntax : pvcreate disk_name
disk_name = /dev/sdc1

1.5 pv create

Now we can extend our vg vgdata with the newly created pv as shown below,
Syntax: vgextend vgname pvname
vgname = vgdata
pvname = /dev/sdc1

1.6 vg extend



1.7 new vg details


1.7 current lv details

Now we have free space in vg, we can extend the lv,
Syntax : lvextend -L +size lvname
size = 1020MiB 
lvname = /dev/vgdata/lvdata

1.8 extend lv

You can see the newly extended size in lvs and lvdisplay command as below

1.9 new lv

LV size is extended, however this will not be visible to file system yet. we have to resize / grow the file system. I have a xfs file system so i will use xfs_growfs, if you have a older fs like ext4/3/2 you may use resize2fs.

command: xfs_growfs
Syntax : xfs_grow lvname/devicename
lvname = /dev/mapper/vgdata-lvdata

1.10 xfs grow

Once you have executed xfs_growfs for the file system you can now see the increased size in the df -h output and you can start utilizing the newly available fs. 

1.11 Extended xfs filesystem


This is the best advantage of a LVM, you can grow/extend/increase your file system space online without any need for downtime. 
LVM has many more uses like cluster support, raid features, backup/recovery.