XEN: CentOS 5.1 guest on a CentOS 5.1 host mini howto

Fri, 03/14/2008 - 13:15 by Damien Saucez • Categories:

Introduction

In this small tutorial, we present how to setup CentOS guests with the standard tools proposed by CentOS.

By default, CentOS gives good tools to rapidly create networked guests, see by yourself:

Host preparation

  • Configure Xen for private networking:
    1. Virtual networks can be configured in /etc/libvirt/qemu/networks/autostart/default.xml. The default configuration is good enough for us but feel free to modify it:
      <network>
        <name>default</name>
        <uuid>8f5a5558-31d0-4680-b326-347ba547d552</uuid>
        <bridge name="virbr0" />
        <forward/>
        <ip address="192.168.122.1" netmask="255.255.255.0">
          <dhcp>
            <range start="192.168.122.2" end="192.168.122.254" />
          </dhcp>
        </ip>
      </network>
      

      This default configuration create a bridge/nat named virbr0 with IP address 192.168.122.1. It also offers DHCP leases in the range 192.168.122.2-192.168.122.254.

      For static IP allocation, just use addresses within 192.168.122.0/24 except 192.168.122.1 which is reserved. The DNS server and the router must be both the IP address of the bridge (192.168.122.1).

      If you modify this file, restart libvirt:

       [usr@host ~]$ sudo service libvirtd restart
      
    2. Change parameters of network-script in etc/xen/xend-config.sxp in order to use interface virbr0:

       (network-script 'network-bridge bridge=virbr0')
      
    3. Restart Xend:

       [usr@host ~]$ sudo service xend restart
      

Guest install

  • create the file that will get the installation (do not use the standard virt-install!):
     [usr@host ~]$ sudo dd if=/dev/zero of=</path/to/the/image> bs=1M count=<size_of_the_image_in_MB>
    
  • start the CentOS installation:

    [usr@host ~]$ sudo virt-install
    Would you like a fully virtualized guest (yes or no)?  This will allow you to run unmodified operating systems.
     no
    What is the name of your virtual machine?
     <vt_name>
    How much RAM should be allocated (in megabytes)?
     <memory_needed>
    What would you like to use as the disk (path)?
     </path/to/the/image>
    Would you like to enable graphics support? (yes or no)
     no
    What is the install location?
     http://centos.info.ucl.ac.be/centos/5.1/local/i386
     
    
    Starting install...
    

The CentOS installation begins, you can use DHCP or fixed IP address.

You now have a fresh CentOS guest, enjoy!

Post install:

Local repositories

In order to use our local repository on the guest, add a file /etc/yum.repos.d/ingi.repo with the following content:

 [ingi]
 name=INGI CentOS repository - $releasever - $basearch
 baseurl=http://centos.info.ucl.ac.be/centos/$releasever/local/i386
 gpgcheck=0

 [ingi-java]
 name=INGI CentOS Java repository - $releasever - $basearch
 baseurl=http://centos.info.ucl.ac.be/centos/$releasever/java/i386
 gpgcheck=0

Update the installation:

[root@guest ~]# yum update

New virtual disk

Here we show how to create a virtual disk for the guest.

  1. Create the virtual disk on the host:
     [usr@host ~]$ sudo dd if=/dev/zero of=</path/to/the/virtual_disk> bs=1M count=<size_of_the_virtual_disk_in_MB>
    
  2. Add the virtual disk in the list of guest's virtual disks by modifying file /etc/xen/<vt_name>. Here we chose to name it xvdb:

    disk = [ "tap:aio:/path/to/the/image,xvda,w", "tap:aio:/path/to/the/virtual_disk,xvdb,w" ]
    
  3. Attach the new virtual disk to the guest:

     [usr@host ~]$ sudo xm block-attach <vt_name> tap:aio:</path/to/the/virtual_disk> /dev/xvdb w
    
  4. Create/format/mount guest's partitions:

     [root@guest ~]# fdisk /dev/xvdb
     ...
     [root@guest ~]# mkfs.ext3 /dev/xvdb<n>
     ...
     [root@guest ~]# mount /dev/xvdb<n> </path/for/partition/n>
    

Thanks

Thanks to Pierre Reinbold for the dd hint for virt-install