Expanding LVM Partitions in VMware

To expanded Filesystems on LVM without rebooting, by adding more partitions. 

fdisk /dev/sda

The number of cylinders for this disk is set to 9790.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.5 GB, 80530636800 bytes
255 heads, 63 sectors/track, 9790 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 104391 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 4178 33450007+ 8e Linux LVM
/dev/sda3 4178 8354 33549073+ 8e Linux LVM
/dev/sda4 8355 9137 6289447+ 8e Linux LVM

Command (m for help): q

###
### Extend the VMDK in vCenter
###

fdisk /dev/sda

The number of cylinders for this disk is set to 9790.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.5 GB, 80530636800 bytes
255 heads, 63 sectors/track, 9790 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 104391 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 4178 33450007+ 8e Linux LVM
/dev/sda3 4178 8354 33549073+ 8e Linux LVM
/dev/sda4 8355 9137 6289447+ 8e Linux LVM

Command (m for help): q

###
### Whuuuuuut? I can't see the extra space!
###

echo '1' > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan

###
### Rescan device geometry
###

fdisk /dev/sda

The number of cylinders for this disk is set to 11096.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 91.2 GB, 91268055040 bytes
255 heads, 63 sectors/track, 11096 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 104391 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 4178 33450007+ 8e Linux LVM
/dev/sda3 4178 8354 33549073+ 8e Linux LVM
/dev/sda4 8355 9137 6289447+ 8e Linux LVM

###
### Ok, that's much better.
###

Command (m for help): d
Partition number (1-4): 4

###
### Delete partition 4
###

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4

###
### Now recreate it, so it starts in the same place, and ends at the end of the disk
###

First cylinder (8355-11096, default 8355):
Using default value 8355
Last cylinder or +size or +sizeM or +sizeK (8355-11096, default 11096):
Using default value 11096

Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)

###
### Remember to change the partition type of Linux LVM. Or you'll be in trouble.
###

Command (m for help): p

Disk /dev/sda: 91.2 GB, 91268055040 bytes
255 heads, 63 sectors/track, 11096 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 104391 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 4178 33450007+ 8e Linux LVM
/dev/sda3 4178 8354 33549073+ 8e Linux LVM
/dev/sda4 8355 11096 22025115 8e Linux LVM

Command (m for help): w
The partition table has been altered!

###
### Write to disk and away we go
###

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
partprobe -s
/dev/sda: msdos partitions 1 2 3 4

###
### Reprobe partition table
###

pvresize /dev/sda4
Physical volume "/dev/sda4" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

###
### Resize the "filesystem" of the LVM partition we've just extended in fdisk,
### Think of this kind of like resize2fs for LVM, but we'll still have to do that on the logical disks later
###

vgdisplay
--- Volume group ---
VG Name systemvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 84.84 GB
PE Size 32.00 MB
Total PE 2715
Alloc PE / Size 1660 / 51.88 GB
Free PE / Size 1055 / 32.97 GB
VG UUID tSuI0o-Z3mu-mldY-n4pS-qfSZ-g5UP-tXPZlR

###
### Confirm we can now see the extra space in the LVM group
###

lvdisplay
--- Logical volume ---
LV Name /dev/systemvg/opt
VG Name systemvg
LV UUID HYQp9x-yA5H-RLJw-f033-pmEY-Lohg-loRhXa
LV Write Access read/write
LV Status available
# open 1
LV Size 7.88 GB
Current LE 252
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/systemvg/LVswap
VG Name systemvg
LV UUID ZXCxs3-nZd4-jR5S-mkCf-zTJP-yVgp-dpq7Mg
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Name /dev/systemvg/opt
VG Name systemvg
LV UUID VUv17I-QbdC-pkyr-bE25-f4MC-gLXq-2QKGr0
LV Write Access read/write
LV Status available
# open 1
LV Size 40.00 GB
Current LE 1280
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

###
### Confirm how big our logical volumes are within our LVM pool
###

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/systemvg-opt
7.7G 3.3G 4.0G 45% /
/dev/sda1 99M 24M 71M 26% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/systemvg-opt
40G 177M 38G 1% /ut01

###
### Confirm amount of space seen on filesystems within the LVM Logical Volumes
###

lvextend -L+5G /dev/systemvg/opt
Extending logical volume opt to 45.00 GB
Logical volume opt successfully resized

###
### Added 5Gb onto our Logical Volume, opt
###

lvdisplay
--- Logical volume ---
LV Name /dev/systemvg/opt
VG Name systemvg
LV UUID HYQp9x-yA5H-RLJw-f033-pmEY-Lohg-loRhXa
LV Write Access read/write
LV Status available
# open 1
LV Size 7.88 GB
Current LE 252
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/systemvg/LVswap
VG Name systemvg
LV UUID ZXCxs3-nZd4-jR5S-mkCf-zTJP-yVgp-dpq7Mg
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Name /dev/systemvg/opt
VG Name systemvg
LV UUID VUv17I-QbdC-pkyr-bE25-f4MC-gLXq-2QKGr0
LV Write Access read/write
LV Status available
# open 1
LV Size 45.00 GB
Current LE 1440
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/systemvg-opt
7.7G 3.3G 4.0G 45% /
/dev/sda1 99M 24M 71M 26% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/systemvg-opt
40G 177M 38G 1% /ut01

###
### So the space is added to the Logical Volume, but the filesystem in the logical volume is not extended
###

resize2fs /dev/systemvg/opt
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/systemvg/opt is mounted on /ut01; on-line resizing required
Performing an on-line resize of /dev/systemvg/opt to 11796480 (4k) blocks.
The filesystem on /dev/systemvg/opt is now 11796480 blocks long.

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/systemvg-opt
7.7G 3.3G 4.0G 45% /
/dev/sda1 99M 24M 71M 26% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/systemvg-opt
45G 181M 42G 1% /ut01

This will also work if your root filesystems (“/”) is on LVM.