Como criar uma VM a partir do zero com o virsh?

7

Parece que você não pode criar uma nova VM com o virsh, a menos que você já tenha um arquivo XML em funcionamento.

Acabei de instalar todos os bits necessários para o QEMU-KVM funcionar e preciso agora criar minha primeira VM.

Como?

Dica: eu não tenho gráficos!

    
por EnzoR 14.09.2016 / 12:28

1 resposta

15

Existe um bom passo a passo aqui . Essencialmente, a ferramenta que você está querendo usar é o virt-install, que você já deve ter se tiver instalado tudo o que é necessário para o QEMU-KVM. Aqui está a seção mais relevante.

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:

  • 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

    
por 14.09.2016 / 12:47

Tags