Help: Convert HDD to QCOW2 img
Hi All,
Recently, I'm writing an interface of wrapper class for QCOW2 in order to manage QCOW2 img files conveniently based on our requirements in my current project , this wrapper includes functions such as QCOW2 creating, read/write and snapshot relatives. Actually, these functions would finally call functions in qemu-img.c, block.c, qcow2.c and others related.
With respect to validation of this wrapper, I installed one VM to generate a fedora20.qcow2 file using qemu team's binary qemu-system_x86-64, and use my wrapper to read this file and write to a new QCOW2 file from sector 0 to total sectors the img includes, finally I can boot the VM using my generated QCOW2 img file.
Unfortunately, I'm suffering issue below,
I connected the fedora20.qcow2 to /dev/nbd0 using support of qemu-nbd and kernel nbd moduel, and fread this block node as file and also write the data to a new QCOW2 file using bdrv_write implemented in block.c starting from sector 0, but this img file doesn't work successfully, error report below when starts up
Error: file 'grub2/i386-pc/normal.mod' not found
Grub rescue>
It seems the partition information is not wrote successfully into the img file, what did I miss? What else should I do except writing the data? Could you give help on it?
The reason why I did above is that I want to write a hard disk drive including OS data (and can be started up normally as host) to qcow2 file, and then boot it as VM under qemu kvm support. Any idea or suggestion?
Host: Fedora20
VM: Fedora20
Kernel: 3.12.32
QEMU: 2.1.2
Thanks a lot!
Best Regards
Halsey Pian
Quoted 8 lines · Halsey Pian
Recently, I'm writing an interface of wrapper class for QCOW2 in order to manage QCOW2 img files conveniently based on our requirements in my current project , this wrapper includes functions such as QCOW2 creating, read/write and snapshot relatives. Actually, these functions would finally call functions in
qemu-img.c,block.c,qcow2.cand others related.
Quoted 5 lines
With respect to validation of this wrapper, I installed one VM to generate a fedora20.qcow2 file using qemu team's binary qemu-system_x86-64, and use my wrapper to read this file and write to a new QCOW2 file from sector 0 to total sectors the img includes, finally I can boot the VM using my generated QCOW2 img file.
Sounds like you might be reinventing qemu-img and/or qemu-io. What's unique about your program?
Quoted 3 lines
It seems the partition information is not wrote successfully into the img file, what did I miss? What else should I do except writing the data? Could you give help on it?
bdrv_close_all() might help if you forgot to shut down the block layer (which closes images and flushes metadata).
Since you have written custom code which you have not published, pretty much anything could be wrong but we wouldn't know.
Quoted 3 lines
The reason why I did above is that I want to write a hard disk drive including OS data (and can be started up normally as host) to qcow2 file, and then boot it as VM under qemu kvm support. Any idea or suggestion?
Did you look at "qemu-img convert"? It might do what you want.
Stefan
On Mon, Dec 1, 2014 at 9:40 AM, Halsey Pian <[email protected]> wrote:
Please keep [email protected] CCed so the discussion stays on the mailing list. I have added it back.
Quoted 2 lines
Hi Stefan, not know if there is similar module, currently I have not seen it. If yes, please forgive me. And for the program if it is unique, there should be some policies for involving QEMU team, right? Thanks.
QEMU does not have something directly equivalent to VMware's SDK for storage.
But there is a very powerful API called libguestfs. Maybe it does what you want:
http://libguestfs.org/
libvirt has APIs for snapshotting and managing storage:
http://libvirt.org/html/libvirt-libvirt-storage.html
QEMU's qemu-img supports JSON output to make it easy to parse. qemu-nbd can be used for read-write access.
There was an attempt to create something called libqblock but the work was never completed. I guess your approach is similar:
https://lists.gnu.org/archive/html/qemu-devel/2013-02/msg02356.html
Stefan
Hi Stefan,
Thanks for so much info you provided.
Okay, I would keep qemu-devel mailing list in the loop, no problem.
Currently, I have finished the coding of the wrapper, now testing the bdrv_read/write qcow2 img. I would look into these libraries and incorporate them based on the concept of interface design.
Thanks.
Halsey
Sent from my iPhone
Quoted 27 lines · Stefan Hajnoczi
On Mon, Dec 1, 2014 at 9:40 AM, Halsey Pian <[email protected]> wrote:
Please keep [email protected] CCed so the discussion stays on the mailing list. I have added it back.
Quoted 2 lines
Hi Stefan, not know if there is similar module, currently I have not seen it. If yes, please forgive me. And for the program if it is unique, there should be some policies for involving QEMU team, right? Thanks.
QEMU does not have something directly equivalent to VMware's SDK for storage.
But there is a very powerful API called libguestfs. Maybe it does what you want:
http://libguestfs.org/libvirt has APIs for snapshotting and managing storage:
http://libvirt.org/html/libvirt-libvirt-storage.htmlQEMU's qemu-img supports JSON output to make it easy to parse. qemu-nbd can be used for read-write access.
There was an attempt to create something called libqblock but the work was never completed. I guess your approach is similar:
https://lists.gnu.org/archive/html/qemu-devel/2013-02/msg02356.htmlStefan