注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

艾伯特的鸟屋

 
 
 

日志

 
 

Ubuntu 11.10, 12.04上安装xen以及部分虚拟化GuestOS实例  

2012-07-21 08:08:08|  分类: linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

本文在https://help.ubuntu.com/community/Xen基础上进行简单改造实现的。

安装Xen

Install a 64-bit hypervisor. (A 64-bit hypervisor works with a 32-bit dom0 kernel, but allows you to run 64-bit guests as well.)

sudo apt-get install xen-hypervisor-amd64

Modify GRUB to default to booting Xen:

sudo sed -i 's/GRUB_DEFAULT=.*\+/GRUB_DEFAULT="Xen 4.1-amd64"/' /etc/default/grub

sudo update-grub

Set the default toolstack to xm (aka xend):

sudo sed -i 's/TOOLSTACK=.*\+/TOOLSTACK="xm"/' /etc/default/xen

Now reboot:

sudo reboot

And then verify that the installation has succeeded:

sudo xm list

Name ID Mem VCPUs State Time(s)

Domain-0 0 945 1 r----- 11.3

Network Configuration

This section describes how to set up linux bridging in Xen. It assumes eth0 is both your primary interface to dom0 and the interface you want your VMs to use. It also assumes you're using DHCP.

sudo apt-get install bridge-utils

Edit /etc/network/interfaces, and make it look like this:

具体实例:

#cat /etc/network/interfaces

auto lo

iface lo inet loopback

auto virbr0

iface virbr0 inet dhcp

auto xenbr0

iface xenbr0 inet dhcp

bridge_ports eth0

auto eth0

iface eth0 inet manual

auto wlan0

iface wlan0 inet dhcp


Restart networking to enable xenbr0 bridge:

sudo service network-manager restart

: 我采用network-manager管理我的网络,包括无线网络



The brctl command is useful for providing addition bridge information. See: man brctl

具体实例

#brctl show

bridge name bridge id STP enabled interfaces

virbr0 8000.feffffffffff yes vif5.0

xenbr0 8000.002713b683c5 no eth0



创建半虚拟化的Guest Linux-likeOS:

There are many options for installing guest images:

xen-tools: A set of scripts for creating various PV guests

virt-manager.org: A management system using libvirt

Converting an existing installation

Downloading pre-build guest images (e.g. http://wiki.xen.org/wiki/Guest_VM_Images)

Or you can manually create one, as described below.

Manually creating a PV Guest VM :

In this section we will focus on Paravirtualized (or PV) guests. PV guests are guests that are made Xen-aware and therefore can be optimized for Xen.

As a simple example we'll create a PV guest in LVM logical volume (LV) by doing a network installation of Ubuntu (other distros such as Debian, Fedora, and CentOS can be installed in a similar way).

sudo pvs

choose your VG

create LV

sudo lvcreate -L 4G -n ubuntu /dev/<VG>

也可以创建虚拟盘,而不是直接采用物理磁盘:

sudo dd if=/dev/zero of=/root/mydisk.img bs=1M seek=8000 count=1

如上命令创建了一个虚拟硬盘mydisk.img


get netboot images

choose an archive mirror https://launchpad.net/ubuntu/+archivemirrors

sudo mkdir -p /var/lib/xen/images/ubuntu-netboot

cd /var/lib/xen/images/ubuntu-netboot

sudo wget <mirror>/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz

wget <mirror>/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz

With a specific mirror chosen:

sudo mkdir -p /var/lib/xen/images/ubuntu-netboot

cd /var/lib/xen/images/ubuntu-netboot

sudo wget http://mirror.anl.gov/pub/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz

sudo wget http://mirror.anl.gov/pub/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz

Set up the initial guest configuration: /etc/xen/ubuntu.cfg

name = "ubuntu"

memory = 256

#disk = ['phy:/dev/<VG>/ubuntu,xvda,w']

disk = ['file:/var/lib/xen/images/ubuntu-netboot/alubuntu.img,ioemu:hda,w']

vif = [' ']

kernel = "/var/lib/xen/images/ubuntu-netboot/vmlinuz"

ramdisk = "/var/lib/xen/images/ubuntu-netboot/initrd.gz"

extra = "debian-installer/exit/always_halt=true -- console=hvc0"

Start the VM and connect to console (-c):

sudo xm create /etc/xen/ubuntu.cfg -c

Do the install.

Once installed, we can use pygrub as the bootloader.

sudo ln -s /usr/lib/xen-4.1/bin/pygrub /usr/bin/pygrub

Once the install is done, the VM will shutdown. Next change the guest config, /etc/xen/ubuntu.cfg:

name = "ubuntu"

memory = 256

#disk = ['phy:/dev/<VG>/ubuntu64,xvda,w']

disk = ['file:/var/lib/xen/images/ubuntu-netboot/alubuntu.img,ioemu:hda,w']

vif = [' ']

bootloader = "pygrub"

#kernel = "/var/lib/xen/images/ubuntu-netboot/amd64/vmlinuz"

#ramdisk = "/var/lib/xen/images/ubuntu-netboot/amd64/initrd.gz"

#extra = "debian-installer/exit/always_halt=true -- console=hvc0"

Start the VM and connect to console (-c):

sudo xm create /etc/xen/ubuntu.cfg -c


关闭VM

sudo xm shutdown ubuntu


参考文献:

https://help.ubuntu.com/community/Xen


  评论这张
 
阅读(379)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017