How to extend Linux LVM disk
First of all (prerequisite) extend volume on virtualization platform, or add a new disk.
Login to the machine with the extended disk.
To get an overview and find the next partition in the row, do (if sda) the "p"-command in fdisk:
$ fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 146.1 GB, 146163105792 bytes
255 heads, 63 sectors/track, 17769 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 17769 142625070 8e Linux LVM
Stay in the fdisk-interface.
Create new partition, eg. sda3. Partition with Linux LVM fdisk partition ID: 8e.
For new partition do the "n"-command, for new, and then "p" for primary partition:
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
If eg. sda2 was the last partition of you sda-device, write the next number in the row:
Partition number (1-4): 3
Press enter, and enter again, when choosing first and last cylinder, to dedicate the rest of your disk to the new partition.
The partition should now be created. Time to format it for LVM. Write "t", and choose the partition you just made:
Command (m for help): t
Partition number (1-5): 3
/dev/sda3 has been chosen. Write "8e", which is the format ID for LVM. See a list with "L":
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
You are almost done! Everything is saved in memory at the moment. Write the new disk with "w":
Command (m for help): w
The partition table has been altered!
...
Reboot the machine, or rescan disk. I will just reboot:
$ reboot
When ready... create new physcial volume:
$ pvcreate /dev/sda3
Check if it is OK with pvdisplay:
$ [root@hostname01 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_hostname01
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID 3c0kQp-B3NH-htw9-Kq9E-IYXS-ho02-Q0e7pW
--- Physical volume ---
PV Name /dev/sda3
VG Name vg_hostname01
PV Size 80.00 GiB / not usable 2.69 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 20479
Free PE 0
Allocated PE 20479
PV UUID He2LPw-CGMU-WVYW-QzEd-xnrx-W5Di-HyOEvN
Find name of volume group with vgdisplay:
$ vgdisplay
--- Volume group ---
VG Name vg_hostname01
...
Extend volume group with new LVM partition:
$ vgextend vg_hostname01 /dev/sda3
Find name of Logical volume with lvdisplay + df, of Logical volume you want to extend:
$ [root@hostname01 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_hostname01/lv_root
$ [root@hostname01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hostname01-lv_root
96G 1.8G 90G 2% /
...
Extend Logical volume with everything Volume group got:
$ lvextend -l +100%FREE /dev/vg_hostname01/lv_root
Now, resize filesystem, with the resize2fs-command:
$ resize2fs /dev/vg_hostname01/lv_root
Your extended LVM disk should now be ready to use!