Haswell
Haswell

Reputation: 1642

QEMU command line replace with libvirt

I am currently using the qemu command line arguments to launch a VM.

My command line is:

/home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64
 -trace events=/home/gnayan/qemu_events 
-drive file=/home/gnayan/CUSTOM_QEMU_SYSTEM/UBUNTU/ubuntu.img,if=virtio,format=raw
-drive file=/home/gnayan/CUSTOM_QEMU_SYSTEM/UBUNTU/u1.img,if=virtio,format=raw 
-m 1G -net nic,model=virtio -net user -redir tcp:2222::22 -enable-kvm &

I would like to launch the same VM using libvirt tools like virsh or virt-install etc, however I am having a hard time getting this done.

I created my domain xml:

<domain type="kvm">
        <name>first</name>
        <currentMemory unit="MB">1024</currentMemory>
        <memory unit="MB">1024</memory>
        <os>
                <type arch='x86_64'>hvm</type>
        </os>
        <devices>
                <emulator>/home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64</emulator>
                <disk type='file' device='disk'>
                        <source file='/home/gnayan/CUSTOM_QEMU_SYSTEM/UBUNTU/ubuntu.img'/>
                        <driver name='qemu' type='raw'/>
                        <target dev='vda' bus='virtio'/>
                </disk>
        </devices>
</domain>

THen tried to create VM using virsh define first.xml I get following error:

error: Failed to define domain from first.xml
error: internal error: Child process (LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64 -help) unexpected exit status 126: libvirt:  error : cannot execute binary /home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64: Permission denied

What may be wrong in my ubuntu settings.

I have install qemu from source.

The path /home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/ has not been exported, will libvirt require this path ?

I also get the following message in dmesg

type=1400 audit(1470991545.250:44): apparmor="DENIED" operation="exec" profile="/usr/sbin/libvirtd" name="/home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64" pid=21287 comm="libvirtd" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[19990.781774] audit: type=1400 audit(1470991545.258:45): apparmor="DENIED" operation="exec" profile="/usr/sbin/libvirtd" name="/home/gnayan/QEMU-devel/qemu-ubuntu/qemu/x86_64-softmmu/qemu-system-x86_64" pid=21288 comm="libvirtd" requested_mask="x" denied_mask="x" fsuid=0 ouid=0

Upvotes: 2

Views: 2573

Answers (1)

Ferrandinand
Ferrandinand

Reputation: 474

I would do this

virt-install --quiet --network bridge=bridge-name,model=virtio --name first  --ram=1024 \
--vcpus=1 --disk path=/home/gnayan/CUSTOM_QEMU_SYSTEM/UBUNTU/ubuntu.img,format=raw\
--disk path=/home/gnayan/CUSTOM_QEMU_SYSTEM/UBUNTU/u1.img,format=raw \
--graphics none --os-type=linux --import --autostart & \
  • bridge-name, in order to link it to the bridge you must have configured in your system(and physical external port added to allow vm access to external network)
  • The --import option is because I assume that the Ubuntu OS is already installed.

  • For the port redirection I would use iptables instead of doing it in a Vagrant style. But just an opinion. Not sure if it is possible in KVM.

My permisions for images in /var/lib/libvirtd/images/ -rw-r--r-- 1 qemu qemu

Upvotes: 2

Related Questions