TurnKey Linux Virtual Appliance Library

Recipe: Install a Turnkey Appliance on KVM remotely headless.

turnkey_3's picture

I helped a friend this weekend to install the WordPress Appliance on a server with KVM.

Here is my "Recipe":

 

1. Download the VMDK-file and Unzip it

 

2. Convert the Vmware-image to QEMU Raw-format with:

qemu-img convert turnkey-wordpress-2009.10-2-hardy-x86.vmdk sda.img

 

3. Mount the image temporary:

If you look att Disk-image with "fdisk -ul sda.img" you see that "sda1" starts at unit 32 and that an unit is 512 bytes (32x512=16384). Mount it like this:

mount -o loop,offset=16384 sda.img /mnt

 

4. Create support for Serial Console:

In /mnt/etc/grub/menu.lst add the following in the top:

serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=15 serial console

Change the kernel-lines in the end to look like:

kernel          /boot/vmlinuz-2.6.2..... ro quiet splash console=tty0 console=ttyS0,115200n8

Create /mnt/etc/event.d/ttyS0 with following content:

# ttyS0 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5

stop on runlevel 0
stop on runlevel 1
stop on runlevel 6

respawn
exec /sbin/getty 115200 ttyS0

 

5. Set static IP:

Edit /mnt/etc/network/interfaces to look like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 1.2.3.4
        netmask 255.255.255.0
        gateway 1.2.3.1

 

6. Setup DNS:

Edit /mnt/etc/resolvconf/resolv.conf.d/base to look like this:

domain yourdomain.com
search yourdomain.com
nameserver 208.67.222.222
nameserver 208.67.220.220

 

7. Unmount the Image:

umount /mnt

 

8. Create an XML-file for KVM:

I modified an existing file and got this (wp.xml):

<domain type='qemu' id='2'>
  <name>wp</name>
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <source file='/srv/virt/wp/sda.img'/>
      <target dev='hda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <mac address='52:54:00:aa:12:34'/>
      <source bridge='br0'/>
      <target dev='vnet2'/>
      <model type='virtio'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/3'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target port='0'/>
    </console>
  </devices>
</domain>

Don't forget that mac address must be unique.

 

9. Define it in KVM and make it autostart with help of virsh:

Start virsh and type:

define wp.xml
autostart wp

Start up your new virtual machine with virsh and play with it...

start wp
console wp

 

That's all folks!

Claes Ström's picture

No comments!?

Was everything clear or was it ununderstandable?

 

One thing to change if you have newer libvirt/kvm running is to have "kvm" instead of "qemu" in the first line of the xml-file with the machine definition. "kvm" gives hardware acceleration and "qemu" not!

<domain type='kvm' id='2'>
  <name>wp</name>
  .
  .

 

And to get swap to work and use kvm's virtual driver for disk change /etc/fstab to:

proc        /proc    proc    defaults            0 0
/dev/vda1    /    ext3    noatime,errors=remount-ro    0 1
/dev/vda2    none    swap    sw                0 0

Maybe upcoming 10.04 based turnkeys could have Serial Console included by default?

 

10.04 have ttyS0 defined in /etc/init/ttyS0.conf (instead of /etc/event.d/ttyS0) with content like:

# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 115200 ttyS0 vt102

See: http://help.ubuntu.com/community/SerialConsoleHowto

 

One more tip: If you upgrade your Ubuntu/KVM server to 10.04, you need to load the kernal kvm-modules (kvm and kvm-amd or kvm-intel), ie put them in /etc/modules which earlier versions not needed.

 

/Claes

(I spent a whole day after my upgrade to 10.04 to get everything to work again...)

Liraz Siri's picture

This could be a great addition to the community documentation

Great work documenting your experience with KVM. In fact, I think this would make a great addition to the community documentation. Probably under the virtualization notes page. You'll notice there's a link on the bottom to "Add child page". Don't worry about making mistakes, we can always fix that later.

Oh and sorry for the lag in response time, we're working on launching the TurnKey Hub private beta as well as coming out with betas of the Lucid based appliances. That's been keeping us unusually busy...

Claes Ström's picture

Community doc..

After and if Tkl based on some newer platform than 8.04 been released, then I going to try write up this doc.

/Claes

Guest's picture

Get a startup error in virsh shell

Nice how-to, but I get an error when I try to start up the zimbra appliance:

 

virsh # start zimbra

libvir: QEMU error : internal error QEMU quit during console startup
qemu: could not open disk image  /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img
error: Failed to start domain zimbra
 

The log file is not very helpful:

 

/usr/bin/kvm -S -M pc -m 512 -smp 1 -name zimbra -nographic -monitor pty -no-acpi -boot c -drive file= /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img,if=virtio,index=0,boot=on -net nic,macaddr=52:54:00:aa:12:34,vlan=0,model=virtio -net tap,fd=10,script=,vlan=0,ifname=vnet0 -serial pty -parallel none -usb 
qemu: could not open disk image  /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img
 
Any ideas?
Claes Ström's picture

What is your the respons of...

ls -al /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img

 

Are you able to mount the image again after your modifications?

 

What platform and versions are you on?

 

Could you test to move your image-map "nearer" root (shorter paths) and see if it work (may some maxlength of parameter strings to kvm/qemu)

 

You have not changed the domain type to kvm in the xml-file, or have you?

 

/Claes

Guest's picture

Hello Claes Thanks for your

Hello Claes

Thanks for your reply. Sorry, I was away for awhile:

I am using Debian 5.0 with the  2.6.26-2-openvz-amd64 kernel. 

Here is the ls -la output.

 

[username]@server:/srv/data/pics$ ls -al /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img
-rwxr-xr-- 1 [username] [username-group] 21474836480 2010-09-23 20:42 /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img
[username]@server:/srv/data/pics$ 
 
On this basis I changed the group owner to libvirt and undefined and redefined  the domain. 
 
Here is the head of the zimbra.xml
 
<domain type='kvm'>
  <name>zimbra</name>
  <uuid>e2a3f414-0d6b-c8d6-bfb9-82914e87ebd7</uuid>
  <memory>512000</memory>
  <currentMemory>512000</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
[username]@server:/srv/data/pics$ 
 
Now I am getting closer. But I see config files for the zimbra in /etc/kvm and /etc/libvirt/qemu. Maybe the /etc/kvm stuff is a remnant of an earlier install attempt, since virsh responds to the libvirt/qemu folder.
 
virsh # define zimbra.xml
Domain zimbra defined from zimbra.xml
 
virsh # start zimbra
libvir: Remote error : socket closed unexpectedly
error: Failed to start domain zimbra
 
virsh # quit
 
Will look into this tomorrow, maybe restarting the daemon will help.
 
torusJKL's picture

Maybe it is a problem with rights?

try

sudo chmod 774 /srv/vm/templates/images/turnkey/turnkey-zimbra-2009.10-2-hardy-x86/turnkey-zimbra-2009.10-2-hardy-x86.vmdk.img


Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)