如何利用xen3.2 在 ubuntu 8.04虚拟Windows系统
创始人
2024-03-21 14:01:01
0

1、安装虚拟主机
更改root密码 
~#sudo passwd root
安装xen服务器
~#apt-get install ubuntu-xen-server
安装lvm2
~#apt-get install lvm2
~#reboot
2、准备LVM-backed VBDs
创建lvm分区
~# fdisk /dev/sda
The number of cylinders for this disk is set to 19457.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (2008-19457, default 2008):
Using default value 2008
Last cylinder or +size or +sizeM or +sizeK (2008-19457, default 19457):
Using default value 19457
Command (m for help): t
Partition number (1-5): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
查看分区情况
~# fdisk /dev/sda -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x624aa2e0
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          62      497983+  83  Linux
/dev/sda2              63        1278     9767520    5  Extended
/dev/sda3            1279        2007     5855692+  82  Linux swap / Solaris
/dev/sda4            2008       19457   140167125   8e  Linux LVM
/dev/sda5              63        1278     9767488+  83  Linux
重启系统,使刚划分的分区有效,否则你用pvcreate或其它工具对这个分区进行操作,会产生无此分区的错误
~#reboot
创建物理卷
~# pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created
建立卷组
~# vgcreate vg1 /dev/sda4
  Volume group "vg1" successfully created
建立逻辑卷
~# lvcreate -L15G -nvbox01-winxp vg1
  Logical volume "vbox01-winxp" created
格式化刚建立的逻辑卷
~# mkfs.ext3 /dev/vg1/vbox01-winxp
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
挂载和卸载逻辑卷
~# mount /dev/vg1/vbox01-winxp /mnt
~# umount /mnt

#P#

3、建立虚拟客户机(winxp)
建立虚拟机配置文件
~# vi /etc/xen/vbox01-winxp.cfg
kernel='/usr/lib64/xen/boot/hvmloader'
builder='hvm'
name='vbox01-winxp'
device_model='/usr/lib64/xen/bin/qemu-dm'
disk=['phy:/dev/vg1/vbox01-winxp,hda,w','phy:/dev/loop0,hdc:cdrom,r']
boot='dc'
memory='512'
vcpus=3
vif=['type=ioemu,mac=00:21:41:e2:00:01,bridge=eth0']
on_poweroff='destroy'
on_reboot='restart'
on_crash='restart'
vnc=1
vnclisten='0.0.0.0'
vncdisplay=0
vncunused=1
vncpasswd='pass'
sdl=0
usb=1
usbdevice='mouse'
挂载ISO到模拟光驱
查找空闲loop设备
~# losetup -f
/dev/loop0
挂载ISO镜象到loop0
~# losetup -f /home/wxt/VRMPVOL_EN.iso
root@vbox01:~# losetup -a
/dev/loop0: [0805]:383528 (/home/wxt/VRMPVOL_EN.iso)
卸载模拟光驱
~# losetup -d /dev/loop0
重新挂载
~# losetup -f /home/wxt/VRMPVOL_EN.iso
开启虚拟客户机vbox01-winxp.cfg
~# xm create vbox01-winxp.cfg
Using config file "/etc/xen/vbox01-winxp.cfg".
Started domain vbox01-winxp
现在就可以用vnc连接到虚拟主机的IP,就可以使用虚拟客户机vbox01-winxp了
关掉vbox01-winxp
~# xm shutdown vbox01-winxp
4、利用dd复制虚拟客户机
# lvcreate -L15G -n vbox01-dcd vg1
  Logical volume "vbox01-dcd" created
# dd if=/dev/vg1/vbox01-winxp of=/dev/vg1/vbox01-dcd
31457280+0 records in
31457280+0 records out
16106127360 bytes (16 GB) copied, 1592.12 s, 10.1 MB/s
~# vi /etc/xen/vbox01-dcd.cfg
kernel='/usr/lib64/xen/boot/hvmloader'
builder='hvm'
guest_os_type='winxp'
name='vbox01-dcd'
device_model='/usr/lib64/xen/bin/qemu-dm'
disk=['phy:/dev/vg1/vbox01-dcd,hda,w','phy:/dev/loop0,hdc:cdrom,r']
boot='dc'
memory='512'
shadow_memory='32'
vcpus='3'
acpi=1
apic=1
vif=['type=ioemu,mac=00:21:41:e2:00:02,bridge=eth0']
on_poweroff='destroy'
on_reboot='restart'
vnclisten='0.0.0.0'
vnc=1
vncdisplay=1
vncunused=1
vncpasswd='password'
sdl=0
usb=1
usbdevice='mouse'
相对于被复制的主机,这里主要改四个地方
主机名vbox01-winxp => vbox01-dcd
虚拟硬盘phy:/dev/vg1/vbox01-winxp => phy:/dev/vg1/vbox01-dcd
网卡MAC地址00:21:41:e2:00:01 => 00:21:41:e2:00:02
VNC连接端口vncdisplay=0 => vncdisplay=1
vbox01-dcd开机
~#xm create vbox01-dcd.cfg
~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  2702     3     r-----   2687.9
vbox01-dcd                                  23   512     2     r-----     14.7
vbox01-winxp                                22   512     2     -b----   1293.5
~# netstat -ln|grep 590[0-9]
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN
5、利用xm restore备份和恢复虚拟客户机
~# xm save vbox01-winxp /mnt/winxp.back
~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   988     3     r-----  27570.4
~# ls -l /mnt/winxp.back
-rwxr-xr-x 1 root root 553009093 2009-02-02 21:15 /mnt/winxp.back
~# xm create vbox01-winxp.cfg
Using config file "./vbox01-winxp.cfg".
Started domain vbox01-winxp
在vbox01-winxp内新建文件等操作,更改虚拟机状态
~# xm shutdown vbox01-winxp
~# xm restore /mnt/winxp.back
~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   988     3     r-----  27603.9
vbox01-winxp                                57   512     2     r-----      5.8
进入vbox01-winxp系统,又恢复到备份点了

【编辑推荐】

  1. Ubuntu下web开发 常见问题与解决方法
  2. 在Ubuntu下建立PowerPC405EP的开发环境
  3. Ubuntu将推针对虚拟技术的JeOS开源版本

相关内容

热门资讯

PHP新手之PHP入门 PHP是一种易于学习和使用的服务器端脚本语言。只需要很少的编程知识你就能使用PHP建立一个真正交互的...
网络中立的未来 网络中立性是什... 《牛津词典》中对“网络中立”的解释是“电信运营商应秉持的一种原则,即不考虑来源地提供所有内容和应用的...
各种千兆交换机的数据接口类型详... 千兆交换机有很多值得学习的地方,这里我们主要介绍各种千兆交换机的数据接口类型,作为局域网的主要连接设...
什么是大数据安全 什么是大数据... 在《为什么需要大数据安全分析》一文中,我们已经阐述了一个重要观点,即:安全要素信息呈现出大数据的特征...
如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
Intel将Moblin社区控... 本周二,非营利机构Linux基金会宣布,他们将担负起Moblin社区的管理工作,而这之前,Mobli...
P2P的自白|我不生产内容,我... 现在一提起P2P,人们就会联想到正在被有关部门“围剿”的互联网理财服务。×租宝事件使得劳...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...