Installing KVM and Creating a Debian VM in OpenIndiana 151a

KVM (Kernel-based Virtual Machine) was developed in Linux as a very speedy in-kernel virtualization solution that takes advantage of Intel’s VT and AMD’s V technology. Recently, it was ported to Open Solaris derived operating systems such as Joyent’s SmartOS and Open Indiana.  Currently, libvirt is not supported so creating a virtual machine is a bit of a manual process.  In this post, I will describe my process for creating KVM based virtual machines on my Open Indiana 151a server.  I will describe how to install a Debian Linux system.

First download an install ISO of the operating system you’d like to install.  I am fortunate enough to work for a university with access to Internet2 and I like to download ISO’s from the University of Texas.  Here is their Debian mirror.

Now, on your Open Indiana 151a server, install the KVM module, application, and driver packages by executing:

# pkg install driver/i86pc/kvm \
system/qemu \
system/qemu/kvm

Next, if you’re using ZFS, create a zvol for your virtual machine hard drive. On my server, I have a mirrored zpool named local that I plan to install my virtual machines on.

# zpool status
  pool: local
 state: ONLINE
  scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        local       ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            c2d1    ONLINE       0     0     0
            c3d1    ONLINE       0     0     0
            c5d0    ONLINE       0     0     0

errors: No known data errors

  pool: rpool
 state: ONLINE
  scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        rpool       ONLINE       0     0     0
          c4d0s0    ONLINE       0     0     0

errors: No known data errors

local is one vdev of three mirrored 1TB drives as recommended for home servers in this great blog post by Constantin Gonzales. I want to create my virtual hard drives on this zpool.

# zfs list -r local
NAME                                     USED  AVAIL  REFER  MOUNTPOINT
local                                    256G   657G    31K  /local
local/shared                             256G   657G   172G  /shared
local/shared/Virtual                    83.8G   657G    33K  /shared/Virtual
local/shared/Virtual/ISO                3.56G   657G  3.56G  /shared/Virtual/ISO
local/shared/Virtual/KVM                80.2G   657G    43K  /shared/Virtual/KVM

I decided to create a 10 gigabyte volume for my Debian virtual machine hard disk to live on.  Here’s the command I used to create it:

# zfs create -p -V 10G local/shared/Virtual/KVM/debian/disk0

The -p option creates parent directories (if they don’t already exist) underneath the given ZFS dataset path. -V tells ZFS this dataset is a zvol and 10G says it’s going to be 10 gigabytes in size. You can see the new zvol by executing the zfs list again:

# zfs list -r local
NAME                                     USED  AVAIL  REFER  MOUNTPOINT
local                                    292G   622G    31K  /local
local/shared                             292G   622G   174G  /shared
local/shared/Virtual                     117G   622G    33K  /shared/Virtual
local/shared/Virtual/ISO                26.7G   622G  26.7G  /shared/Virtual/ISO
local/shared/Virtual/KVM                90.6G   622G    46K  /shared/Virtual/KVM
local/shared/Virtual/KVM/debian         10.3G   622G    31K  /shared/Virtual/KVM/debian
local/shared/Virtual/KVM/debian/disk0   10.3G   632G    16K  -

Now, we need to create a virtual network interface for the virtual machine to use.  Use dladm to list your current virtual network devices:

# dladm show-vnic
LINK         OVER         SPEED  MACADDRESS        MACADDRTYPE         VID
vnic0        igb0         1000   0:0:dc:79:f6:e3   fixed               0
vnic1        igb0         1000   0:0:dc:79:f6:e4   fixed               0
vnic2        igb0         1000   0:0:dc:79:f6:b8   fixed               0

If you do not have any virtual network devices, nothing will be listed. Go ahead and create a new one for your new Debian instance using the physical network interface the virtual machine will be communicating on (mine is igb0, your’s could be e1000g0, etc…):

# sudo dladm create-vnic -l igb0 vnic3

List the virtual network interfaces once again and make sure your new device is listed:

# dladm show-vnic
LINK         OVER         SPEED  MACADDRESS        MACADDRTYPE         VID
vnic0        igb0         1000   0:0:dc:79:f6:e3   fixed               0
vnic1        igb0         1000   0:0:dc:79:f6:e4   fixed               0
vnic2        igb0         1000   0:0:dc:79:f6:b8   fixed               0
vnic3        igb0         1000   2:8:20:28:d8:67   random              0

Now create a start-up script for your new virtual machine. Below is the simple script I use to start my virtual machines. For this new Debian instance, I set the CD and HD variables to the Debian install ISO and my new zvol respectively. The VNIC variable is set to the new virtual network interface we created above. I set the memory to 1024MB and the VNC session number to 5.

#!/usr/bin/bash

VNIC=vnic3
HD=/dev/zvol/dsk/local/shared/Virtual/KVM/debian/disk0
CD=/shared/Virtual/ISO/debian-504-i386-netinst.iso
VNC=5
MEM=1024

MAC=`dladm show-vnic -po macaddress $VNIC`

/usr/bin/qemu-kvm \
-boot cd \
-enable-kvm \
-vnc 0.0.0.0:$VNC \
-smp 2 \
-m $MEM \
-no-hpet \
-localtime \
-drive file=$HD,if=ide,index=0 \
-drive file=$CD,media=cdrom,if=ide,index=2  \
-net nic,vlan=0,name=net0,model=e1000,macaddr=$MAC \
-net vnic,vlan=0,name=net0,ifname=$VNIC,macaddr=$MAC \
-vga std

The /usr/bin/qemu-kvm executable requires root level permissions so I run the script with sudo. Like this:

# sudo ./start-debian.sh

If all goes well, the virtual machine should boot. A windowed screen with a graphical interface will not appear like in VirtualBox or VMWare. You’ll only see a bunch of text like this scroll by:

...
drive 0x000fda80: PCHS=16383/16/63 translation=lba LCHS=1024/255/63 s=20971520
Running option rom at cb00:0003
ebda moved from 9fc00 to 9f400
Returned 53248 bytes of ZoneHigh
e820 map has 7 items:
  0: 0000000000000000 - 000000000009f400 = 1
  1: 000000000009f400 - 00000000000a0000 = 2
  2: 00000000000f0000 - 0000000000100000 = 2
  3: 0000000000100000 - 000000003fffd000 = 1
  4: 000000003fffd000 - 0000000040000000 = 2
  5: 00000000feffc000 - 00000000ff000000 = 2
  6: 00000000fffc0000 - 0000000100000000 = 2
enter handle_19:
  NULL
Booting from Hard Disk...
Boot failed: not a bootable disk

enter handle_18:
  NULL
Booting from DVD/CD...
150MB medium detected
Booting from 0000:7c00

From your workstation, use a VNC client (I use TightVNC) and connect to your KVM server using the session number you setup above. On my Linux workstation, I run:

jgrafton@pod:~$ vncviewer orion:5

If all has gone well and your KVM server firewall is not blocking port 5905, (5900 + your VNC session number) the VNC client should connect to your KVM server and you should see something similar to this screenshot:

Install Debian and enjoy your new KVM virtual machine!  Remember, you’ll need a separate VNIC and VNC session number for each new virtual machine you create.  Have fun!

Let me know if it works for you by either leaving comments or tweeting me at @Graftolistic.

This entry was posted in computers, openindiana, solaris. Bookmark the permalink.

7 Responses to Installing KVM and Creating a Debian VM in OpenIndiana 151a

  1. Pingback: SmartOS News – Sept 25, 2011 – SmartOS.org

  2. Pingback: Linux News » Installing KVM and Creating a Debian VM in OpenIndiana 151a

  3. Pingback: Links 28/9/2011: Linux 3.1 RC8, Gains for Android Tablets | Techrights

  4. biant92 says:

    Please help !!!

    KVM not working just freeze the machine, tested on desktop and laptop:

    Desktop:

    System Configuration: Gigabyte Technology Co., Ltd. X48-DQ6
    BIOS Configuration: Award Software International, Inc. F8D 04/24/2009

    Q6600 Intel(R) Core(TM)2 Quad CPU Socket 775

    pandora@tesla:~$ isainfo -v
    64-bit amd64 applications
    vmx ssse3 cx16 sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu
    32-bit i386 applications
    vmx ssse3 ahf cx16 sse3 sse2 sse fxsr mmx cmov sep cx8 tsc fpu

    Virtualization (VT-x) in bios is enabled.

    Laptop:

    Toshiba Tecra S10-11A
    Intel® Core™2 Duo processor P8600, Intel® PM45 Express chipset

    pandora@laptop:~$ isainfo -v
    64-bit amd64 applications
    vmx sse4.1 ssse3 cx16 sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu
    32-bit i386 applications
    vmx sse4.1 ssse3 ahf cx16 sse3 sse2 sse fxsr mmx cmov sep cx8 tsc fpu

    Virtualization (VT-x) in bios is enabled.

    Do these machines support the KVM or not ???

  5. John says:

    Hello biant92,

    Unfortunately, KVM will not work with your processors. KVM requires the Extended Page Tables (EPT) feature of Intel’s second generation VT extensions. Only Intel processors based on the Nehalem architecture (Core i3,i5,i7 and various newer Xeons) and after support EPT. I need to update my previous blog post with this information.

    Joyent’s requirements for Illumos KVM: https://github.com/joyent/illumos-kvm
    Extended Page Tables: http://en.wikipedia.org/wiki/Extended_Page_Table

  6. biant92 says:

    Thank you for your prompt response. I also want to thank you for the very useful bolog.

    Thank you very much!!!

  7. Nice work! I wrote a little script to start the vms with SMF. Simple and ugly, but working (at less for one vm). Maybe it can help someone! OpenIndiana KVM startup script

Comments are closed.