Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1718462
  • 博文数量: 163
  • 博客积分: 10591
  • 博客等级: 上将
  • 技术积分: 1980
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-08 18:17
文章分类

全部博文(163)

文章存档

2018年(1)

2012年(1)

2011年(47)

2010年(58)

2009年(21)

2008年(35)

分类: LINUX

2009-06-15 15:26:54

Making Guest Domains

(Adapted from )

To run virtual domains on top of the host machine, one must create a disk image with some operating system installed on it. The following instructions will show you how to set up a SL4 disk image for Xen.

1. As root on a machine that has Xen installed, create a directory to store the images in. It doesn't matter where you create this directory, but make sure that there is enough disk space left on the partition (approximately 2GB) and that it is not going to be deleted accidentally (i.e. in /root/ is a good place).

$ mkdir xen-images

2. Descend into the directory and create a mountpoint for the images. This will be used later for the loopback interface to access the image as a separate partition.

$ cd xen-images
$ mkdir mnt

3. Create a 1GB image file and a 500MB swap file. dd essentially creates an empty file on disk of whatever size you specify. FOr instance, the first line (below) creates a file named sl4guest_base.img of size 1024k * 1000, or 1GB.

$ dd if=/dev/zero of=sl4guest_base.img bs=1024k count=1000
$ dd if=/dev/zero of=sl4guest_base-swap.img bs=1024k count=500

4. Change permissions on the images. This is just good policy for security, since if someone has write access to the images, they can modify the OS installed inside.

$ chmod 640 sl4guest_base*

5. Format the image file as ext3 and the swap file as swap space.

$ mkfs.ext3 sl4guest_base.img
$ mkswap sl4guest_base-swap.img

6. Mount the image file as a loopback device on the mountpoint you created earlier:

$ mount -o loop sl4guest_base.img mnt/

7. Perform a bootstrap install of SL4. Use for this. rpmstrap allows you to install to a file or partition on a machine that already has a working Linux distribution on it without needing physical access to the machine.

rpmstrap sl402 mnt/

7. Copy the Xen kernel modules from the host system into the image, which is still mounted on mnt/ in the current directory.

cp -a /lib/modules/2.6.16-xen mnt/lib/modules/

8. Disable the thread-local storage (TLS) libraries. This is not required, but your Xen guests will take a performance hit if you do not do this.

mv mnt/lib/tls mnt/lib/tls.disabled

9. Create mnt/etc/hosts. Replace guest below with the hostname of your choice for the guest image.

127.0.0.1       localhost localhost.localdomain guest

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

10. Create mnt/etc/hostname within the mounted image. Replace with your desired hostname, again.

echo  > mnt/etc/hostname

11. Create mnt/etc/sysconfig/network within the mounted image. Replace hostname with your desired hostname, yet again. Change the gateway to point to the subnet gateway machine.

HOSTNAME="hostname" 
NETWORKING=yes
GATEWAY=192.168.16.1

12. Create mnt/etc/sysconfig/network-scripts/ifcfg-eth0. Change IPADDR and GATEWAY to appropriate values.

ONBOOT=yes
BOOTPROTO=none
DEVICE=eth0
IPADDR=192.168.16.5
NETMASK=255.255.255.0
NAME=eth0
GATEWAY=192.168.16.1
TYPE=Ethernet

13. Edit mnt/etc/fstab within the mounted image. This tells the guest system where to mount its hard drives on boot.

proc            /proc       proc    defaults    0 0
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
/dev/hda2 none swap sw

14. Unmount the image. You cannot start a Xen guest domain while the image file is mounted.

$ umount -l mnt/





Configuring a Xen Host Machine

This document will take you through the steps to configure Domain-0 and a guest under Xen. It assumes that you have a working install of Xen on the host machine and a usable guest image file. You will also need a swap image file, as constructed in .

1. As root on the host machine, make sure the xen daemon, xend, is running:

$ ps aux | grep xend If not, start xend: $ /etc/init.d/xend start

2. Save the attached file to the host machine in /etc/xen

3. Open sl4guest.conf using your favorite text editor.

4. The "kernel=" line should point to the Xen kernel installed on the host machine. Change as appropriate on your host machine.

kernel = "/boot/vmlinuz-2.6.16-xen3_86.1_rhel4.1"

5. The "ramdisk=" line should point to the initrd file installed on the host machine in /boot. If one exists that matches the xen kernel, change the following line to point to it.

ramdisk="/boot/initrd-2.6-xen.img"

6. The "memory=" line specifies how much RAM the guest domain will have. For Scientific Linux 4, make sure this is at least 256, as SL4 won't run in anything less.

memory = 256

7. The "name=" line specifies a name for the guest domain, which you will use when giving commands to the xen hypervisor. Each guest domain must have a unique name.

name = "sl4"

8. The "vif=" line specifies a virtual interface for the guest to use for networking. For this set of instructions, do not specify an interface:

vif = [ '' ]

9. The "disk=" line maps image files on disk to devices for the guest domains. In the following example, we are mapping the image file /tmp/sl4_guest_base.img to the guest's /dev/hda1, and it will have read/write access to that "drive". We also map the file /tmp/sl4_guest_base-swap.img to the guest's /dev/hda2 and give it read/write access. The guest's /etc/fstab file will then determine how those two devices get mounted onto the filesystem.

disk = ['file:/tmp/sl4_guest_base.img,hda1,w','file:/tmp/sl4_guest_base-swap.img,hda2,w']

10. Save the file and exit your text editor.

11. Run the following command to check that everything is good to go with Xen:

$ xm list This will list currently running domains, how much memory they are allocated, and what their current state is (although this last bit of information is somewhat unreliable).

12. Start your guest domain:

$ xm create /etc/sl4guest.conf

13. To attach to the console of the guest domain, do:

$ xm console sl4 "sl4" should be replaced by the name that you specified in the guest config file. To detach from the console of a guest and return to Domain-0, hit ctrl-].

14. To set up networking, attach to the guest domain console and log in as root. Open /etc/sysconfig/network in your favorite editor and edit it to look something like this:

HOSTNAME="gsn-vwn1" NETWORKING=yes GATEWAY=192.168.16.1

15. Next, create /etc/sysconfig/network-scripts/ifcfg-eth0 and enter:

ONBOOT=yes BOOTPROTO=none DEVICE=eth0 IPADDR=192.168.16.5 NETMASK=255.255.255.0 NAME=eth0 GATEWAY=192.168.16.1 TYPE=Ethernet This is an example setup for a machine on a network with statically allocated IPs. If you have set up DHCP, you will need to change this slightly.

16. Detach from the console, shutdown the guest domain, and then recreate it. Networking should be up and running



阅读(2147) | 评论(0) | 转发(0) |
0

上一篇:Xen Images with Redhat Tools

下一篇:Torque的安装

给主人留下些什么吧!~~