Sometimes you need to extend the existing volume group to be able to add free space to the logical volumes in there.
Look at this situation:
[root@localhost ~]# vgs data VG #PV #LV #SN Attr VSize VFree data 1 1 0 wz--n- 39.99g 0
The VG “data” has no free space anymore that I could add to one of the logical volumes that belong to this VG. So I need a new HDD. Assume you’ve got a new HDD in your server and you are going to add the new space to the existing volume group in your LVM-based system. Below are the steps you have to do.
Add a new HDD
Depending on your configuration you’ve got a new HDD. I cannot describe this here, so I assume you simply got /dev/sdc.
Create a new partition
Use fdisk /dev/sdc to create a new partition. I use to create an partition of type extended and then a logical disk in there. Then I set the partition type to “8e” that means “Linux LVM”:
[root@localhost ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x64e9bcd4. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off themode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sdc: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x64e9bcd4 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 1 First cylinder (1-5221, default 1): <ENTER> Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): <ENTER> Using default value 5221 Command (m for help): p Disk /dev/sdc: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x64e9bcd4 Device Boot Start End Blocks Id System /dev/sdc1 1 5221 41937651 5 Extended Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (1-5221, default 1):<ENTER> Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221):<ENTER> Using default value 5221 Command (m for help): p Disk /dev/sdc: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x64e9bcd4 Device Boot Start End Blocks Id System /dev/sdc1 1 5221 41937651 5 Extended /dev/sdc5 1 5221 41937619+ 83 Linux Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Create a new PV
This is the picture before:
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 system lvm2 a-- 9.50g 3.75g /dev/sdb5 data lvm2 a-- 39.99g 0
Now I’m creating a new physical volume based on the partition created before:
[root@localhost ~]# pvcreate /dev/sdc5 Physical volume "/dev/sdc5" successfully created [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 system lvm2 a-- 9.50g 3.75g /dev/sdb5 data lvm2 a-- 39.99g 0 /dev/sdc5 lvm2 --- 39.99g 39.99g
Extend the VG
After I’ve created a new physical volume, I’m extending the existing volume group:
[root@localhost ~]# vgextend data /dev/sdc5 Volume group "data" successfully extended
As you can see below the extended VG “data” has now almost 40 GByte free space:
[root@localhost ~]# vgs data VG #PV #LV #SN Attr VSize VFree data 2 1 0 wz--n- 79.98g 39.99g