====== Increase_size_of_raw_disk_image_with_partitions ======
So there are a few ways out there for this. There is also a new virt-resize tool for resizing a VM disk with partitions. Having LVM inside the VM guest is another method.
This method covers:
* Using LV (lvm) for a Guest (which has partitons, one for root and one for swap.)
====== Increase Size of LV ======
lvresize -L+5G /dev/vg0/deb02
//adds 5GB to the lv
====== Use fdisk to recreate partitions ======
Carefully, we can use fdisk to delete and recreate partitions to include the newly created free space.
All going well, this method should leave all information intact. Use dd to backup the LV firstly if you so wish.
**fdisk /dev/vg0/deb02**
The number of cylinders for this disk is set to 3263.
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/vg0/deb02: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000505b9
Device Boot Start End Blocks Id System
/dev/vg0/deb02p1 * 1 2496 20049088+ 83 Linux
/dev/vg0/deb02p2 2497 2610 915705 5 Extended
/dev/vg0/deb02p5 2497 2610 915673+ 82 Linux swap / Solaris
Command (m for help): **d**
Partition number (1-5): **5**
Command (m for help): **d**
Partition number (1-5): **2**
Command (m for help): **d**
Selected partition 1
Command (m for help): **p**
Disk /dev/vg0/deb02: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000505b9
Device Boot Start End Blocks Id System
Command (m for help): **n**
Command action
e extended
p primary partition (1-4)
**p**
Partition number (1-4): **1**
First cylinder (1-3263, default 1):****
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-3263, default 3263): **+24G**
Command (m for help): **p**
Disk /dev/vg0/deb02: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000505b9
Device Boot Start End Blocks Id System
/dev/vg0/deb02p1 1 2919 23446836 83 Linux
Command (m for help): **n**
Command action
e extended
p primary partition (1-4)
**p**
Partition number (1-4): **2**
First cylinder (2920-3263, default 2920): ****
Using default value 2920
Last cylinder or +size or +sizeM or +sizeK (2920-3263, default 3263): ****
Using default value 3263
Command (m for help): **p**
Disk /dev/vg0/deb02: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000505b9
Device Boot Start End Blocks Id System
/dev/vg0/deb02p1 1 2919 23446836 83 Linux
/dev/vg0/deb02p2 2920 3263 2763180 83 Linux
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 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
====== Check the Partition and resize2fs ======
kpartx -av /dev/vg0/deb02
e2fsck -f /dev/mapper/vg0-deb02p1
resize2fs /dev/mapper/vg0-deb02p1
e2fsck -f /dev/mapper/vg0-deb02p1
mkswap /dev/mapper/vg0-deb02p2
kpartx -dv /dev/vg0/deb02
====== Boot VM and fix swap partition ======
Start the KVM VM with virsh. All worked well for me. After booting, I had to fix up the swap. Here is what I done for that when logged into the VM:
df -h 'check new 20GB file size.
free 'see that there is no swap.
ls /dev/vda*
swapon /dev/vda2
vi /etc/fstab
/dev/vda2 none swap sw 0 0
References:
http://buffalo.nas-central.org/wiki/Talk:Custom_Partitions_on_the_LS_Pro
http://itsignals.cascadia.com.au/?p=28
http://blog.jdpfu.com/2010/10/31/solved-increase-kvm-vm-image-file-size
http://xen.1045712.n5.nabble.com/AW-Increase-size-of-file-based-diskimage-with-MBR-partitions-fs-td2594510.html
http://www.scriptkiddie.org/blog/page/2/