Increase the size of LVM after adding virtual disk space

1

I have asked for a hard drive upgrade for my virtual server running centos 6.5

i can see that the space has been increased as /dev/sdb now is 214.7GB and used to be 150.3GB

root@webhost [/sys/class/block/sdb/device]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes
64 heads, 32 sectors/track, 81920 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000390ad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502        3573     3145728   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3            3574       81920    80227328   83  Linux

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
64 heads, 32 sectors/track, 204800 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x796ffff3

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      143360   146800624   83  Linux

Disk /dev/mapper/backup-lv0: 150.3 GB, 150319661056 bytes
255 heads, 63 sectors/track, 18275 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

root@webhost [/sys/class/block/sdb/device]#

as you can see the current lvm size is 140GB

  --- Volume group ---
  VG Name               backup
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  15
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               140.00 GiB
  PE Size               4.00 MiB
  Total PE              35839
  Alloc PE / Size       35839 / 140.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               9WAEQb-oEXG-QdJ0-MIK9-ZEu1-x176-U76PzS

root@webhost [/sys/class/block/sdb/device]# 

how can i resize the lvm partition to match the drive's size?

linux
centos
lvm
fdisk
asked on Server Fault Dec 24, 2019 by Meni • edited Dec 25, 2019 by Meni

3 Answers

1

You need to expand sdb1 to cover all available disk space. Then, you can pvresize /dev/sdb1 and lvextend -l +100%FREE <your_volume_name>.

Background info: in RHEL6 and previous, RedHat suggested to create a "Protective MBR" to prevent old OSes from modifying the LVM metadata. This means that LVM physical volumes where partition-based, rather than disk-based (as in your case). So, to extend the physical volume, you first need to extend the partition.

However, the fdisk version shipped with RHEL6 does not support simple partition resize. You need to remove and re-create the sdb1 partition, which needs to be absolutely identical to what you now have (except for the lenght/size, of course). I strongly suggest you to use fdisk -u, which will give you partition size in sector number rather than cylinders.

Alternatively, you can use parted which should support partition resize (this feature is version-dependent and I do not remember if the one shipped with RHEL6 supports it).

Be carefull: a wrongly-recreated partition will meen DATA LOSS. I suggest you practicing on a test virtual machine before doing that in producion.

answered on Server Fault Dec 25, 2019 by shodanshok
0

You need to do a pvresize to allow LVM to recognise the additional disk. Its as simple as pvrsize /path/to/blockdevice

answered on Server Fault Dec 25, 2019 by davidgo
0

@shodanshok thank you for pointing me to the right direction

Unfortunately my lvm volume was partition based and because i did not want to delete my current partition in order to resize it(once i lost all data) i have created another partition and used it to extend the lvm. so what i did was: 1) created a new partition with

fdisk /dev/sdb

2) i initialized a physical volume for lvm managing with:

pvcreate /dev/sdb2

3) i added the new physical volume to my lvm group with:

lvextend /dev/backup/lv0 /dev/sdb2

4) finaly i resized the filesystem with:

resize2fs /dev/backup/lv0

answered on Server Fault Dec 25, 2019 by Meni

User contributions licensed under CC BY-SA 3.0