Sunday, June 12, 2016

Create a customized KVM on laptop

What do I mean by saying I need a customized KVM?

1. A way to get the external DHCP IP address to the KVM
2. A qcow2 image modified maybe?
3. Multiple network nics with specific needs, ie over vlan, host only etc.
4. Use specific nic cards ie for DPDK reasons

etc etc.

The above are some of my reasons I moved out from Vagrant etc.
I have a Vagrant file which can pretty much use a yaml file to create a set of KVM's with some option to nics. But as usual more than that is required.

Here in I will state (for my own good) steps to do what exactly I want -

Network

I want two nics, one external bridged so that others on the LAN can access my VM directly via an IP (assuming the general LAN has a DHCP server with free IP addresses and is freely giving those IP addresses, if your administrators have mac binded the dhcp ip addresses, then the only way you can get this functionality is the SNAT way)

  • Disable Network Manager. How?




  • Create a manual Bridge via brctl and link with a physical network -
  • 
    
    brctl addbr <bridge_name>
    brctl addif <bridge_name> <phys_net -- connected to the local lan of the DHCP server>
    ip link set <phys_net> up
    ip link set <bridge_name> up
    ifup <bridge_name>  (we will call this brex, for further use)
    OR via ifcfg-
    #> cat /etc/sysconfig/network-scripts/ifcfg-br0
    DEVICE=br0
    TYPE=Bridge
    DELAY=0
    BOOTPROTO=dhcp
    ONBOOT=yes
    NM_CONTROLLED=no
    PERSISTENT_DHCLIENT=yes
    DHCLIENT_IGNORE_GATEWAY=no
    GATEWAY=10.2.0.254
    DNS1=10.2.0.26
    DNS2=10.3.0.26

    #> cat /etc/sysconfig/network-scripts/ifcfg-eno1
    DEVICE="eno1"
    ONBOOT=yes
    UUID="f423eb24-2c1d-49d1-acdf-9a63ea867ff4"
    IPV6INIT=no
    BOOTPROTO=none
    TYPE=Ethernet
    NAME="eno1"
    BRIDGE=br0





  • disable firewalls for bridges - These control whether or not packets traversing the bridge are sent to iptables for processing. In the case of using bridges to connect virtual machines to the network, generally such processing is *not* desired, as it results in guest traffic being blocked due to host iptables rules that only account for the host itself, and not for the guests.



  • net.bridge.bridge-nf-call-arptables = 0
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0



  • Define one host only network (this is virtual). DHCP server is required if you want to auto populate IP address. However generally having statically configured openstack nodes help.



  • 
    (without DHCP)
    cat > /tmp/hostonly.xml <<EOF
    <network>
    <name>hostonly</name>
    <ip address="192.168.17.254" netmask="255.255.255.0"/>
    </network>
    EOF
    (Load and autorestart, remember the bridge name is virbr0 ^^)
    virsh net-define /tmp/hostonly.xml
    virsh net-autostart hostonly
    virsh net-start hostonly
    virt-install pass the bridge for network - Below will set two nics inside your VM, 1st one should be the hostonly nic, can be used for provisioning openstack clusters. 2nd one is the external access nic.
    virt-install <blah.. blah..> --network network:virbr0 --network network:brex (A complete virt-install is given below)

    VM Setup


    • Check nested virtualization support and please enable it, docs here.
    • install all the required RPM's for this excercise -

    • yum install libvirt qemu-kvm virt-manager virt-install libguestfs-tools xorg-x11-apps xauth virt-viewer libguestfs-xfs -y


    • Get Image (centos - url to check latest qcow2 - Index of /centos/7/images )




    • Lets create the directories for our use

    • mkdir -p /vmimages/{qcow2-arch,qcow2-kvm}
      cd /vmimages/qcow2-kvm/
      (lets stay here and use all the commands from here)


    • Copy to a libvirt images folder ie 'cp CentOS-7-x86_64-GenericCloud.qcow2 /vmimages/qcow2-arch/'

    • wget -c 'http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2'
      mv CentOS-7-x86_64-GenericCloud.qcow2 /vmimages/qcow2-arch/


    • Check the size of your qcow2 image disk (this is the max size of your VM disks, alas! this is not enough)

    • virt-filesystems --long -h --all -a ../qcow2-arch/CentOS-7-x86_64-GenericCloud.qcow2
      Name       Type        VFS  Label  MBR  Size  Parent
      /dev/sda1  filesystem  xfs  -      -    8.0G  -
      /dev/sda1  partition   -    -      83   8.0G  /dev/sda
      /dev/sda   device      -    -      -    8.0G  -


    • Lets increase it!, step 1. create a black qcow2 image of your desired size (remember these files are parse files, so when you create they wouldnt take all the space required)

    • qemu-img create -f qcow2 centos7.2-kvm1.qcow2 40G


    • Step 2. expand centos (downloaded qcow2 image) into the newly created 40G empty qcow2 image

    • virt-resize --expand /dev/sda1 ../qcow2-arch/CentOS-7-x86_64-GenericCloud.qcow2 centos7.2-kvm1.qcow2


    • check via virt-filesystems, of the new qcow2 image

    • virt-filesystems --long -h --all -a centos7.2-kvm1.qcow2
      Name       Type        VFS  Label  MBR  Size  Parent
      /dev/sda1  filesystem  xfs  -      -    40G   -
      /dev/sda1  partition   -    -      83   40G   /dev/sda
      /dev/sda   device      -    -      -    40G   -


    • If you want to use the awesome feature of KVM called 'Copy on Write', then some more steps are required. What it does, is it uses another disk for the VM to write the changes. So all the VM's can have one master disk and write the changes to there own copy disks.

    • qemu-img create -f qcow2 -b centos7.2-kvm1.qcow2 packstack-node1.qcow2 <-- choose a name of the backup file intutively so that it reflects the node you would be running.


    • Do some customization.. This has good docs here and more here!! (Here i start feeling the similarity with docker build)

    • Here we are removing cloud-init from the qcow2 image (its a nuisance, unless this image is being spawned in the cloud)
      
      
      virt-customize -a packstack-node1.qcow2 --run-command 'yum remove cloud-init* -y'
      Here we are setting a very complex password!
      virt-customize -a packstack-node1.qcow2 --root-password password:Cent05

      Finally! Create VM and start




      • We have come to the stage to start the KVM. ( --cpu SandyBridge,+vmx is to enable nested VM's. It is CPU architecture dependent and to be enabled in bios, more details here)

      • virt-install --ram 8096 --vcpus 4 --os-variant centos7.0 --disk path=/vmimages/qcow2-kvm/packstack-node1.qcow2,device=disk,bus=virtio,format=qcow2 --import --noautoconsole --vnc --network bridge:virbr1,model=e1000 --network bridge:br0,model=e1000 --cpu SandyBridge,+vmx --dry-run --print-xml --name packstacknode1 > packstacknode1.xml



      • Load your XML into libvirt

      • virsh define packstacknode1.xml
        virsh start packstacknode1
        virsh console packstacknode1



      • Some tyding.. login to console




      • create the ifcfg-eth{0,1} files

      • cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
        DEVICE=eth0
        ONBOOT=yes
        BOOTPROTO=static
        NM_CONTROLLED=no
        IPADDR=192.168.17.101
        NETMASK=255.255.255.0
        EOF
        cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth1
        DEVICE=eth1
        ONBOOT=yes
        BOOTPROTO=dhcp
        NM_CONTROLLED=no
        DEFROUTE=yes
        EOF              



      • put a hostname

      • hostnamectl set-hostname --static packstacknode1.redhat.local
        Yay! you have a shiny new packstack node with e1000 ethernet nics, which supports ovs-dpdk
        check 'ip a l' you should be able to connect to VM from your laptop on both the IP addresses.
        From outside your laptop, you should be able to access the VM over LAN


        Saturday, January 17, 2015

        Required ports for Consul to work properly

        What was not clear from the consul docs HERE, ports required to be open on the server. Here is the list of errors seen - 
        Error joining the cluster: dial tcp 192.168.59.18:8301: i/o timeout
        2015/01/14 23:55:50 [ERR] agent: failed to sync remote state: rpc error: failed to get conn: dial tcp 192.168.59.18:8300: i/o timeout
        Ports the consul requires are
        • 8301 - RPC
        • 8300 - TCP
        • 8500 - HTTP
        • 8600 - DNS (domain lookup)

        SSH important options and there meaning

        These are important to me, in the following cases. (Disclaimer, there are potential security loopholes in using the suggestion as given)
        These are options set on source (from where you are ssh’ing)
        • Host *
        • ForwardAgent yes (forwarding ssh-agent, so that you do not need to distribute your private keys everywhere)
        • CheckHostIP yes (probably good to have for security)
        • StrictHostKeyChecking no (disables security attribute associated with keys to hosts)
        • TCPKeepAlive yes (very handy in shaky internets)
        • #AllowTcpForwarding yes (this is only required when you use ssh as a socks proxy)
        • UserKnownHostsFile /dev/null (security threat, handy when you have a cloud env, where the same IP are assigned to new setups)
        • IdentitiesOnly yes (very handy, when you have a large no. of keys loaded into your ssh-agent and occasionally you have to log into a server with another key)

        Tuesday, January 6, 2015

        Thanjavur - The Great 'Raja Raja Chola I' built this enormous temple exactly 1004 years ago!

        Thanjavur!!!

        Taken from wikipedia, The name came from the killing of daemon called Tanjan by 'Neelamegha Perumal' a form of Vishnu, thus Thanjavur!

        Brihadeshwar Temple  is one of the largest, temples in India, built by The king 'Raja Raja Chola I' in the years 1003 tp 1010 AD.

        Amazing place and amazing food. The drive was even better, took the Bangalore -> Salem -> Namakkal -> Karur -> Trichy -> Thanjavur route.

        Stayed at Abbi's Inn

        Here are some pictures from the trip.












        Monday, December 22, 2014

        Living Life or Leaving Life

        This question has always intrigued me, and this has nothing to do with my stint at Iskcon.


        Monday, September 22, 2014

        Mahi Gal, Coke Studio Pakistan, Season 6, Episode 4 (excellent music and lyrics) archived

         
        Thanks to 'Syed Obaid Hasan Raza' for translating, archiving it here as well -

        shaam payi muk aasaan gaiyaan
        Evening has fallen and my yearnings have reached an end

        ni mera chaḍ gaye kaag banera
        The crows have flown from their perch above my wall

        maape sab sahelaṛiyaan
        My parents and all my friends

        ni mainoon taa’nah dende tera
        Taunt me with my love for you

        ho panchhi wi muṛ gharaan noon aande
        Even birds come home at the end of the day

        kyoon chit naeen karda tera
        So why does your heart not urge you to return?

        aa sardaar wasa ja jhokaan
        Come, my master, and make this dwelling flourish

        kadi pa tatṛi wal phera
        Come and see this miserable beggar sometime

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        teri deed ghareebaan da hajj ve
        Seeing you is the supreme pilgrimage for us poor beggars

        haaye ve
        Oh!

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        teri deed ghareebaan da hajj ve
        Seeing you is the supreme pilgrimage for us poor beggars

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        saabat rakh pareet noon
        Let love remain constant

        kite pa watnaan wal phera
        And come visit your home sometime

        ho panchhi wi muṛ gharaan noon aande
        Even birds come home at the end of the day

        kyoon chit naeen karda tera
        So why does your heart not urge you to return?
        (sargam)

        ‘urfi to may-andesh ze ghaugha-i raqeebaan
        Urfi, don’t worry about the uproar your rivals create

        aawaaz-i sagaan kam nakunad rizq-i gada ra
        The barking of dogs does not diminish the humble beggar’s daily bread
        (sargam)

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        teri deed ghareebaan da hajj ve
        Seeing you is the supreme pilgrimage for us poor beggars

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        nah main sohni nah gun palle
        I’m not beautiful, nor have I any great virtues

        nah main sohni nah gun palle
        I’m not beautiful, nor have I any great virtues

        mere ‘aib nimaani de kajj we
        Please hide the flaws of this miserable wretch

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        teri deed ghareebaan da hajj ve
        Seeing you is the supreme pilgrimage for us poor beggars

        kade aa ve maahi gal lag ve
        Come sometime, beloved, and gather me to your heart

        Monday, February 10, 2014

        Davmail Gateway server implements EWS Cal, mail, smtp

        My search for a EWS way of fetching email came to a halt. An awesome software exists. DAVMAIL!
        Awesome part is, it implements POP/IMAP/SMTP/Caldav/Carddav/LDAP   which is awesome! 

        recommended. 

        VIM issues with powerline

        What to do if you get this annoying issue - vi requirements.txt ...