Showing posts with label Virtual machine. Show all posts
Showing posts with label Virtual machine. Show all posts

Wednesday, July 24, 2019

Converting proprietary formats to native formats in qemu

Virtual box stores its image in vdi and vmware with vmdk format. To convert to qcow2 or raw format use the following command

qemu-img convert file.vdi -O qcow file.qcow

-O option is used to specify the format

The formats supported by qemu are
  1. raw
  2. cloop
  3. cow [only on windows]
  4. qcow
  5. qcow2 [has many advantages, higly recommended]
  6. vmdk
  7. vdi
  8. vhdx
  9. vpi
  10. bochs
  11. dmg
  12. nbd
  13. parallels
  14. vvfat
Remember you can convert images  only between these formats.

Reference

https://virtuallyfun.com/wordpress/2011/04/30/qemu-disk-image-conversion/

Redhat Qemu Documentation

Qemu: How To transfer file from host to guest using Qemu-nbd

In the last post we have seen how to transfer  files  using guestfs-tools to mount an image to transfer files. In this method we are using a native client called qemu-nbd to transfer files. Make sure qemu-utils have been installed if not run

apt-get install qemu-utils

After installing first run

sudo modprobe nbd max_part=8

This command loads the nbd module and instructs the kernel we will manage upto eight partitions. To mount first we need to connect the image to the qemu network device block driver.

 sudo qemu-nbd --connect=/dev/nbd0  hq.qcow2

Now check the partitions  of the device /dev/nbd0

sudo fdisk /dev/nbd0 -l

this command will list the partitions in the image. Now we can mount the image using the mount command.

sudo mount /dev/nbd0p1  /mnt

to unmount the image run

sudo umount  /mnt
sudo qemu-nbd  --disconnect /dev/nbd0

With this command you can modify your contents in your image. If you are mounting  a  linux distro image make sure you are modifying only the home folder and nothing elsee other wise it will corrupt your image.

QEMU: How to transfer files from Host to Guest

In virtual box there is a way to transfer files from host to guest and vice versa using the guest additions. In qemu there is a way to transfer files. First install
libguestfs-tools.

apt-get install libguestfs-tools

The libguestfs-tools package contains two important programs guestmount and guestunmount. To mount a image say with qcow2 format run

guestmount -a hd.qcow2 -m /dev/sda  /mnt/dir 

-a hd.qcow2: this option must be followed by a image file.
-m /dev/sda: the disk layout  your image file has. If you don't know just type random disk no and it will give you a layout of the image file.
 /mnt/dir: the mount point of your image.

No you can transfer your file. To unmount run

guestunmount  /mnt/dir

IMPORTANT: Never mount an image when qemu is running. It will corrupt the image.

Reference:

 http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html
 

Tuesday, July 23, 2019

HOW-TO: QEMU

There are many  popular virtualization software in the wild  such as virtual box, vmware, etc. But there is another virtualization software native to linux and is opensource that is Qemu. It can also emulate hardware level virtualization.
To install qemu run the following command

apt-get install qemu

make sure you install qemu-system-gui otherwise you will be left without GUI and you will only see

VNC server started at 127.0.0.1:5869

make sure you also installed libsdl-dev and libconsole packages. If you don't want to have GUI then uninstall qemu-system-gui package and install gvncviewer.

apt-get install gvncviewer

To run gvncviewer use the following command

/usr/bin/gvncviewer localhost ::1:5869

First we need  to create a virtual hard disk  file. The native format for qemu is a raw file but if you have more disk space then it is recommended to use qcow2 format to create a virtual image we use the qemu-img command.

qemu-img create -f qcow2 hd.qcow2 1G

if you use .img for your image qemu will give warning about explicitly specifying a format.
-f qcow2 says create a  image with the format qcow2
1G says the file must of size 1 GB

To run your virtual os if your system is 32 bit then run qemu-system-i386 and  if it's 64 bit then run qemu-system-x86_64

For example to run freedos

qemu-system-i386 -m 512 -cpu host -enable-kvm -hda hd.cow2  -cdrom freedos.iso -boot order=d

-m 512: use ram of 512 MB
-cpu host: Emulate host cpu
-boot order=d: boot from cdrom

After you have installed your virtual os run

qemu-system-i386 -m 512 -cpu host -enable-kvm hd.qcow2

That's it you can now use your virtual os.



 

Popular Posts