Increase Linux LVM Space Print

  • 277

METHOD #2: Partitions are LVM based

Here are the steps that I roughly followed to resize a KVM guest that used LVM internally.

Shutdown the VM
add more space to the guest's "image file" (something like: cat old.img 10G_addon.raw >> new.img
start the VM (using the newly created new.img)
run fdisk inside VM and delete & re-create LVM partition

% fdisk /dev/vda
...
Device Boot Start End Blocks Id System
/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 3263 26105625 8e Linux LVM

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

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/vda1 * 1 13 104391 83 Linux

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-5874, default 14): 14
Last cylinder or +size or +sizeM or +sizeK (14-5874, default 5874):
Using default value 5874

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 5874 47078482+ 83 Linux

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

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 5874 47078482+ 8e Linux LVM

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

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.
%
Reboot the VM

Resize the LVM physical volume

% pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name VolGroup00
PV Size 24.90 GB / not usable 21.59 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 796
Free PE 0
...

% pvresize /dev/vda2

% pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name VolGroup00
PV Size 44.90 GB / not usable 22.89 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 1436
Free PE 640
...
Resize the LVM Logical Volume

% lvresize /dev/VolGroup00/LogVol00 -l +640
Extending logical volume LogVol00 to 43.88 GB
Logical volume LogVol00 successfully resized
Grow the File system

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


Was this answer helpful?

« Back