You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Current »

This page describes how to create new virtual machines on the infra/api hosts running KVM/libvirt, with Virtual Machine Manager or with CLI tools. 

In order for any of this to work, it is required that one or more hosts are installed with the role::kvm puppet role.

Virtual Machine Manager

Install Virtual Machine Manager

$ apt install virt-manager ssh-askpass-gnome

Connect to the remote KVM host

  1. Start Virtual Machine Manager, and click File -> Add Connection...
  2. Select:
    1. Hypervisor = QEMU/KVM
    2. Connect to remote host
    3. Method = SSH
    4. Username = <your username at the remote host>
    5. Hostname = <kvmhost.domain.net>
    6. Autoconnect
  3. You will be prompted for you password at the remote host. Enter it, and hit OK.
  4. You should now see something like this, and you're all set to create virtual machines!

Creating a virtual machine

  1. Select the remote server, and click the Create a new virtual machine button
  2. Ensure that the remote server is selected in the Connection dropdown, and select Network Boot (PXE)
  3. Select the correct OS type and version. In most cases, this should be Linux and Ubuntu 16.04
  4. Choose the RAM and CPU settings you need
  5. Select Enable storage for this virtual machine and Select or create custom storage and click Manage..
  6. Select vmvg in the left menu, and click the green button with a plus sign
  7. Give the disk a name, preferably the same name as your new virtual machine, enter a sufficient disk size, and click Finish
  8. Ensure that the newly created volume are selected, and click Choose volume
  9. Give the virtual machine a name, and check Customize configuration before install. Also, select the network your virtual machine should connect to. In most cases, you should select one of the options starting with Virtual network.
  10. In the customization menu, select Boot Options and ensure that Start virtual machine on host boot up are selected, and that both the NIC and Disk are selected under Boot device order. The NIC should be first. Click Apply, and then Begin Installation. 
  11. Your new virtual machine is now ready to go, and is set up for PXE booting. It's now probably smart to take a note of the MAC adress on the virtual NIC.

CLI-tools (virt-install)

Log on to the KVM host. First list the available networks

$ virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 management           active     yes           yes
 services             active     yes           yes

Then; create a new machine

$ virt-install --name <vm-name> --memory <RAM in MB> --vcpus <cpus> --cpu host --pxe --boot network,hd --os-variant ubuntu16.04 --disk size=<disk size in GB>,pool=vmvg -w network:<net-name> --autostart --noautoconsole --wait 0

To find the MAC-address

$ virsh domiflist <vm-name>
Interface  Type       Source     Model       MAC
-------------------------------------------------------
-          network    management virtio      52:54:00:e8:8d:1c

Start/stop/reset machine

$ virsh start <vm-name>    # start a shutdown machine
$ virsh destroy <vm-name>  # Force stop a machine
$ virsh shutdown <vm-name> # Gracefully shutdown a machine
$ virsh reboot <vm-name>   # Gracefully reboot a machine
$ virsh reset <vm-name>    # Hard reset / cold boot a machine

 



  • No labels