- Variables
QCOW_FILE=file.img
LV_NAME=RootDisk
- 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
- Set the file size
SIZE="60G"
- create a logical volume with matching size.
lvcreate -L${SIZE} -n${LV_NAME} vg0
- “mount” the image file as a nbd device
qemu-nbd -c /dev/nbd0 ${QCOW_FILE}
- copy the contents from nbd0 to the new logical volume
dd if=/dev/nbd0 of=/dev/vg0/${LV_NAME} bs=1M
- disconnect the volume
qemu-nbd -d /dev/nbd0