1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Extending VM Hard Drives

Discussion in 'Proxmox VE 1.x: Installation and configuration' started by SirLouen, Apr 19, 2010.

  1. SirLouen

    SirLouen Member

    Joined:
    Mar 20, 2010
    Messages:
    69
    Likes Received:
    0
    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!
     
  2. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    11,726
    Likes Received:
    137
    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
     
  3. SirLouen

    SirLouen Member

    Joined:
    Mar 20, 2010
    Messages:
    69
    Likes Received:
    0
    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
     
  4. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    11,726
    Likes Received:
    137
    20971520 is 10 GB, if you need 20 GB, use 41943040.
     
  5. SirLouen

    SirLouen Member

    Joined:
    Mar 20, 2010
    Messages:
    69
    Likes Received:
    0
    It worked just perfect

    Thanks again tom! :D
     
  6. sub3xt1

    sub3xt1 Member

    Joined:
    Sep 9, 2009
    Messages:
    44
    Likes Received:
    0
    what about if the vm is linux?
    any clue for me?
     
  7. udo

    udo Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 22, 2009
    Messages:
    5,138
    Likes Received:
    70
    Hi,
    resize2fs?

    Udo
     
  8. sub3xt1

    sub3xt1 Member

    Joined:
    Sep 9, 2009
    Messages:
    44
    Likes Received:
    0
    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..
     
  9. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    15,112
    Likes Received:
    148
    Because qcow2 is a complex file format - you can't simple resize it with dd
     
  10. sub3xt1

    sub3xt1 Member

    Joined:
    Sep 9, 2009
    Messages:
    44
    Likes Received:
    0
    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?
     
  11. udo

    udo Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 22, 2009
    Messages:
    5,138
    Likes Received:
    70
    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
     
  12. sub3xt1

    sub3xt1 Member

    Joined:
    Sep 9, 2009
    Messages:
    44
    Likes Received:
    0
    ok, let me examine it. thank you for your clue.

    it is an optional, right. or just it is mandatory?

    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.
     
  13. udo

    udo Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 22, 2009
    Messages:
    5,138
    Likes Received:
    70
    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).
    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
     
  14. abcmei

    abcmei New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
  15. SirLouen

    SirLouen Member

    Joined:
    Mar 20, 2010
    Messages:
    69
    Likes Received:
    0
    Nice specially for Windows XP that doesn't have this functionallity by default.

    Regards :)
     
  16. ozgurerdogan

    ozgurerdogan Member

    Joined:
    May 2, 2010
    Messages:
    312
    Likes Received:
    0
    How about decreasing size? Can same method be used?
     
  17. hack4ce

    hack4ce New Member

    Joined:
    Jul 19, 2011
    Messages:
    1
    Likes Received:
    0
    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.
     

Share This Page