KVM on Ubuntu 24.0 error on change display from spice to VNC
<h1>Resolving VNC Configuration Error in KVM on Ubuntu</h1>
<p>If you’re using KVM on Ubuntu and encounter the following error when attempting to configure VNC as the graphics protocol for your virtual machines:</p>
<pre>
libvirt.libvirtError: unsupported configuration: chardev ‘spicevmc’ not supported without spice graphics
</pre>
<p>This post will guide you through the necessary steps to resolve this issue by manually modifying the VM’s XML configuration.</p>
<h2>Steps to Resolve the Error and Configure VNC</h2>
<h3>1. Shut Down the Virtual Machine</h3>
<p>Before making any changes to the VM’s configuration, ensure that the VM is <strong>powered off</strong>.</p>
<pre><code>virsh shutdown <vm-name></code></pre>
<h3>2. Backup the VM’s XML Configuration</h3>
<p>It’s always a good practice to back up the VM’s XML configuration before modifying it.</p>
<pre><code>virsh dumpxml <vm-name> > vm-config-backup.xml</code></pre>
<h3>3. Edit the VM’s XML Configuration</h3>
<p>Open the VM’s XML configuration file to make the necessary changes.</p>
<pre><code>virsh edit <vm-name></code></pre>
<h4>a. Remove the ‘spicevmc’ Chardev</h4>
<p>Within the XML file, locate the section related to <code>spicevmc</code> and remove or comment it out:</p>
<pre><code><channel type=’spicevmc’>
<target type=’virtio’ name=’com.redhat.spice.0’/>
</channel>
</code></pre>
<p><strong>Change to:</strong></p>
<pre><code><!–
<channel type=’spicevmc’>
<target type=’virtio’ name=’com.redhat.spice.0’/>
</channel>
–>
</code></pre>
<h4>b. Modify the <graphics> Section to Use VNC</h4>
<p>Find the <code><graphics></code> section and ensure it’s configured for VNC:</p>
<pre><code><graphics type=’vnc’ autoport=’yes’ listen=’0.0.0.0’>
<listen type=’address’ address=’0.0.0.0’/>
</graphics>
</code></pre>
<h3>4. Save and Exit the Editor</h3>
<p>In <code>nano</code>, press <code>Ctrl + O</code> to save and <code>Ctrl + X</code> to exit.</p>
<h3>5. Redefine the VM with the Modified Configuration</h3>
<p>After modifying the XML file, redefine the VM with the updated configuration.</p>
<pre><code>virsh define vm-config-backup.xml</code></pre>
<h3>6. Verify the VNC Configuration</h3>
<h4>a. Identify the Assigned VNC Port</h4>
<pre><code>virsh vncdisplay <vm-name></code></pre>
<p>The output will be similar to <code>:1</code>, indicating that the VNC port is <code>5901</code> (VNC uses 5900 + display number).</p>
<h4>b. Check if the Port is Open</h4>
<pre><code>sudo ss -tuln | grep 5901
</code></pre>
<p>You should see something like:</p>
<pre>
tcp LISTEN 0 128 0.0.0.0:5901 0.0.0.0:*
tcp LISTEN 0 128 [::]:5901 [::]:*
</pre>
<h3>7. Configure the Firewall to Allow VNC Connections</h3>
<h4>a. Using UFW (Uncomplicated Firewall)</h4>
<pre><code>sudo ufw allow 5901/tcp
sudo ufw reload
</code></pre>
<h3>8. Start the Virtual Machine</h3>
<pre><code>virsh start <vm-name></code></pre>
<h3>9. Access the VM’s VNC Console</h3>
<h4>a. Using an External VNC Client</h4>
<ol>
<li><strong>Install a VNC Client (if you don’t have one):</strong>
<pre><code>sudo apt install remmina -y</code></pre>
</li>
<li><strong>Connect to the VM:</strong>
<ul>
<li>Open Remmina.</li>
<li>Enter the server’s IP address and VNC port (e.g., <code>192.168.1.100:5901</code>).</li>
<li>Enter the VNC password if prompted.</li>
</ul>
</li>
</ol>
<h4>b. Using noVNC for Browser Access</h4>
<p>If you prefer accessing the VNC console via a browser without installing external VNC clients, you can set up <strong>noVNC</strong>.</p>
<ol>
<li><strong>Install noVNC and Websockify:</strong>
<pre><code>sudo apt install git python3-pip -y
git clone https://github.com/novnc/noVNC.git
cd noVNC
pip3 install websocket-client
</code></pre>
</li>
<li><strong>Start noVNC:</strong>
<pre><code>./utils/launch.sh –vnc localhost:5901 –listen 6080
</code></pre>
<p>This command will start noVNC and make it accessible at <code>http://<your-domain-or-ip>:6080/vnc.html</code>.</p>
</li>
<li><strong>Access via Browser:</strong>
<ul>
<li>Open your browser and navigate to <code>http://<your-domain-or-ip>:6080/vnc.html</code>.</li>
<li>Enter the VNC connection details and access the VM’s console.</li>
</ul>
</li>
</ol>
<div class=”note”>
<strong>Note:</strong> To make noVNC accessible permanently and securely, consider setting up a reverse proxy with <strong>Nginx</strong> and enabling <strong>HTTPS</strong>.
</div>
<h2>Conclusion</h2>
<p>By following these steps, you should be able to resolve the <code>chardev ‘spicevmc'</code> error and properly configure VNC to access the desktops of your KVM VMs on Ubuntu. This setup allows you to use external VNC clients or access the console via a browser using noVNC, providing greater flexibility in managing your virtual machines.</p>
<p>If you encounter any further issues during the configuration, carefully review each step to ensure all settings are correct. Feel free to reach out for additional clarification if needed!</p>