Description of the environment
Hypervisor: VMware vSphere 6.5
OS: SUSE Linux Enterprise Server 12 SP1
Kernel: 3.12.69-60.64.32-default
Filesystem: xfs/ext4

Using LVM.

To day I want to show you how to expand the filesystem of a virtual machine without any downtime.
On the web there are a very huge number of articles that explain how to do that, but I wasn’t able to find one with all the steps reported below.

Identify the device that hosts the LVM

hostname:~ # df -h
File system                                    Dim. Usati Dispon. Uso% Montato su
/dev/mapper/vg--test-lvm--test                  16G   44M     15G   1% /media

hostname:~ # vgscan
  Found volume group "vg-test" using metadata type lvm2

hostname:~ # pvscan
PV /dev/sdf1   VG vg-test          lvm2 [16,00 GiB / 0    free]

Now that you have discovered the name of the device that you want to expand (/dev/sdf) proceed from VMware

Rescan the device

hostname:~ # echo 1 > /sys/block/sdf/device/rescan
hostname:~ # /sbin/multipathd restart

Check the new device size

hostname:~ # fdisk -l
Disk /dev/sdf: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0a826a18

Device     Boot Start      End  Sectors Size Id Type
/dev/sdf1        2048 33554431 33552384  16G 8e Linux LVM

Disk /dev/mapper/vg--test-lvm--test: 16 GiB, 17175674880 bytes, 33546240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Create a partiton with the new space and tag it as Linux LVM type

hostname:~ # fdisk /dev/sdf

Welcome to fdisk (util-linux 2.25).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Comando (m per richiamare la guida): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Numero della partizione (2-4, default 2): 2
First sector (33554432-41943039, default 33554432):
Last sector, +sectors or +size{K,M,G,T,P} (33554432-41943039, default 41943039):

Created a new partition 2 of type 'Linux' and of size 4 GiB.

Comando (m per richiamare la guida): t
Numero della partizione (1,2, default 2): 2
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Comando (m per richiamare la guida): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Dispositivo o risorsa occupata

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

Reload partition table

hostname:~ # partprobe

Create the new physical volume

hostname:~ # pvcreate /dev/sdf2

Extend the volume group with the newly created physical volume

hostname:~ # vgextend vg-test /dev/sdf2

Extend the LVM inside of the volume group

hostname:~ # lvextend -l +100%FREE vg-test/lvm-test

Resize the filesystem:

hostname:~ # resize2fs /dev/mapper/vg--test-lvm--test


By Valerio