top of page
  • Writer's pictureHammad Alam

Creating a VM on KVM and attaching to NSX-T

STEPS to Deploy a VM in KVM. Following is for Ubuntu, centos is very similar:


Download the image file to a directory

nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ mkdir  /home/nsxt/tmp/VMs/cirros-2
nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ cd /home/nsxt/tmp/VMs/cirros-2

Passwords: username: cirros password: gocubsgo


Instantiate the VMs

sudo virt-install -n ubuntu-vm1 --import --os-type=Linux --os-variant=sles11 --ram=512 --vcpus=1 --disk /home/nsxt/tmp/VMs/cirros-1/cirros-0.4.0-i386-disk.img,bus=ide  --graphics vnc,listen=0.0.0.0,port=5901 --network network:nsx-managed --noautoconsole --noreboot

options explained:

-n → Name of your VM. Could be anything

--disk → is the path to your image file

--graphics → is helpful if you want vnc / UI access to the VM

the listen IP 0.0.0.0 means it would listen on the KVM host's IP addresss

port 5901 is the port of VNC for this instance, if you dont give port, it would take port 5900 but when you have multiple VMs in KVM, you want each to have a different port


List the VM you just created

nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu-vm1                      shut off

Edit the VM for Networking

nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ sudo virsh edit ubuntu-vm1
Domain T1_DB_VM1 XML configuration edited.
Navigate to the interface type (see screeshot)



and make it look like the following. Note that <parameters interfaceid> line should not be there between virtualport at this time. It will be automatically added later.


    <interface type='bridge'>
      <mac address='52:54:00:9b:51:ae'/>
      <source bridge='nsx-managed'/>
      <virtualport type='openvswitch'>
      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

Boot the VM

nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ sudo virsh start ubuntu-vm1 Domain ubuntu-vm1 started Once VM is booted, you have 2 options to connect to it a. Connect to the VNC (using VNC client)



b. virsh console <centos-vm1>

Configure the VM

IP the VM and give a default gateway

nsxt@kvm-comp1:~/tmp/VMs/cirros-2$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 12    ubuntu-vm1                      running
 13    ubuntu-vm2                      running

nsxt@kvm-comp1:~/tmp/VMs/cirros-2$ sudo virsh console 12
[sudo] password for nsxt:
Connected to domain ubuntu-vm1
Escape character is ^]

login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
cirros login: cirros
Password:

$ sudo ifconfig eth0 2.2.2.12 netmask 255.255.255.248 up
$ sudo route add default gw 2.2.2.9
$ echo nameserver 192.168.0.254 >> /etc/resolv.conf

Adding the VM to NSX-T Go back to the virsh and edit the VM


nsxt@kvm-comp1:~/tmp/VMs/cirros-1$ sudo virsh edit ubuntu-vm1


  1. Copy the UUID from the interfaceid that should have been auto populated now


<interface type='bridge'>
      <mac address='52:54:00:9b:51:ae'/>
      <source bridge='nsx-managed'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='cfb8620e-46e9-4333-bb2b-377fdb017081'/>
      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

Take it to NSX Manager and add a new Logical Switch Port on a LS where you want the VM to go



Test Connectivity:




1 view0 comments
bottom of page