16

It looks like that you cannot create a brand new VM with virsh unless you already have a working XML file.

I have just installed all the needed bits for QEMU-KVM to work, and need now to create my very first VM.

How to?

Hint: I don't have graphics!

  • Hey, just revisiting some questions. How did you get on with this? – I_GNU_it_all_along Nov 11 '16 at 16:11
  • I solved the problem by checking the man pages and the official QEMU and KVM web sites and a number of tests and tries. I have been asking to manually do everything, instead I've got answers on how to do it with 3rd party applications. I am almost finished and will publish my working solutions also here asap. – EnzoR Dec 9 '16 at 15:29
  • I'm pretty certain virt-install is part of the qemu-kvm suite but I'm glad you got it sorted. – I_GNU_it_all_along Dec 10 '16 at 15:56
  • @I_GNU_it_all_along virt-install is not part of the quemu-kvm. At least not under Debian/Ubuntu. – EnzoR Dec 10 '16 at 17:54
  • Hmm must have got my wires crossed with another package I usually install alongside them, virt-manager. No bother dude. – I_GNU_it_all_along Dec 10 '16 at 18:46
30

There is quite a good walkthrough here. Essentially the tool you're wanting to use is virt-install, which you should already have if you have installed everything needed for QEMU-KVM. Here's the most relevant section.

6. Creating a new Guest VM using virt-install

virt-install tool is used to create the VM. This tool can be used in both interactive or non-interactive mode.

In the following example, I passed all the required values to create an VM as command line parameters to the virt-install command.

# virt-install \
-n myRHELVM1 \
--description "Test VM with RHEL 6" \
--os-type=Linux \
--os-variant=rhel6 \
--ram=2048 \
--vcpus=2 \
--disk path=/var/lib/libvirt/images/myRHELVM1.img,bus=virtio,size=10 \
--graphics none \
--cdrom /var/rhel-server-6.5-x86_64-dvd.iso \
--network bridge:br0

In the above virt-install command the parameters have the following meaning:

  • n: Name of your virtual machine

  • description: Some valid description about your VM. For example: Application server, database server, web server, etc.

  • os-type: OS type can be Linux, Solaris, Unix or Windows.

  • os-variant: Distribution type for the above os-type. For example, for linux, it can be rhel6, centos6, ubuntu14, suse11, fedora6 , etc.

    For windows, this can be win2k, win2k8, win8, win7

  • ram: Memory for the VM in MB

  • vcpu: Total number of virtual CPUs for the VM.

  • disk path=/var/lib/libvirt/images/myRHELVM1.img,bus=virtio,size=10: Path where the VM image files is stored. Size in GB. In this example, this VM image file is 10GB.

  • graphics none: This instructs virt-install to use a text console on VM serial port instead of graphical VNC window. If you have the xmanager set up, then you can ignore this parameter.

  • cdrom: Indicates the location of installation image. You can specify the NFS or http installation location (instead of –-cdrom). For example: --location=http://.com/pub/rhel6/x86_64/*

  • network bridge:br0: This example uses bridged adapter br0. It is also possible to create your own network on any specific port instead of bridged adapter.

    If you want to use the NAT then use something like below for the network parameter with the virtual network name known as VMnetwork1. All the network configuration files are located under /etc/libvirt/qemu/networks/ for the virtual machines. For example:

    –-network network=VMnetwork1

  • 4
    It's rather strange how this isn't mentioned in most documentations, but rather they assume that you already have a working VM, when you're probably reading the tutorial precisely because you don't. Anyway, thanks. :) – Teekin May 31 '18 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.