Overview

Skill Level: Any Skill Level

Basic knowledge of Linux

In this tutorial i will teach how to create a new guest virtual machine using virt-install.

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

Ingredients

PowerKVM should be installed before proceeding to create the virtual machine

Step-by-step

  1. Login into your kvm machine using root account

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

    Run the below command on terminal to start the execution

    [root@kvm_iic ~]# virt-install \
    > -n POWERVC \
    > –description “RHEL-7 as KVM Guest” \
    > –ram=2048 \
    > –vcpus=2 \
    > –location //var/lib/libvirt/images/RHEL-7.4-20170711.0-Server-x86_64-dvd1.iso \
    > –os-type=linux \
    > –disk /var/lib/libvirt/images/POWERVC,size=50 \
    > –os-variant=rhel7 \
    > –graphics none \
    > –console pty,target_type=serial \
    > –extra-args ‘console=ttyS0,115200n8 serial’ \
    > –network bridge:br0

  2. Explaination about parameters passed for creating the virtual machine

    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.
    • ram — Size of the Memory to be allocated to guest VM in MB
    • vcpus — Total number of virtual CPUs fto be assigned to VM
    • location — Indicates the location of installation image
    • 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
    • disk — /var/lib/libvirt/images/POWERVC,bus=virtio,size=10 Path where the VM image files is to be stored. Size in GB. In this example, this VM image file is 50GB.
    • graphics — 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.
    • network — This example uses bridged adapter br0.
  3. List Virtual Machines

    The following command will display all the virtual machines that are installed on your KVM.

    [root@kvm_iic ~]# virsh list –all
    Id        Name                             State
    —————————————————————————–
    44        centos7                             running
    107     OBJECTSTORAGE2         running
    109     CONTROLLER                   running
    110     BLOCKSTORAGE              running
    113     OBJECTSTORAGE1         running
    114     COMPUTE                          running
    –¬†¬†¬†¬†¬†¬†¬†¬†¬† POWERVC¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† ¬† ¬† ¬† shut off

  4. Shutdown VM

    [root@kvm_iic ~]# virsh shutdown POWERVC

    Domain POWERVC is being shutdow

  5. Edit VM

    [root@kvm_iic ~]# virsh edit POWERVC

  6. Start VM and Connect to VM Console

    [root@kvm_iic ~]# virsh start POWERVC –console
    Domain POWERVC started
    Connected to domain POWERVC
    Escape character is ^]
  7. Connect to Running VM Console

    [root@kvm_iic ~]# virsh console POWERVC
    Connected to domain POWERVC
    Escape character is ^]
  8. Display VM Information

    To display the VM information, use the following command

    [root@kvm_iic ~]# virsh dominfo POWERVC
    Id: 115
    Name: POWERVC
    UUID: 5d47505b-51e8-4f6f-a24a-bebf3ce5f878
    OS Type: hvm
    State: running
    CPU(s): 8
    CPU time: 29.9s
    Max memory: 16777216 KiB
    Used memory: 16777216 KiB
    Persistent: yes
    Autostart: disable
    Managed save: no
    Security model: selinux
    Security DOI: 0
    Security label: system_u:system_r:svirt_t:s0:c206,c468 (enforcing)

     

    Now you have successfully created a virtual machine using virt-install command.

Join The Discussion