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?
Best Answer
You need to expand
sdb1
to cover all available disk space. Then, you canpvresize /dev/sdb1
andlvextend -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 thesdb1
partition, which needs to be absolutely identical to what you now have (except for the lenght/size, of course). I strongly suggest you to usefdisk -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.