简体   繁体   English

将ext3图像转换为qcow2格式

[英]Convert ext3 image to qcow2 format

I have an ext3 image. 我有一个ext3图片。 But I need image in qcow2 format to bring up the VM using qemu. 但是我需要qcow2格式的映像才能使用qemu启动虚拟机。 Is there any command to create qcow2 from ext3 format? 有什么命令可以从ext3格式创建qcow2吗?

Assumptions: 假设:

  • QEMU already installed 已安装QEMU
  • "ext3 format" is an image of a HDD ext3 partition eg created by dd (probably really a raw file) “ ext3格式”是HDD ext3分区的映像,例如由dd创建(可能实际上是原始文件)

    qemu-img convert -O qcow2 image.ext3 image.qcow2 qemu-img转换-O qcow2 image.ext3 image.qcow2

My improvised method: 我的简易方法:

  • Create a qcow2 image disk with enough space to accommodate the ext3 image. 创建一个具有足够空间以容纳ext3映像的qcow2映像磁盘。

     qemu-img create -f qcow2 disk.qcow2 10G 
  • Expose the qcow2 image as a device. 将qcow2图像作为设备公开。

     modprobe nbd qemu-nbd -c /dev/nbd0 disk.qcow2 
  • Create a linux partition inside the qcow2 disk. 在qcow2磁盘内创建一个Linux分区。

     cfdisk /dev/nbd0 
  • Copy the the ext3 image over the linux partition. 将ext3映像复制到linux分区上。

     dd if=image.ext3 of=/dev/nbd0p1 
  • Disconnect the qcow2 device. 断开qcow2设备。

     sync qemu-nbd -d /dev/nbd0 

Ready! 准备! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM