Installing Xen On An Ubuntu 8.04 (Hardy Heron) Server From The Ubuntu Repositories - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2008-05-06 17:14. ::

3 Creating Virtual Machines (domU)

Now let's create our first guest domain, xen1.example.com, running Hardy Heron (hardy) with the IP address 192.168.0.101:

xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
--initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
--mirror=http://archive.ubuntu.com/ubuntu/ --passwd

A lot of switches are unnecessary here because we specified the same details in /etc/xen-tools/xen-tools.conf but it shows that you can specify the desired settings either on the command line or in /etc/xen-tools/xen-tools.conf. Please make sure that you specify --ide, otherwise your virtual machine might not boot!

(To learn more about the available options, take a look at the xen-create-image man page:

man xen-create-image

)

The xen-create-image command will now create the xen1.example.com virtual machine for us. This can take a few minutes. The output should be similar to this one:

root@server1:~# xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
> --ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
> --dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
> --initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
> --mirror=http://archive.ubuntu.com/ubuntu/ --passwd

General Information
--------------------
Hostname       :  xen1.example.com
Distribution   :  hardy
Partitions     :  swap            256Mb (swap)
                  /               2Gb   (ext3)
Image type     :  sparse
Memory size    :  64Mb
Kernel path    :  /boot/vmlinuz-2.6.24-16-xen
Initrd path    :  /boot/initrd.img-2.6.24-16-xen

Networking Information
----------------------
IP Address 1   : 192.168.0.101 [MAC: 00:16:3E:62:DA:BB]
Netmask        : 255.255.255.0
Broadcast      : 192.168.0.255
Gateway        : 192.168.0.1


Creating partition image: /home/xen/domains/xen1.example.com/swap.img
Done

Creating swap on /home/xen/domains/xen1.example.com/swap.img
Done

Creating partition image: /home/xen/domains/xen1.example.com/disk.img
Done

Creating ext3 filesystem on /home/xen/domains/xen1.example.com/disk.img
Done
Installation method: debootstrap
Done

Running hooks
Done

No role scripts were specified.  Skipping

Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done


Logfile produced at:
         /var/log/xen-tools/xen1.example.com.log
root@server1:~#

There should now be a xen1.example.com configuration file - /etc/xen/xen1.example.com.cfg. Take a look at it to become familiar with virtual machine configuration files:

cat /etc/xen/xen1.example.com.cfg

# Configuration file for the Xen instance xen1.example.com, created
# by xen-tools 3.8 on Tue May  6 16:01:38 2008.
#
#
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.24-16-xen'
ramdisk     = '/boot/initrd.img-2.6.24-16-xen'
memory      = '64'
#
#  Disk device(s).
#
root        = '/dev/hda2 ro'
disk        = [
                  'file:/home/xen/domains/xen1.example.com/swap.img,hda1,w',
                  'file:/home/xen/domains/xen1.example.com/disk.img,hda2,w',
              ]

#
#  Hostname
#
name        = 'xen1.example.com'
#
#  Networking
#
vif         = [ 'ip=192.168.0.101,mac=00:16:3E:62:DA:BB' ]
#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
extra = '2 console=xvc0'

The file: parameter is now deprecated in Xen 3.2, therefore we must edit /etc/xen/xen1.example.com.cfg now and replace file: with tap:aio: (otherwise you'll get an error similar to this one:

Error: Device 769 (vbd) could not be connected. losetup /dev/loop0 /home/xen/domains/xen1.example.com/swap.img failed

when you try to start a vm - see http://ubuntuforums.org/showthread.php?t=770902 as well):

vi /etc/xen/xen1.example.com.cfg

[...]
disk        = [
                  'tap:aio:/home/xen/domains/xen1.example.com/swap.img,hda1,w',
                  'tap:aio:/home/xen/domains/xen1.example.com/disk.img,hda2,w',
              ]
[...]

(Please note: if you have a dual-core CPU and want the virtual machine to use both CPU cores, please add the line vcpus = '2' to the configuration file, like this:

vi /etc/xen/xen1.example.com.cfg

# Configuration file for the Xen instance xen1.example.com, created
# by xen-tools 3.8 on Mon May  5 16:49:32 2008.
#
#
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.24-16-xen'
ramdisk     = '/boot/initrd.img-2.6.24-16-xen'
memory      = '64'
vcpus       = '2'
[...]

Afterwards, in the virtual machine, you can run the command

cat /proc/cpuinfo

to check that both CPU cores are being used by the virtual machine. The output could look like this if your vm is using both cores:

xen1:~# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 75
model name      : AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
stepping        : 2
cpu MHz         : 2210.054
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr
 sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm
 cr8legacy ts fid vid ttp tm stc
bogomips        : 5526.81

processor       : 1
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 75
model name      : AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
stepping        : 2
cpu MHz         : 2210.054
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr
 sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow up pni cx16 lahf_lm cmp_legacy svm
 cr8legacy ts fid vid ttp tm stc
bogomips        : 5526.81

xen1:~#

)

To start the virtual machine, run

xm create /etc/xen/xen1.example.com.cfg

Run

xm console xen1.example.com

to log in on that virtual machine (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it (192.168.0.101).

In the virtual machine (when you use it for the first time), run

mv /lib/tls /lib/tls.disabled

Now back to the host system (dom0). To get a list of running virtual machines, type

xm list

The output should look like this:

root@server1:~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   569     1     r-----    103.6
xen1.example.com                             1    64     1     -b----     60.8
root@server1:~#

To shut down xen1.example.com, do this:

xm shutdown xen1.example.com

If you want vm01 to start automatically at the next boot of the system, then do this:

ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.

Let's create a second vm, xen2.example.com with the IP address 192.168.0.102:

xen-create-image --hostname=xen2.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.102 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
--initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
--mirror=http://archive.ubuntu.com/ubuntu/ --passwd

Then open the configuration file of the vm, /etc/xen/xen2.example.com.cfg, and replace file: with tap:aio: again:

vi /etc/xen/xen2.example.com.cfg

[...]
disk        = [
                  'tap:aio:/home/xen/domains/xen2.example.com/swap.img,hda1,w',
                  'tap:aio:/home/xen/domains/xen2.example.com/disk.img,hda2,w',
              ]
[...]

Afterwards, you can start xen2.example.com like this:

xm create /etc/xen/xen2.example.com.cfg

(Don't forget to run

xm console xen2.example.com

and

mv /lib/tls /lib/tls.disabled

when you're in the vm for the first time!)

... and shut it down like this:

xm shutdown xen2.example.com

A list of all virtual machines that were created with the xen-create-image command is available under

xen-list-images

root@server1:~# xen-list-images
Name: xen1.example.com
Memory: 64
IP: 192.168.0.101

Name: xen2.example.com
Memory: 64
IP: 192.168.0.102
root@server1:~#

To learn more about what you can do with xen-tools, take a look at this tutorial: http://www.howtoforge.com/xen_tools_xen_shell_argo

 

4 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by turk182 (not registered) on Tue, 2010-04-06 22:12.

Hi Falko, when i run:

xm console xen1.example.com

it ask me for a login name and password, what do i write there??

THXS!

Submitted by petervanbussel (registered user) on Tue, 2009-12-08 09:50.

Hi all,

Despite of :

mv /lib/tls /lib/tls.disabled

I get this warning during boot:

***************************************************************
***************************************************************
** WARNING: Currently emulating unsupported memory accesses **
** in /lib/tls glibc libraries. The emulation is **
** slow. To ensure full performance you should **
** install a 'xen-friendly' (nosegneg) version of **
** the library, or disable tls support by executing **
** the following as root: **
** mv /lib/tls /lib/tls.disabled **
** Offending process: init ramfs-tools (pid=15947) **
***************************************************************
***************************************************************

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/260825

and

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/246625

didn't help sofar...

Any suggestions?

Regards, Peter

 

 

Submitted by Anonymous (not registered) on Thu, 2009-01-01 18:45.

Hallo there,

I have installed xen on hardy,and i can start the virtual machine. But when i try to reach it with xm console i'll got an error: "Error 'xen1.example.com.cfg' does not exist. I used a terminal.What went wrong?


Submitted by Anonymous (not registered) on Fri, 2008-09-26 23:06.

WOW !  

 This is the BEST howto I've ever read.  I could not believe that in less than an hour I got Xen working ! 

 You hit every error along the way.  This is my first time using Ubuntu.

 ABSOLUTELY OUTSTANDING JOB !

Submitted by Anonymous (not registered) on Fri, 2008-10-17 19:20.

thx a lot for this great tutorial

 i read other tuts without getting a sole vm to run.

I learnt other things, but yours did the final trick.

 greetings

Submitted by bendix (registered user) on Thu, 2008-07-10 14:59.

Very nice guide! Here is a little addition: 

During system boot and shutdown I get several complaints from /etc/init.d/xendomains due to missing quotes in test statements. In one line there is a duplicate call of "cut". Here is a patch to quieten this:

 root@unics:~# diff -uN xendomains.orig xendomains.new
--- xendomains.orig     2008-07-10 15:48:13.000000000 +0200
+++ xendomains.new      2008-07-10 15:51:53.000000000 +0200
@@ -63,7 +63,7 @@
        echo_rc()
        {
            #echo -n "  [${_SMSG[${_RC_RV}]}] "
-           if test ${_RC_RV} = 0; then
+           if test "${_RC_RV}" = "0"; then
                success "  [${_SMSG[${_RC_RV}]}] "
            else
                failure "  [${_SMSG[${_RC_RV}]}] "
@@ -80,7 +80,7 @@
         else
          echo_rc()
          {
-           if test ${_RC_RV} = 0; then
+           if test "${_RC_RV}" = "0"; then
                log_success_msg "  [${_SMSG[${_RC_RV}]}] "
            else
                log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
@@ -183,7 +183,7 @@
 {
     name=`echo "$1" | cut -d\  -f1`
     name=${name%% *}
-    rest=`echo "$1" | cut cut -d\  -f2-`
+    rest=`echo "$1" | cut -d\  -f2-`
     read id mem cpu vcpu state tm < <(echo "$rest")
 }
 
@@ -193,7 +193,7 @@
     RC=1
     while read LN; do
        parseln "$LN"
-       if test $id = 0; then continue; fi
+       if test "$id" = "0"; then continue; fi
        case $name in
            ($NM)
                RC=0
@@ -268,7 +268,7 @@
 {
     while read LN; do
        parseln "$LN"
-       if test $id = 0; then continue; fi
+       if test "$id" = "0"; then continue; fi
        if test "$state" != "-b---d" -a "$state" != "-----d"; then
            return 1;
        fi
@@ -310,7 +310,7 @@
     echo -n "Shutting down Xen domains:"
     while read LN; do
        parseln "$LN"
-       if test $id = 0; then continue; fi
+       if test "$id" = "0"; then continue; fi
        echo -n " $name"
        if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
            case $name in

Submitted by lyceus (registered user) on Tue, 2008-05-27 21:52.

If you want to avoid manually editing the .cfg file for every server you create using xen-create-image, just run the following (after installing xen-tools): mv /bin/xen-create-image /bin/xen-create-image_old
sed -e 's/file:/tap:aio:/' /bin/xen-create-image_old > /bin/xen-create-image
chmod 0755 /bin/xen-create-image

Submitted by svenix (registered user) on Sat, 2008-07-26 08:41.

I got an error with this fix. I still wasn't able to start virual machine.

The result of this fix in my cfg files is something like this:

 disk        = [
                  'tapaio::/home/xen/domains/svenix/swap.img,hda1,w',
                  'tapaio::/home/xen/domains/svenix/disk.img,hda2,w',
              ]

So I still have to fix this issue manually.

Now I fixed the fix...

sed -e 's/file:/:tap:aio/' /usr/bin/xen-create-image_old > /usr/bin/xen-create-image
chmod 0755 /usr/bin/xen-create-image

Now xen-create-image is working for me.

Submitted by Pete (not registered) on Mon, 2009-01-12 23:52.
It's because it should be tap:aio not tapaio
Submitted by vinsik (registered user) on Thu, 2008-05-22 15:26.

I've had some networking problems xen 3.2 in hardy.
The problem seems to be hardy xen kernel. It drops packets to vifX.0 interfaces. 

Anyway found this post, where people have the same problem:
https://bugs.launchpad.net/ubuntu/+source/xen-3.2/+bug/204010 

I'm running domU's on  kernel from gutsy - vmlinuz-2.6.22-14-xen.
Worked for me.

Submitted by TuxieRootIAM (not registered) on Thu, 2008-12-11 06:27.

For Kernel 2.6.24-22-xen, no patches are required. Everything from Xen installation/configuration to VM creation works perfectly on my case. Just run

apt-get upgrade

If needed, reinstall Xen package. I hope this helps.

Submitted by Matey (not registered) on Mon, 2008-10-06 15:36.

I get this error:

Error: Device 769 (vbd) could not be connected. losetup /dev/loop6 /etc/xen/domains/xen-1/swap.img failed

I changed my xen server's name to xen-1 and changes few things like the IP address.

Also My kernel files are not "...-16-xen.." but -19-xen. I got them corrected too in my .cfg file but still get the above error?

I do have those Virtual files (.img) under //xen/domain/xen-1/  as well!

Anyone know why?

Thank You!

Regards;