Skip to content

Linux guest under KVM

Henryk Paluch edited this page Apr 18, 2021 · 9 revisions

Linux Guest under KVM

I use:

  • Host OS openSUSE 15.2 LEAP
  • Random guests including Linux guests with virt-manager/virt-viewer

Clipboard not working

(Incomplete) resources:

Mandatory requirements:

  • must have Spice-vdagent installed and running. Using for example:
sudo apt-get install spice-vdagent
sudo systemctl enable spice-vdagentd

But it is FAR from emough. You must also have configured RedHat spice device:

  • in your Virt-Manager
  • click on "Add Hardware"
  • click on "Channel" Device - ensure that Name is keep com.redhat.spice.0
  • save changes

Now poweroff and power on your Guest. Login to your guest and verify, that this device exists:

ls -l /dev/virtio-ports/
lrwxrwxrwx 1 root root 11 Apr 12 16:17 com.redhat.spice.0 -> ../vport2p1

If there is no /dev/virtio-ports/com.redhat.spice.0 then your Guest VM configuration failed for some reason.

If there exist /dev/virtio-ports then your clipboard should really start working...

Update guest screen resolution

Many alternative Windows Managers (including LXDE and XFCE4) will not resize guest screen resolution. We must do it by ourselfs.

  • Find you monitor output name:
    xrandr --listmonitors
    Monitors: 1
    0: +Virtual-1 1366/361x768/203+0+0  Virtual-1
    
  • it is Virtual-1 in my case
  • now force update of screen resolution:

Ummm, do not use this - under some environments it will kill SPICE...

xrandr --output Virtual-1 --auto


## Shared filesystem

How to share guest/host filesystem. I used (mostly) this guide:
- https://unix.stackexchange.com/questions/606816/error-adding-device-unsupported-configuration-only-supports-passthrough-access

My changes:
- remove leading slash from `Target` in VM Manage settings, for example:
- Target: `shared_vm`

And here is XML fragment of VM configuration:
```xml
<filesystem type="mount" accessmode="mapped">
<driver type="path"/>
<source dir="/var/local/shared_vm"/>
<target dir="shared_vm"/>
<alias name="fs0"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0"/>
</filesystem>

Under Guest I use following entry in /etc/fstab:

shared_vm /mnt/shared_vm 9p trans=virtio 0 0

Create Virtual Floppy

Sometimes we need virtual floppy (for example for Autoinst SUSE install).

NOTE: You can create autoinst.xml from running system using:

sudo yast clone_system
# will generate /root/autoinst.xml

In my case (to reuse bare-metal autoinst.xml for VM install) I made these changes:

  • disk name changed from /dev/sda to /dev/vda
  • use PCI address for eth0 instead of MAC address for easier reuse

Here is resulting diff:

--- zotac-orig/autoinst.xml	2021-04-18 12:14:37.533228534 +0200
+++ zotac-virt-manager/autoinst.xml	2021-04-18 12:22:47.273319335 +0200
@@ -715,7 +715,7 @@
         <bootproto>dhcp4</bootproto>
         <mtu>0</mtu>
         <name>eth0</name>
-        <startmode>hotplug</startmode>
+        <startmode>auto</startmode>
       </interface>
     </interfaces>
     <ipv6 config:type="boolean">false</ipv6>
@@ -723,20 +723,10 @@
     <managed config:type="boolean">false</managed>
     <net-udev config:type="list">
       <rule>
-        <name>wlan1</name>
+        <name>eth0</name>
         <rule>KERNELS</rule>
         <value>0000:01:00.0</value>
       </rule>
-      <rule>
-        <name>eth0</name>
-        <rule>ATTR{address}</rule>
-        <value>00:01:2e:7a:5f:f8</value>
-      </rule>
-      <rule>
-        <name>eth1</name>
-        <rule>ATTR{address}</rule>
-        <value>00:01:2e:7a:5f:f9</value>
-      </rule>
     </net-udev>
     <routing>
       <ipv4_forward config:type="boolean">false</ipv4_forward>
@@ -750,7 +740,7 @@
   </ntp-client>
   <partitioning config:type="list">
     <drive>
-      <device>/dev/sda</device>
+      <device>/dev/vda</device>
       <disklabel>gpt</disklabel>
       <enable_snapshots config:type="boolean">false</enable_snapshots>
       <initialize config:type="boolean">false</initialize>

WARNING! In reality you may have to also change partition sizes (YaST will warn if they will not fit to target and propose sensible changes to partition layout)

We can prepare such floppy using commands like:

  • install requirements
    sudo zypper in dosfstools mtools qemu-tools
  • create formatted empty floppy image (from: https://mail.gnome.org/archives/commits-list/2011-December/msg00811.html)
    qemu-img create -f raw floppy.img 1440k
    /usr/sbin/mkfs.msdos -s 1 floppy.img
  • now add to your /etc/mtools.conf virtual letter and absolute path to your floppy image, for example:
    drive z: file="/home/hpaluch/ISOs/auto-inst/zotac-virt-manager/floppy.img"
    
  • and now you can easily list/copy files to this virtual floppy using commands like:
    # creates label SUSE_INST on virtual floppy floppy.img
    mlabel z:SUSE_INST
    mdir z:
    # autoinst.xml is file in current directory
    mcopy autoinst.xml z:
    mdir z:
    
  • now you can attach your floppy to KVM VM, etc...

Example for Autoyast install on openSUSE LEAP 15.2:

  • attach openSUSE-Leap-15.2-DVD-x86_64.iso to created VM
  • attach floppy floppy.img to your VM
  • on boot you must specify parameter like:
    autoyast=device://fd0/autoinst.xml ifcfg=eth0=dhcp
    
  • note: the ifcfg=... was absolutely necessary to configure network eth0 on install (all repository commands would otherwise fail)
  • when booted properly there must be AutoYaST Settings entry in installation wizard navigation tree (left pane).
Clone this wiki locally