Convert qcow to lvm

  1. Variables
    QCOW_FILE=file.img
    LV_NAME=RootDisk
  2. Find out the size of the file

    qemu-img info ${QCOW_FILE}

    > image: file.img
    > file format: qcow2
    > virtual size: 60G (64424509440 bytes)
    > disk size: 56G
    > cluster_size: 65536
    > Format specific information:
    compat: 0.10

  3. Set the file size

    SIZE="60G"

  4. create a logical volume with matching size.

    lvcreate -L${SIZE} -n${LV_NAME} vg0

  5. “mount” the image file as a nbd device

    qemu-nbd -c /dev/nbd0 ${QCOW_FILE}

  6. copy the contents from nbd0 to the new logical volume

    dd if=/dev/nbd0 of=/dev/vg0/${LV_NAME} bs=1M

  7. disconnect the volume

    qemu-nbd -d /dev/nbd0

Leave a Reply

Your email address will not be published. Required fields are marked *