Convert directory to QEMU/KVM virtual disk image

By: Colorant Frog | 1 Year | Syntax: Plain Text | Views: 218
URL http://paste.itunix.eu/view/7640d6c7

  1.  
  2.  
  3. First, create a raw image of the required size. I'll assume 10G is enough. Using seek creates a sparse file, which saves space.
  4.  
  5. dd if=/dev/null of=example.img bs=1M seek=10240
  6.  
  7. Next, create a filesystem on it.
  8.  
  9. mkfs.ext4 -F example.img
  10.  
  11. (Note that you need the -F option for mkfs.ext4 to operate on a file as opposed to a disk partition)
  12.  
  13. Then, mount it.
  14.  
  15. mkdir /mnt/example
  16. mount -t ext4 -o loop example.img /mnt/example
  17.  
  18. Now you can copy your files to /mnt/example. Once this is done, unmount it and you can use example.img as a drive in a virtual machine. If you want you can convert it from a raw image to another format like qcow2e using qemu-img, but this isn't required.
  19.  

Reply to "Convert directory to QEMU/KVM virtual disk image"

Here you can reply to the paste above