Create CentOS 5.2 Domu on Ubuntu Hardy Dom0

Want to support HowtoForge? Become a subscriber!
 
Submitted by Camran (Contact Author) (Forums) on Mon, 2008-10-06 16:32. :: CentOS | Ubuntu | Xen | Virtualization

Create CentOS 5.2 Domu on Ubuntu Hardy Dom0

Author: Cameron Sarkary <ksarkary [at] gmail [dot] com>
Last edited 09/09/2008

This tutorial provides step-by-step instructions on how to install Images of xen on an Ubuntu Hardy Heron (Ubuntu 8.04) server system (i386). Linux distributions that can run as Xen guests out of the box, obviating the need to create your own custom filesystems. The filesystems on jailtime.org have already been tweaked to deal with Xen’s idiosyncracies, and are also designed to be lightweight and minimally divergent from the original distribution.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

I will use Ubuntu Hardy Heron (i386) for the host OS (dom0) and CentOS 5.2 for the guest operating systems (domU).

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1. Download the CentOS 5.1 image from jailtime. http://jailtime.org/download:centos:v5.2

2. Untar the image:

tar -xjf centos.5-2.20080708.img.tar.bz2

3. Create directories under /mnt to mount image your downloaded from jailtime and in our case lvm parition.

mkdir /mnt/img
mkdir /mnt/vm1

4. Prepare file-based image (note: this is a meager setup of 1GB root / and 128MB swap, you'll likely want much more for a real-world VM):

mkdir -p /home/xen/domains/centos
cd /home/xen/domains/centos
dd if=/dev/zero of=Cent_base.img bs=1024k count=1024
dd if=/dev/zero of=Cent_swap.img bs=1024k count=128
mkfs.ext3 diskimage
mkswap swapimage

5. Mount jailtime image and lvm partition image.

mount -o loop centos.5-2.img /mnt/img
mount -o loop /home/xen/domains/centos/Cent_base.img /mnt/vm1

6. Copy the image files to our VM image i.e on lvm parition.

cp -a /mnt/img/* /mnt/vm1/

7. Configure IP for domU. I don’t think I need to explain this step.

cat /mnt/vm1/etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.254

8. Configure domU hostname.

cat /mnt/vm1/etc/sysconfig/network

NETWORKING=yes
HOSTNAME=complay

9. For me the xm console never worked until I have used this line in /mnt/vm/etc/inittab, I hope you know where to put following line in /mnt/vm1/etc/inittab, otherwise learn about inittab first please.

1:2345:respawn:/sbin/mingetty console

10. root logins are not allowed on default jailtime image, so if you need them you can enable them too, or if you change your SSH port to something unusual you can do that too in /mnt/vm/etc/ssh/sshd_config; change following:

Port 2023
PermitRootLogin yes

11. Unmount both images.

umount /mnt/img /mnt/vm

12. My domU config file looks like following:

cat centos.cfg

name = 'cent5'


kernel = '/boot/vmlinuz-2.6.24-16-xen'
ramdisk = '/boot/initrd.img-2.6.24-16-xen'
memory  = '128'


root    = '/dev/sda1 ro'

disk    = [ 'tap:aio:/home/xen/mnt/cent_base.img,sda1,w', 'tap:aio:/home/xen/mnt/cent_swap.img,sda2,w' ]


dhcp = 'dhcp'
vif  = [ '' ]


on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

13. Start your domU:

xm create -c /etc/xen/centos.cfg

14. You will see a nice login prompt like the following:

CentOS release 5.2 (Final)
Kernel 2.6.24-16-xen on an i686

localhost login:

15. Log in as root, default root password for jailtime image is “password”.

16. Change your root password first.

17. Enter nameservers in /etc/resolv.conf.

18. If you want to resize an image file:

First, make sure that the image file is not already mounted and is not already running as a xen guest. The following commands increase an image file to 4GB. Back up the image before attempting this.

dd if=/dev/zero of=/home/xen/domains/centos/Cent_base.img bs=1M conv=notrunc count=1 seek=4000
losetup /dev/loop0 /home/xen/domains/centos/Cent_base.img
e2fsck -f /dev/loop0
resize2fs /dev/loop0
e2fsck -f /dev/loop0
losetup -d /dev/loop0

You may then boot or mount the image to confirm the increased size. The e2fsck checks in this howto are not strictly necessary.

 

Links

http://jailtime.org/


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 lalo (not registered) on Thu, 2010-06-10 09:36.

[root@testServer]# losetup /dev/loop0 xentest.img
[root@testServer lgh]# e2fsck -f /dev/loop0
e2fsck 1.39 (29-May-2006)
Couldn't find ext2 superblock, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/loop0

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

[root@testServer lgh]# resize2fs /dev/loop0
resize2fs 1.39 (29-May-2006)
resize2fs: Bad magic number in super-block while trying to open /dev/loop0
Couldn't find valid filesystem superblock.

Submitted by Anonymous (not registered) on Tue, 2009-10-27 12:38.

Hi

i am getting error when I start the vm

xm create -c vm

my config file look like this

kernel= "/xen/xen-3.4.1/dist/install/boot/vmlinuz-2.6.18.8-xenU"
memory = 128
name = "mailserver"
vif = [ 'mac=00:16:3e:00:00:11,bridge=xenbr0' ]
disk = ['file:/lakxen/suselinux/image/centos.5-3.x86.gnome.img,sda1,w']
root = "/dev/sda2 ro xencons=tty"

i8042.c: No controller found.
mice: PS/2 mouse device common for all mice
TCP bic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
Using IPI No-Shortcut mode
xen-vbd: registered block device major 8
blkfront: sda1: barriers enabled
XENBUS: Device with no driver: device/console/0
Root-NFS: No NFS server available, giving up.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "sda2" or unknown-block(2,0)
Please append a correct "root=" boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

Submitted by Anonymous (not registered) on Fri, 2009-01-23 18:07.

I'm stuck!

The "mkfs.ext3 diskimage" gives me this error:

"Could not stat diskimage --- No such file or directory

The device apparently does not exist; did you specify it correctly?"

Submitted by Anonymous (not registered) on Tue, 2009-03-10 05:45.

Me too. However I'm looking at this somewhat unrelated how-to: 

http://www.watters.ws/wiki/index.php/How_to_Build_a_CentOS_3_Template

 ...An am inferring that one should replace the give mkfs commands with:

dd if=/dev/zero of=Cent_base.img bs=1024k count=1024
dd if=/dev/zero of=Cent_swap.img bs=1024k count=128
mkfs.ext3 Cent_base.img
mkswap Cent_swap.img

 ...The mkfs.ext3 then says "Cent_base.img is not a block special device. Proceed anyway? (y,n)"  ...to which I say yes.

 

Submitted by Boris (not registered) on Wed, 2008-10-22 18:15.

http://lxer.com/module/newswire/view/110642/index.html