Extending VM Hard Drives

S

SirLouen

Guest
I would like to know if its possible to extend a raw virtual HDD with a KVM machine (windows 2008) running inside it, without destroying its content.

And if possible, how may I do it.

Thanks in advance!
 
I would like to know if its possible to extend a raw virtual HDD with a KVM machine (windows 2008) running inside it, without destroying its content.

And if possible, how may I do it.

Thanks in advance!

Howto resize KVM disk (here for a Windows 2008 guest):


  1. Before playing with dd, make sure you have a valid backup
  2. power off the windows guest.
  3. locate the disk image file, e.g. cd /var/lib/vz/images/VMID
  4. Enlarge the existing raw disk image. As we got ext3 this will create a sparse image (disk space won't actually be used until non-zero data is written to the file). The value after seek = is the size of the new disk in sectors. In this case 209715200 x 512 = 100GB:
    Code:
    dd if=/dev/zero of=vm-VMID-disk-1.raw bs=512 count=0 seek=209715200
  5. restart pvedaemon to update the web interface (size of disk)
    Code:
    /etc/init.d/pvedaemon restart
  6. Start the windows 2008 and extend the partition with the windows disk manager
 
I did something similar to this recently in order to extend an iSCSI disk I had on the local network.

What I did not understand totally is about "resizing" with dd:

seek is the total extra amount or the total of the whole disk

example if I have a 10 Gb disk and I put seek=20971520(512x20971520=10Gb) then I will end with 20Gb or I will end the same I started with 10Gb

Thanks
 
I did something similar to this recently in order to extend an iSCSI disk I had on the local network.

What I did not understand totally is about "resizing" with dd:

seek is the total extra amount or the total of the whole disk

example if I have a 10 Gb disk and I put seek=20971520(512x20971520=10Gb) then I will end with 20Gb or I will end the same I started with 10Gb

Thanks
20971520 is 10 GB, if you need 20 GB, use 41943040.
 
Proxmox 1.3

i tried to extend vm 104 (backup from vm 102).
vm 104 had 50GB, and i want to extend 10GB.

** hdd is 50GB **
pmxhost:/var/lib/vz/images/104# ls -al
total 52442140
drwxr-xr-x 2 root root 4096 Apr 15 02:38 .
drwxr-xr-x 7 root root 4096 May 27 09:30 ..
-rw-r--r-- 1 root root 53648293888 May 27 10:13 vm-102-disk.qcow2

pmxhost:/var/lib/vz/images/104# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/pve/root 68G 18G 47G 27% /
tmpfs 3.9G 0 3.9G 0% /lib/init/rw
udev 10M 56K 10M 1% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/mapper/pve-data 191G 111G 81G 58% /var/lib/vz
/dev/sda1 504M 33M 446M 7% /boot

** extend 10GB **
pmxhost:/var/lib/vz/images/104# dd if=/dev/zero of=vm-102-disk.qcow2 bs=512 count=0 seek=125829120
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.3046e-05 s, 0.0 kB/s

** restart pvedaemon 2x **
pmxhost:/var/lib/vz/images/104# /etc/init.d/pvedaemon restart
Restarting PVE daemon: pvedaemon.

pmxhost:/var/lib/vz/images/104# /etc/init.d/pvedaemon restart
Restarting PVE daemon: pvedaemon.


** extended by 10GB **
pmxhost:/var/lib/vz/images/104# ls -al
total 51120516
drwxr-xr-x 2 root root 4096 May 27 03:34 .
drwxr-xr-x 7 root root 4096 May 27 09:30 ..
-rw-r--r-- 1 root root 64424509440 May 27 10:05 vm-102-disk.qcow2

but, web interface shows that hdd of vm 104 still 50 GB. why??

=====
vm: vm104
=====

[root@vm104 ~] df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 49644228 411524 99% /
/dev/sda1 101086 84006 13% /boot
tmps 517624 0 0% /dev/shm

[root@vm104 ~] vgdisplay |grep Free
Free PE / Size 0 / 0

[root@vm104 ~] resize2fs /dev/mapper/VolGroup00-LogVol00
resize2fs 1.39
The Filesystem is already 12812288 blocks long. Nothing to do!

is there something i didnt do it???
please help..
 
ok, i see the sign of your clue...
furthermore ,... help me please...

HTML:
pmxhost:/var/lib/vz/images/104# qemu-img info vm-102-disk.qcow2
image: vm-102-disk.qcow2
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 49G
cluster_size: 4096

pmxhost:/var/lib/vz/images/104# qemu-img convert -f qcow2 vm-102-disk.qcow2 -O raw vm-102-disk.raw

pmxhost:/var/lib/vz/images/104# dd if=/dev/zero of=vm-102-disk.raw bs=1M count=0 seek=61440
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.6102e-05 s, 0.0 kB/s

pmxhost:/var/lib/vz/images/104# qemu-img convert -f raw vm-102-disk.raw -O qcow2 vm-102-disk.qcow2

pmxhost:/var/lib/vz/images/104# qemu-img info vm-102-disk.qcow2
image: vm-102-disk.qcow2
file format: qcow2
virtual size: 60G (64424509440 bytes)
disk size: 47G
cluster_size: 4096
web interface also shows it is 60GB.
but, when i enter the vm, i still dont see additional harddrive...

HTML:
[root@vm104 ~] vgdisplay |grep Free
  Free PE / Size     0 / 0

[root@vm104 ~] resize2fs /dev/mapper/VolGroup00-LogVol00
  resize2fs 1.39
  The Filesystem is already 12812288 blocks long. Nothing to do!
what should i do next?
 
ok, i see the sign of your clue...
furthermore ,... help me please...

HTML:
pmxhost:/var/lib/vz/images/104# qemu-img info vm-102-disk.qcow2
image: vm-102-disk.qcow2
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 49G
cluster_size: 4096

pmxhost:/var/lib/vz/images/104# qemu-img convert -f qcow2 vm-102-disk.qcow2 -O raw vm-102-disk.raw

pmxhost:/var/lib/vz/images/104# dd if=/dev/zero of=vm-102-disk.raw bs=1M count=0 seek=61440
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.6102e-05 s, 0.0 kB/s

pmxhost:/var/lib/vz/images/104# qemu-img convert -f raw vm-102-disk.raw -O qcow2 vm-102-disk.qcow2

pmxhost:/var/lib/vz/images/104# qemu-img info vm-102-disk.qcow2
image: vm-102-disk.qcow2
file format: qcow2
virtual size: 60G (64424509440 bytes)
disk size: 47G
cluster_size: 4096
web interface also shows it is 60GB.
but, when i enter the vm, i still dont see additional harddrive...

HTML:
[root@vm104 ~] vgdisplay |grep Free
  Free PE / Size     0 / 0

[root@vm104 ~] resize2fs /dev/mapper/VolGroup00-LogVol00
  resize2fs 1.39
  The Filesystem is already 12812288 blocks long. Nothing to do!
what should i do next?
Hi,
you expand your disk but the partition table on the disk are the old one.
Look with "fdisk -l"
The esay way is to make a new partion on the free space and add them to the volume group (vgextend). Make sure you leave 4GB free in the vg for backup!

Udo
 
Hi,
you expand your disk but the partition table on the disk are the old one.
Look with "fdisk -l"
ok, let me examine it. thank you for your clue.

The esay way is to make a new partion on the free space and add them to the volume group (vgextend).
it is an optional, right. or just it is mandatory?

Make sure you leave 4GB free in the vg for backup!

Udo
i dont get the point of it. it is on host or VM??
i assign 50GB for VM, and the VM use it all... almost 50GB. so there is no 4GB left in VM.
in host, there is 45 GB left.
 
ok, let me examine it. thank you for your clue.

it is an optional, right. or just it is mandatory?
Sorry I make a mistake - you wan't to extend a client-hd not the proxmox-hd.
So it's depends on your VM-Guest. If there a linux with lvm running, you can use the way i wrote (forgot the 4GB free) with a additional partition. If you use a simple partition with ext3 or windows you can use the gparted-live-cd to expand the filesystem (boot the cd in the VM-guest).
i dont get the point of it. it is on host or VM??
i assign 50GB for VM, and the VM use it all... almost 50GB. so there is no 4GB left in VM.
in host, there is 45 GB left.
This mean you should have in the volume group pve 4GB free space. In the posting before there was show 0 free space - therefore you run in trouble with backups (the lvm-snapshot need space for the data which changed during backup and the commitment after that).


Udo
 
Nice specially for Windows XP that doesn't have this functionallity by default.

Regards :)
 
I just did this with my Ubuntu VM and it worked well. Once I used dd to resize my .raw file, I booted into gparted to finish it off. Since dd creates space at the end of .raw file, I had a disk with unallocated space at the end. In order to add this new, unallocated space to my primary partition (sda1), I had to delete the swap partition. Only after I deleted the swap partition was I able to "move" the new unallocated space over and merge it with sda1. I left 2.00 GB and remade the swap partition after I had merged the other two. I hope this will be useful to someone.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!