Installing Xen On An Ubuntu 7.10 (Gutsy Gibbon) Server From The Ubuntu Repositories - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2007-11-04 18:37. ::

3 Creating Virtual Machines (domU)

Now let's create our first guest domain, xen1.example.com, running Gutsy Gibbon (gutsy) 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.22-14-xen \
--initrd=/boot/initrd.img-2.6.22-14-xen --debootstrap --dist=gutsy \
--mirror=http://de.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 \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.22-14-xen \
--initrd=/boot/initrd.img-2.6.22-14-xen --debootstrap --dist=gutsy \
--mirror=http://de.archive.ubuntu.com/ubuntu/ --passwd> --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.22-14-xen \
> --initrd=/boot/initrd.img-2.6.22-14-xen --debootstrap --dist=gutsy \
> --mirror=http://de.archive.ubuntu.com/ubuntu/ --passwd
Unknown option: debootstrap

General Information
--------------------
Hostname       :  xen1.example.com
Distribution   :  gutsy
Fileystem Type :  ext3

Size Information
----------------
Image size     :  2Gb
Swap size      :  256Mb
Image type     :  sparse
Memory size    :  64Mb
Kernel path    :  /boot/vmlinuz-2.6.22-14-xen
Initrd path    :  /boot/initrd.img-2.6.22-14-xen

Networking Information
----------------------
IP Address 1   : 192.168.0.101
Netmask        : 255.255.255.0
Broadcast      : 192.168.0.255
Gateway        : 192.168.0.1


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

Creating disk 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 script 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.5 on Tue Oct 30 14:55:46 2007.
#
#
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.22-14-xen'
ramdisk     = '/boot/initrd.img-2.6.22-14-xen'
memory      = '64'
#
#  Disk device(s).
#
root        = '/dev/hda1 ro'
disk        = [ 'file:/home/xen/domains/xen1.example.com/disk.img,hda1,w', 'file:/home/xen/domains/xen1.example.com/swap.img,hda2,w' ]
#
#  Hostname
#
name        = 'xen1.example.com'
#
#  Networking
#
vif         = [ 'ip=192.168.0.101' ]
#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

(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.5 on Tue Oct 30 14:55:46 2007.
#
#
#  Kernel + memory size
#
kernel      = '/boot/vmlinuz-2.6.22-14-xen'
ramdisk     = '/boot/initrd.img-2.6.22-14-xen'
memory      = '64'
vcpus       = '2'
#
#  Disk device(s).
#
root        = '/dev/hda1 ro'
disk        = [ 'file:/home/xen/domains/xen1.example.com/disk.img,hda1,w', 'file:/home/xen/domains/xen1.example.com/swap.img,hda2,w' ]
#
#  Hostname
#
name        = 'xen1.example.com'
#
#  Networking
#
vif         = [ 'ip=192.168.0.101' ]
#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

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).

To get a list of running virtual machines, type

xm list

The output should look like this:

root@server1:~# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      327     1 r-----    687.7
xen1.example.com                           1       64     1 -b----     22.4
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 and Feisty Fawn (feisty) as the operating system:

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.22-14-xen \
--initrd=/boot/initrd.img-2.6.22-14-xen --debootstrap --dist=feisty \
--mirror=http://de.archive.ubuntu.com/ubuntu/ --passwd

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

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

... 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 akurtz (registered user) on Wed, 2008-01-09 06:17.

Gutsy has xen-tools version 3.5, and from 3.2 on --deboostrap and --rpmstrap are obsolete. See the man page or http://www.xen-tools.org/software/xen-tools/upgrading.html
That said, the version of rpmstrap available on gutsy does not work out of the box for xen. I'm still working on that.

Submitted by amorris (registered user) on Mon, 2007-11-19 09:05.

Falko, Thanks for a great tutorial.

I tried it and was most impressed, until... I rebooted the guest.

From there on in whenever the guest is started it will not attach to the network! You cannot ping it, you cannot ssh, you cannot get a console - more Dr Zeus then xen (sorry).

Well after a couple of late nights  I found that the config file needs to know the original mac address in order to re-start the machine. Perhaps the create-xen-image command has inherited more security since you first did the tutorial - apparmour? Anyway, here are my suggested add-ons to the above:

Obtain the MAC address first thing after you boot the guest ie:

ping xen1

arp xen1

Now configure the virtual NIC to always use that MAC address:

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

vif         = [ 'mac=00:16:3E:6C:A5:5C', 'ip=192.168.0.106' ]

 

Voila! 


Submitted by mossholderm (registered user) on Fri, 2008-01-25 03:31.

I add the following two lines to /etc/udev/rules.d/70-persistent-net.rules. They cause the OS to assign the interfaces by the device path, rather than the MAC address, which is what leads to the problem you are seeing.

SUBSYSTEM=="net", SUBSYSTEMS=="xen", DRIVERS=="vif", ATTRS{nodename}=="device/vif/0", NAME="eth0"
SUBSYSTEM=="net", SUBSYSTEMS=="xen", DRIVERS=="vif", ATTRS{nodename}=="device/vif/1", NAME="eth1"
Submitted by stephenhow (registered user) on Wed, 2008-04-02 02:39.

Thanks for the net rules, they did the trick.  But, it took me a while to figure out that the /etc/udev/rules.d/70-persistent-net.rules file to fix is on the domU disk image.  I tried changing the one on my actual (dom0) boot disk, and got very confused.  Once I realised that it was the domU having the network problems, and that I needed only to fix it's /etc/udev/rules.d/ and it's /etc/networking/interfaces was ok.  (I use LVM, so I just mounted the domU root disk and fixed it before starting it up with 'xm create'.)

 

Submitted by stephenhow (registered user) on Wed, 2008-04-02 13:17.

I wrote up a little how-to configure the /etc/udev/rules.d/70-persistent-net.rules and the vif in the domU .cfg to solve the problem of networking not working, or networking stops working, or eth interface number increasing:

http://adminstuff.wikidot.com/xen-bridge-networking