Skip to content

Instantly share code, notes, and snippets.

@yspkm
Created October 23, 2023 03:31
Show Gist options
  • Save yspkm/fb69f61f5fc0cc5c90bc01aded1f2204 to your computer and use it in GitHub Desktop.
Save yspkm/fb69f61f5fc0cc5c90bc01aded1f2204 to your computer and use it in GitHub Desktop.
How to use QEMU GUI (virt-manager)

How to Configure Access for qcow2 in virt-manager

If you've created a qcow2 virtual disk, you might have noticed that it's not internally accessible even when you access it using sudo virt-manager. To fix this, we need to make a few changes to the /etc/libvirt/qemu.conf file.

1. Locate the Configuration File: The configuration file is found at /etc/libvirt/qemu.conf.

2. Modify the User and Group Settings: Find the lines that specify the user and group for QEMU processes. The default settings look like:

# user = "root"
# group = "root"

Uncomment (remove the # at the start) these lines and set them as follows:

user = "root"
group = "root"

3. Save and Close the Configuration File.

4. Additional Security Note: By default, VMs are run as non-root for security. Changing the VMs to run as root can pose a security risk, especially if a malicious VM gains access to /dev/vhost-net, /dev/vhost-vsock, or /dev/vhost-scsi.

If you decide to run VMs as root, it's recommended to adjust access settings in /etc/apparmor.d/abstractions/libvirt-qemu to enhance security. More details about this can be found in the mentioned links in the qemu.conf file.

Using QEMU with a GUI on Ubuntu via virt-manager:

  1. Install Necessary Software:

    sudo apt update
    sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
  2. Add Your User to Necessary Groups:

    sudo adduser $USER libvirt
    sudo adduser $USER kvm

    Logout and log back in for the group changes to take effect.

  3. Start and Enable the libvirtd Service:

    sudo systemctl start libvirtd
    sudo systemctl enable libvirtd
  4. Modify qemu.conf for Root Access:

    By default, QEMU might not have permissions to access certain resources. To run VM processes as root, modify the qemu.conf:

    • Open the configuration file:

      sudo nano /etc/libvirt/qemu.conf
    • Locate the sections for user and group. Update them as follows:

      user = "root"
      group = "root"
      
    • Save the file and exit.

    Warning: Running virtual machines as root can pose security risks. Ensure that you understand these risks before making this change.

  5. Launch virt-manager:

    virt-manager
  6. Create a New Virtual Machine:

    In virt-manager, click "Create a new virtual machine" and follow the wizard.

  7. Networking:

    By default, VMs use a NAT-based network connection (default). For advanced setups (like bridged networking), configure separately.

  8. Manage VMs:

    Use the virt-manager GUI to manage VMs.


After creating qcow2, even if you access it with sudo virt-manager, it's internally inaccessible. Therefore, changes to /etc/libvirt/qemu.conf are necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment