Virsh VM – How to Create a Virtual Machine from Scratch

kvmqemuvirsh

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!

Best Answer

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

Related Question