LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 03-28-2012, 07:35 AM   #1
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Rep: Reputation: Disabled
Size of vm created by qemu-img convert


I am using 'qemu-img convert' to convert a hyper-v vm into kvm. Problem is this creates the .img as the maximum virtual size (127Gb) rather than the actual machine size (24Gb) which is the size of the hyper-V file. Is there some way to set the file size during the convert?

Thanks,
 
Old 03-29-2012, 03:05 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

What's the exact command you've used?

Kind regards,

Eric
 
Old 03-29-2012, 05:22 AM   #3
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by EricTRA View Post
Hi,
What's the exact command you've used?
Eric
qemu-img convert –p –O raw ’/media/VM/Virtual hard disks/Win7Pro.vhd’ /vm/images/Win7Pro.img

Last edited by Nick_C; 03-29-2012 at 05:23 AM.
 
Old 03-29-2012, 05:27 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

You could have used qcow2 which is a compressed format instead of raw and which can be perfectly used by kvm. The type 'raw' does no compression and uses all of the space originally assigned to the 'disk'. On the other hand if you use qcow2 for example the size will be significantly smaller. I have images which original disk size is set to 25 Gb and which in reality only occupy 2.5 Gb once installed. Have a look at the man page for qemu-img.

Kind regards,

Eric
 
Old 03-29-2012, 05:30 AM   #5
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
no, but you can clean up the unused space after the conversion is done. qemu-img is able to deduplicate zero-blocks from an image, but first you need to fill the unused blocks in the VM by zeroes.

If this is a linux VM, simply use `dd if=/dev/zero of=/path/to/file` until it runs out of space, and delete that file. Then run `qemu-img convert ...` to get qemu-img to rerun over the image again, and remove the zero-filled chunks
 
Old 03-29-2012, 05:32 AM   #6
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
EDIT: sfill is another linux option

for windows, look at sdelete, from sysinternals
 
Old 03-29-2012, 07:02 AM   #7
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dyasny View Post
no, but you can clean up the unused space after the conversion is done. qemu-img is able to deduplicate zero-blocks from an image, but first you need to fill the unused blocks in the VM by zeroes.

If this is a linux VM, simply use `dd if=/dev/zero of=/path/to/file` until it runs out of space, and delete that file. Then run `qemu-img convert ...` to get qemu-img to rerun over the image again, and remove the zero-filled chunks
Unfortunately Windows 7 VM not Linux.
 
Old 03-29-2012, 07:08 AM   #8
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by Nick_C View Post
Unfortunately Windows 7 VM not Linux.
read my previous post
 
Old 03-29-2012, 07:10 AM   #9
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dyasny View Post
no, but you can clean up the unused space after the conversion is done. qemu-img is able to deduplicate zero-blocks from an image, but first you need to fill the unused blocks in the VM by zeroes.

If this is a linux VM, simply use `dd if=/dev/zero of=/path/to/file` until it runs out of space, and delete that file. Then run `qemu-img convert ...` to get qemu-img to rerun over the image again, and remove the zero-filled chunks
Can I just confirm I have understood this completely; are you saying that if I run SDelete on the Win 7 VM first, then when I run 'qemu-img convert' that will automatically create a much smaller .img output file?

Is the qemu-ing convert -S option related to this issue in any way.
 
Old 03-29-2012, 07:13 AM   #10
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by EricTRA View Post
Hi,

You could have used qcow2 which is a compressed format instead of raw and which can be perfectly used by kvm. The type 'raw' does no compression and uses all of the space originally assigned to the 'disk'. On the other hand if you use qcow2 for example the size will be significantly smaller. I have images which original disk size is set to 25 Gb and which in reality only occupy 2.5 Gb once installed. Have a look at the man page for qemu-img.
I seem to recall reading that RAW is the preferred format because it gives the fastest disk access, maybe I have got that wrong. Also a qcow2 vm cannot be resized downwards whereas a RAW vm can.
 
Old 03-29-2012, 07:18 AM   #11
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Don't know if it is going to work or not but I have decided to try:
1). Defrag each Win 7 VM internally
2). Shrink the NTFS file system within eash VM
3). qemu-image -resize to shrink the VM down to the size of the contained file system.

Next time the answer is obviously to reduce the max size of the VM forst in Hyper-V.
 
Old 03-29-2012, 07:37 AM   #12
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

It's only logical that RAW is the fastest since there's no compression/decompression involved when using the disk. On the other hand you were right about qcow2 not being able to 'downsize' the image only extend its size. I didn't know that but then again how many times would you need to downsize a qcow2 image? You could first downsize the raw format and then convert to a compressed file format like qcow2.

Kind regards,

Eric
 
Old 03-29-2012, 07:37 AM   #13
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
1. I'm not aware of -S (maybe you meant -s?)
2. RAW provides the best disk speeds, because it has the least overhead, but it's also very low on features - it can't be a snapshot for example
3. What you mean to do is going to defeat the purpose of thin provisioning completely, and will not allow your VM to expand it's virtual disk automatically.
 
Old 03-29-2012, 02:23 PM   #14
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 299

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dyasny View Post
1. I'm not aware of -S (maybe you meant -s?)
2. RAW provides the best disk speeds, because it has the least overhead, but it's also very low on features - it can't be a snapshot for example
3. What you mean to do is going to defeat the purpose of thin provisioning completely, and will not allow your VM to expand it's virtual disk automatically.
Well my intention is to reduce the VM it to a sensible size, say 40Gb, certainly not the 127Gb it has now ended-up as. It can always be expanded later if necessary by 'qemu-img resize' and then increasing the size of the VM's file system.

qemu-ing --help
Quote:
-C indicated the consecutive number of bytes that must contain only zeros for qemu-img to create a sparse image during conversion

Last edited by Nick_C; 03-29-2012 at 02:49 PM.
 
Old 03-30-2012, 05:29 AM   #15
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by Nick_C View Post
Well my intention is to reduce the VM it to a sensible size, say 40Gb, certainly not the 127Gb it has now ended-up as. It can always be expanded later if necessary by 'qemu-img resize' and then increasing the size of the VM's file system.
That _a_ way to go, but it's not the best way IMO. If you zero out the unused blocks and then shrink the image using qemu-img, you will not have tp change the partition size, since the VM will keep believing it has the full size (and the image will be able to grow to the full size if need be)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] lousy qemu-img performance converting to qcow2 ... if you use a hard drive Skaperen Linux - Virtualization and Cloud 8 06-01-2011 03:42 AM
After qemu-img, qemu is not capable to detect the C drive (empty) frenchn00b Linux - General 3 10-18-2009 05:39 AM
partitioning qemu-img; share your wisdom and what you got on vhd? linus72 Linux - General 3 06-14-2009 10:41 AM
Qemu.img to hard drive towjamb Debian 3 04-17-2007 05:33 PM
how to mount .img cd image created with k3b sunpascal Linux - Software 3 01-31-2006 08:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 12:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration