Bug 1124144

Summary: qemu-img fail to recognize the Hyper-V Virtual Hard Disk (VHD) format image
Product: Red Hat Enterprise Linux 6 Reporter: Sibiao Luo <sluo>
Component: qemu-kvmAssignee: Jeff Cody <jcody>
Status: CLOSED WONTFIX QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.5CC: bsarathy, chayang, jcody, juzhang, michen, mkenneth, qzhang, rbalakri, virt-maint, xfu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1124636 (view as bug list) Environment:
Last Closed: 2015-01-27 17:45:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 1124636    

Description Sibiao Luo 2014-07-29 05:14:45 UTC
Description of problem:
I created one 1GB VHD(Fixed size) format image via, but qemu-img fail to recognize the Hyper-V Virtual Hard Disk (VHD) format image.
BTW, QEMU can used it as read-only device to boot up and can detect it in guest correctly. I will attach the image for your debugging.

Version-Release number of selected component (if applicable):
host info:
# uname -r && rpm -q qemu-kvm-rhev
2.6.32-493.el6.x86_64
qemu-kvm-rhev-0.12.1.2-2.431.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1.create a VHD(Fixed size and Dynamically expanding) format image via Hyper-v(Hyper-V Manager Verfison: 6.3.9600.16384) in Window Server 2012 R2.
e.g.1.Choose Disk Format(VHD)----Choose Disk Type(Fixed size)----1GB sluo1-fixed-size.vhd
e.g.2.Choose Disk Format(VHD)----Choose Disk Type(Dynamically expanding)----1GB sluo2-dynamically-expanding.vhd
2.Copy out the VHD images to local host and use qemu-img to recognize them or convert to qcow2 image.
# qemu-img info sluo1-fixed-size.vhd 
# qemu-img info sluo2-dynamically-expanding.vhd 
3.Launch a KVM guest with the VHD image as read-only device.
e.g.:...-drive file=/home/sluo1-fixed-size.vhd,if=none,format=vpc,id=drive-data-disk,cache=none,werror=stop,rerror=stop,readonly=on -device virtio-blk-pci,bus=pci.0,addr=0x7,drive=drive-data-disk,id=data-disk

Actual results:
after step 2, 
# qemu-img info sluo1-fixed-size.vhd 
image: sluo1-fixed-size.vhd
file format: raw                    <----------------- should be vpc
virtual size: 1.0G (1073742336 bytes)
disk size: 1.0G
# qemu-img info sluo2-dynamically-expanding.vhd 
image: sluo2-dynamically-expanding.vhd
file format: vpc
virtual size: 1.0G (1073479680 bytes)
disk size: 8.0K
cluster_size: 2097152
# qemu-img convert -p -f vpc -O qcow2 sluo1-fixed-size.vhd test1.qcow2
    (100.00/100%)
# qemu-img convert -p -f vpc -O qcow2 sluo2-dynamically-expanding.vhd test2.qcow2
    (100.00/100%)

after step 3, boot up KVM guest successfully and the VHD disk can be detected in guest correctly.

Expected results:
qemu-img can recognize the Hyper-V Virtual Hard Disk (VHD) format image correctly.

Additional info:

Comment 3 Jeff Cody 2014-07-29 14:56:20 UTC
Hi Sibiao,

Thanks for the sample issue.  For fixed-sized VPC (VHD) images, qemu currently cannot autodetect the type during a probe.  This is because for a format-probe, QEMU sends a data chunk from the beginning of the file to each image format driver, to detect header signatures / magic.  However, fixed sized VPC/VHD images only have a footer at the end of a file, and no header at the beginning.  This means that the image will most likely just be detected as 'raw'.

This could be changed upstream, as a feature enhancement.

Comment 4 Sibiao Luo 2014-07-30 02:12:11 UTC
(In reply to Jeff Cody from comment #3)
> Hi Sibiao,
> 
> Thanks for the sample issue.  For fixed-sized VPC (VHD) images, qemu
> currently cannot autodetect the type during a probe.  This is because for a
> format-probe, QEMU sends a data chunk from the beginning of the file to each
> image format driver, to detect header signatures / magic.  However, fixed
> sized VPC/VHD images only have a footer at the end of a file, and no header
> at the beginning.  This means that the image will most likely just be
> detected as 'raw'.
> 
> This could be changed upstream, as a feature enhancement.

Yes, thanks for your detail explains. BTW, qemu-img can recognize for the VHDX(Fixed size/Dynamically expanding) as vhdx correctly.

Choose Disk Format+----VHD----Choose Disk Type+----Fixed size
                  |                           |
                  |                           +----Dynamically expanding
                  |                           |
                  |                           +----Differencing
                  |
                  +----VHDX---Choose Disk Type+----Fixed size
                                              |
                                              +----Dynamically expanding
                                              |
                                              +----Differencing

# qemu-img info sluo3-fixed-size.vhdx 
image: sluo3-fixed-size.vhdx
file format: vhdx
virtual size: 1.0G (1073741824 bytes)
disk size: 1.0G
cluster_size: 33554432

# qemu-img info sluo4-dynamically-expanding.vhdx 
image: sluo4-dynamically-expanding.vhdx
file format: vhdx
virtual size: 1.0G (1073741824 bytes)
disk size: 4.0M
cluster_size: 33554432

Best Regards,
sluo