CENTOS virtual Machine Resize

I installed Windows in a virtual machine on my CENTOS server but I ran out of room in the windows machine, is there a simple way to rezise the file to give more space to the windows OS?
georgopanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
Which version of Windows is in your guest?
0
Daniel HelgenbergerCommented:
There is, indeed. I suppose you are using libvirt / qemu and a image file as virtual drive?
If not, please elaborate further.

1. Shut down the windows guest
2. A generic command would be, assuming you did not change any default values:
qemu-img resize /var/lib/libvirt/images/<windows-boot>.img +20GB

Open in new window

This works for all kind of images. Replace the <GB> by something you like.
3. Now, boot the windows guest and go to disk management. There you will see the new 'unallocated' space you added. Right click on the active partition and choose "Extend partition". This works with windows starting at XP (i think, never tried it on an earlier version) (Guide with pictures here)

If you use a dedicated or special device for your VM boot disk, please elaborate what you use.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
georgopanosAuthor Commented:
Windows server 2008

The command

qemu-img resize /var/lib/libvirt/images/<windows-boot>.img +20GB

is not working it just lists a command syntax.
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Daniel HelgenbergerCommented:
Please specify if you use KVM or VMware.
In that command, you have to change <windows boot>.img to your actual file name.
Please post more details (hypervisor, settings for your vm), otherwise no one will be able to help you in a more specific way.
0
georgopanosAuthor Commented:
I installed CENTOS 5.9 with the XEN kernel and desktop GNOME. I ran the virt-manager and created a new virtual machine from an ISO of Windows 2008 Server.

This is the output after running the qemu-img command

[root@new-host-9 wml]# qemu-img resize winserver +10G
qemu-img version 0.9.1, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility

Command syntax:
  check [-f fmt] filename
  create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]
  commit [-f fmt] filename
  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename
  info [-f fmt] filename
  snapshot [-l|-a snapshot|-c snapshot|-d snapshot] filename
  rebase [-u] -b backing_file [-F backing_fmt] filename

Command parameters:
  'filename' is a disk image filename
  'base_image' is the read-only disk image which is used as base for a copy on
    write image; the copy on write image only stores the modified data
  'output_base_image' forces the output image to be created as a copy on write
    image of the specified base image; 'output_base_image' should have the same
    content as the input's base image, however the path, image format, etc may
    differ
  'fmt' is the disk image format. It is guessed automatically in most cases
  'size' is the disk image size in kilobytes. Optional suffixes 'M' (megabyte)
    and 'G' (gigabyte) are supported
  'output_filename' is the destination disk image filename
  'output_fmt' is the destination format
  '-c' indicates that target image must be compressed (qcow format only)
  '-e' indicates that the target image must be encrypted (qcow format only)
  '-6' indicates that the target image must use compatibility level 6 (vmdk format only)
  '-u' enables unsafe rebasing. It is assumed that old and new backing file
       match exactly. The image doesn't need a working backing file before
       rebasing in this case (useful for renaming the backing file)

  Parameters to snapshot subcommand:
    'snapshot' is the name of the snapshot to create, apply or delete
    '-a' applies a snapshot (revert disk to saved state)
    '-c' creates a snapshot
    '-d' deletes a snapshot
    '-l' lists all snapshots in the given image

Supported format: parallels qcow2 vvfat vpc bochs dmg cloop vmdk qcow cow host_device raw
[root@new-host-9 wml]# [root@new-host-9 wml]# qemu-img resize winserver +10G
  check [-f fmt] filename
  create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]
  commit [-f fmt] filename
  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename
-bash: [root@new-host-9: command not found
  info [-f fmt] filename
[root@new-host-9 wml]# qemu-img version 0.9.1, Copyright (c) 2004-2008 Fabrice Bellard
-bash: syntax error near unexpected token `('
  'output_base_image' forces the output image to be created as a copy on write
[root@new-host-9 wml]# usage: qemu-img command [command options]
  'output_filename' is the destination disk image filename
  'output_fmt' is the destination format
  '-c' indicates that target image must be compressed (qcow format only)
  '-e' indicates that the target image must be encrypted (qcow format only)
-bash: usage:: command not found
  '-6' indicates that the target image must use compatibility level 6 (vmdk format only)
  '-u' enables unsafe rebasing. It is assumed that old and new backing file
[root@new-host-9 wml]# QEMU disk image utility

  Parameters to snapshot subcommand:
    'snapshot' is the name of the snapshot to create, apply or delete
    '-a' applies a snapshot (revert disk to saved state)
-bash: QEMU: command not found
    '-c' creates a snapshot
    '-d' deletes a snapshot
[root@new-host-9 wml]#
[root@new-host-9 wml]# Command syntax:
-bash: Command: command not found
[root@new-host-9 wml]#   check [-f fmt] filename
    '-l' lists all snapshots in the given image
-bash: check: command not found
[root@new-host-9 wml]#   create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]
-bash: create: command not found
[root@new-host-9 wml]#   commit [-f fmt] filename
-bash: commit: command not found
[root@new-host-9 wml]#   convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename
0
Daniel HelgenbergerCommented:
Hello,
please to post some useful info. I still do not know witch hypervisor you use (i suppose KVM..)

Ok, please open virt-manager. Locate your vm. Locate the disk drive your vm boots from. Then, look for a file name. Use the qemu-img command with this file.

If you are unable to do so, make sure the vm is running.
Then run:
virsh list
You get a listing of your running machines; please remember the domain ID.
Then run and post the output (please use the code tags for your post):
virsh dumpxml <put the domain id from virsh list here>
0
georgopanosAuthor Commented:
I hope I did this correct to make this more understanding.

[root@new-host-9 wml]# qemu-img info winserver
image: winserver
file format: raw
virtual size: 10G (10800332800 bytes)
disk size: 10G

[root@new-host-9 wml]# virsh list
 Id Name                 State
----------------------------------
  0 Domain-0             running
  1 Windows2008          idle
  2 server               idle


[root@new-host-9 wml]# virsh dumpxml server
<domain type='xen' id='2'>
  <name>server</name>
  <uuid>345ef0a1-eb96-e909-8f6f-82d2f8207f9b</uuid>
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type>hvm</type>
    <loader>/usr/lib/xen/boot/hvmloader</loader>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
    <disk type='file' device='disk'>
      <driver name='file'/>
      <source file='/home/wml/winserver'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='file'/>
      <source file='/home/wml/en_windows_server_2008_r2_standard_enterprise_datacenter_web_vl_build_x64_dvd_x15-59754.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
    </disk>
    <interface type='bridge'>
      <mac address='00:16:3e:15:93:c8'/>
      <source bridge='xenbr0'/>
      <script path='vif-bridge'/>
      <target dev='vif2.0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/4'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5902' autoport='yes' keymap='en-us'/>
  </devices>
</domain>
[root@new-host-9 wml]# virsh dumpxml server
<domain type='xen' id='2'>
  <name>server</name>
  <uuid>345ef0a1-eb96-e909-8f6f-82d2f8207f9b</uuid>
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type>hvm</type>
    <loader>/usr/lib/xen/boot/hvmloader</loader>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
    <disk type='file' device='disk'>
      <driver name='file'/>
      <source file='/home/wml/winserver'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='file'/>
      <source file='/home/wml/en_windows_server_2008_r2_standard_enterprise_datacenter_web_vl_build_x64_dvd_x15-59754.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
    </disk>
    <interface type='bridge'>
      <mac address='00:16:3e:15:93:c8'/>
      <source bridge='xenbr0'/>
      <script path='vif-bridge'/>
      <target dev='vif2.0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/4'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5902' autoport='yes' keymap='en-us'/>
  </devices>
</domain>

Open in new window

0
Daniel HelgenbergerCommented:
Ok,
so 'server' is the vm witch needs to be resized?

If so, shut it down with
virsh shutdown server
or from the guest itself.
then run:
qemu-img resize /home/wml/winserver +<put the additional size in GB here>GB

If the image is raw, make sure you have enough free disk space. You can check the format with:
qemu-img info /home/wml/winserver
any time.

After the resize start server again and do the file system extension. Follow my first post.
0
georgopanosAuthor Commented:
That is what I did in my first post I followed everything you said and it did not work. Unless there is some type of syntax missing, and yes the image is raw. I have plenty of space there is a terabyte drive in the system.
0
Daniel HelgenbergerCommented:
Try adding the format then,
qemu-img resize -f raw ....
0
georgopanosAuthor Commented:
it did not work!
could the version of qemu be the issue I am using 0.9.1
0
georgopanosAuthor Commented:
OK thats what it was found an RPM of a newer version and it worked thanks.
0
Daniel HelgenbergerCommented:
True. Just looked, CentOS 5 is too old for resize it seems.
You need to perform the steps qemu dos manually:
1. Create a new image, it needs to be the size you want to extend:
qemu-img create -f raw temp.img 10GB

Open in new window

2. Then, copy both images in one larger image:
cat /home/wml/winserver temp.img > /home/wml/winserver-new.img

Open in new window

3. At the end, use virsh edit to change the relevant section in the definition XML, change the <source file> section of your IDE disk, add -new.img at the end:
virsh edit server
...
driver name='file'/>
      <source file='/home/wml/winserver-new.img'/>
      <target dev='hda' bus='ide'/>
...

Open in new window

save the file, start the vm and delete the temp.img and the old boot image if everything runs smoothly.

PS: If possible, try upgrading to CentOS 6 and use libvirt. This is by far better then XEN on Cent5, and as you can see some important tools are updated as well.
0
Daniel HelgenbergerCommented:
Glad it worked out finally. As you can see, resize is way better and faster than the copy method. And sorry, I was using my mobile phone and it was impossible to look through the output of qemu-img, thats why I was asking for the code tags for the definition. ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VMware

From novice to tech pro — start learning today.