Changes between Version 3 and Version 4 of kvm-manager


Ignore:
Timestamp:
Jun 26, 2018, 10:08:37 AM (15 months ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • kvm-manager

    v3 v4  
     1[[PageOutline]]
     2
    13= kvm-manager =
    2 
    34We use [https://0xacab.org/dkg/kvm-manager kvm-manager] to create, start and stop virtual guests.
    45
    56Starting with `stretch`, we are using the new systemd tools in kvm-manager which are documented below.
     7
     8== Basic Usage ==
     9
     10The steps in puppet are exactly the same - you will need to add a stanza in the physical server pp file for each guest you want to create.
     11
     12Similarly, you will need to create a pp file for the guest itself.
     13
     14After you push to the physical server, you will need to create a symlink for the cd.iso file (if you are installing a new guest).
     15
     16Then, to start the guest:
    617
    718 * Add guest user to the kvm group. I'm not sure why this is now required so have not automated it yet...
     
    1425 * Enable a guest to start at boot time: `systemctl enable kvm@$guest.service`
    1526 * Prevent a guest from starting at boot time: `systemctl disable kvm@$guest.service`
    16  * Debug: `journalctl -u kvm@$guest.service`
    1727
    18 To test out process manually:
     28== When things go wrong ==
     29
     30=== How it works ===
     31
     32Before diving into details of what steps to take, here's a description of what happens when a guest is started.
     33
     34From the service file:
     35
     36{{{
     37PermissionsStartOnly=true
     38User=%i
     39ExecStartPre=/usr/local/sbin/kvm-setup %i
     40ExecStart=/usr/local/sbin/kvm-start %i
     41ExecStop=/usr/local/sbin/kvm-stop %i
     42ExecStopPost=/usr/local/sbin/kvm-teardown %i
     43}}}
     44
     45The PermissionsStartOnly part means that only the start and stop scripts are executed by the user specified (which will always be the name of the guest).
     46
     47The ExecStartPre and ExecStopPost are executed as root.
     48
     49So this means, every time you start the guest:
     50
     51 1. `/usr/local/sbin/kvm-setup $guest` is run as root
     52 1. `/usr/local/sbin/kvm-start $guest` is run as the guest user
     53
     54Everytime you stop it:
     55
     56 1. `/usr/local/sbin/kvm-stop $guest` is run as $guest
     57 1. `/usr/local/sbin/kvm-teardown` is run as root.
     58
     59The kvm-setup and kvm-teardown scripts setup the networking for the guest. kvm-start launches the kvm process. And kvm-stop sends it the qemu signal to shut down.
     60
     61Additionally, we have:
     62
     63{{{
     64Wants=kvm-screen@%i.service
     65Before=kvm-screen@%i.service
     66}}}
     67
     68This part indicates that everytime kvm@$guest.service starts, we should start kvm-screen@$guest.service - which launches the screen session that goes with it.
     69
     70The kvm-screen service simply runs: `/usr/local/sbin/kvm-screen $guest` as the $guest user.
     71
     72=== Trouble Shooting ===
     73
     74There are a number of steps you can take to debug what is going wrong.
     75
     76The first step is: `journalctl -u kvm@$guest.service` and `systemctl status kvm@$guest.service`
     77
     78In addition, you can try running each step manually. This is perfectly safe and acceptable to do - but you must ensure you run the right commands as the right user.
    1979
    2080As root:
     
    3393kvm-teardown $guest
    3494}}}
     95
     96Here's a real world example:
     97
     98{{{
     990 medgar:~# systemctl status kvm@stokely.service
     100● kvm@stokely.service - KVM Manager virtual guest management script for stokely
     101   Loaded: loaded (/usr/local/share/kvm-manager/kvm@.service; disabled; vendor preset: enabled)
     102   Active: failed (Result: exit-code) since Tue 2018-06-26 04:57:42 UTC; 9h ago
     103  Process: 4408 ExecStartPre=/usr/local/sbin/kvm-setup stokely (code=exited, status=1/FAILURE)
     104
     105Jun 26 04:57:42 medgar systemd[1]: Failed to start KVM Manager virtual guest management script for stokely.
     106Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Unit entered failed state.
     107Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Failed with result 'exit-code'.
     108Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Service hold-off time over, scheduling restart.
     109Jun 26 04:57:42 medgar systemd[1]: Stopped KVM Manager virtual guest management script for stokely.
     110Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Start request repeated too quickly.
     111Jun 26 04:57:42 medgar systemd[1]: Failed to start KVM Manager virtual guest management script for stokely.
     112Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Unit entered failed state.
     113Jun 26 04:57:42 medgar systemd[1]: kvm@stokely.service: Failed with result 'exit-code'.
     1143 medgar:~#
     115}}}
     116
     117This output indicates that the failure happened with the ExecStartPre command existing with a non-zero exit code.
     118
     119Now, running it manually:
     120
     121{{{
     1223 medgar:~# kvm-setup stokely
     123Running kvm-prepare
     124Configuring tap (stokely0) on bridge (br0).
     125ioctl(TUNSETIFF): Device or resource busy
     1261 medgar:~#
     127}}}
     128
     129This error suggests that the networking may not have been torn down properly on a previous run. So, let's tear it down:
     130
     131{{{
     1321 medgar:~# kvm-teardown stokely
     133De-configuring the network.
     1340 medgar:~# kvm-setup stokely
     135Running kvm-prepare
     136Configuring tap (stokely0) on bridge (br0).
     137/dev/mapper/vg_medgar0-stokely
     138kvm-prepare completed successfully
     1390 medgar:~#
     140}}}
     141
     142Now it works! But, before trying to restart stokely, let's tear it down again so we are back in the right state for it to start on it's own:
     143
     144{{{
     1450 medgar:~# kvm-teardown stokely
     146De-configuring the network.
     1470 medgar:~#
     148}}}