免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8832 | 回复: 11

Centos5.4 xen虚拟化技术应用 [复制链接]

论坛徽章:
0
发表于 2010-05-30 23:37 |显示全部楼层
本人转自我的博客http://www.opvps.com 分享给Centos系Xen玩家

1.以文件img磁盘方式存放虚拟机

2.基于复制本机文件生成Centos5.4虚拟机

3.Debian5.0.3虚拟机系统安装

一.以文件方式存放虚拟机

生成映像

dd if=/dev/zero of=/u1/xenvm/centos.img oflag=direct bs=1M seek=40960 count=1

生成40GB的虚拟机映像 不立即分配空间 作为存取文件系统

dd if=/dev/zero of=/u1/xenvm/centos.swap oflag=direct bs=1M seek=512 count=1

生成512M的虚拟机映像 不立即分配空间 作为虚拟机的swap

格式化/u1/xenvm/centos.img

mkfs.ext3 /u1/xenvm/centos.img

格式化swap

mkswap /u1/xenvm/centos.swap

二.其于复制本机文件生成Centos5.4虚拟机

1.mount 出img

mount -o loop /u1/xenvm/centos.img /mnt

2.建系统目录并设权限

mkdir /mnt/{home,proc,opt,sys,tmp}

chmod 777 /mnt/tmp

3.复制系统所需文件

cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} /mnt

cp -ax /lib/modules/$(uname -r) /mnt/lib/modules/$(uname -r)

4.修改如下四个文件

/etc/fstab #分区

/etc/passwd #用户及密码

/etc/hosts #hosts文件

/etc/sysconfig/network #主机名

/etc/sysconfig/network-scripts/ifcfg-eth0 #ip地址

其中/etc/fstab根据主机定义及虚拟机的配置文件定义

主机/etc/fstat如下

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/opt              /opt                    ext3    defaults        1 2

/dev/sdb /u1 ext3    defaults,noatime        1 2

/dev/sdc /u2 ext3    defaults,noatime        1 2

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

LABEL=SWAP-sda3         swap                    swap    defaults        0 0

虚拟机/etc/fstab写成如下

/dev/xvda1               /                       ext3    defaults 1 1

/dev/xvda2               none                    swap    sw       0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

5.生成虚拟机的配置文件/etc/xen/centos.cfg

kernel = “/boot/vmlinuz-2.6.18-164.6.1.el5xen”

ramdisk = “/boot/initrd-2.6.18-164.6.1.el5xen.img”

memory = 256

name = “centos”

vif = [ 'bridge=xenbr0' ]

vcpus=2

disk = ['tap:aio:/u1/xenvm/vm104.img,xvda1,w', 'tap:aio:/u1/xenvm/vm104.swap,xvda2,w']

root = “/dev/xvda1 ro”

6.启动 xm create -c /etc/xen/centos.cfg即可启动

7.备注出现 : No such file or directory这种错误的话

Mounting root filesystem.

mount: could not find filesystem ‘/dev/root’

Setting up other filesystems.

Setting up new root fs

setuproot: moving /dev failed: No such file or directory

no fstab.sys, mounting internal defaults

setuproot: error mounting /proc: No such file or directory

setuproot: error mounting /sys: No such file or directory

Switching to new root and running init.

unmounting old /dev

unmounting old /proc

unmounting old /sys

switchroot: mount failed: No such file or directory

Booting has failed.

则执行如下操作

cd /boot

mkinitrd –omit-scsi-modules –with=xennet –with=xenblk –preload=xenblk initrd-$(uname -r)-no-scsi.img $(uname -r)

再修改/etc/xen/centos.cfg中的ramdisk = “/boot/initrd-2.6.18-164.6.1.el5xen.img”为

ramdisk = “/boot/initrd-2.6.18-164.6.1.el5xen-no-scsi.img”

三.Debian5.0.3虚拟机系统安装

1.下载启动所需的文件

wget http://ftp.nl.debian.org/debian/ ... netboot/xen/vmlinuz

wget http://ftp.nl.debian.org/debian/ ... tboot/xen/initrd.gz

2.设定安装配置文件

/etc/xen/debina.cfg

kernel = “/boot/vmlinuz” #下载的vmlinuz位置

ramdisk = “/boot/initrd.gz” #下载的initrd.gz位置

memory = 256

name = “debian”

vif = [ 'bridge=xenbr0' ]

vcpus=2

disk = [ 'tap:aio:/u1/xenvm/debian.img,xvda,w', ] #按1中生成debian.img无需格式化

3.启动并完成网络安装(建议安装过程debian国内镜相服务器)

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

4.安装完成后修改配置文件如下

/etc/xen/debina.cfg

bootloader=”/usr/bin/pygrub”

memory = 256

name = “debian”

vif = [ 'bridge=xenbr0' ]

vcpus=2

disk = [ 'tap:aio:/u1/xenvm/debian.img,xvda,w', ]

###

全文完!

评分

参与人数 1可用积分 +6 收起 理由
chenyx + 6

查看全部评分

论坛徽章:
0
发表于 2010-06-01 06:16 |显示全部楼层
不错,支持下

论坛徽章:
0
发表于 2010-06-02 11:24 |显示全部楼层
帮顶

论坛徽章:
0
发表于 2010-06-02 19:56 |显示全部楼层
支持,学习了

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
发表于 2010-06-02 20:24 |显示全部楼层
写的不错,收藏了

求职 : Linux运维
论坛徽章:
19
CU大牛徽章
日期:2013-03-13 15:15:0815-16赛季CBA联赛之山东
日期:2016-10-31 10:40:10综合交流区版块每日发帖之星
日期:2016-07-06 06:20:00IT运维版块每日发帖之星
日期:2016-02-08 06:20:00数据库技术版块每日发帖之星
日期:2016-01-15 06:20:00IT运维版块每日发帖之星
日期:2016-01-15 06:20:00IT运维版块每日发帖之星
日期:2016-01-10 06:20:00黄金圣斗士
日期:2015-11-24 10:45:10IT运维版块每日发帖之星
日期:2015-09-01 06:20:00IT运维版块每日发帖之星
日期:2015-08-13 06:20:00IT运维版块每日发帖之星
日期:2015-07-30 09:40:012015年亚洲杯之巴勒斯坦
日期:2015-05-05 10:19:03
发表于 2010-06-02 21:37 |显示全部楼层
好贴一定要顶。呵呵呵,谢谢楼主分享。。

论坛徽章:
0
发表于 2010-06-03 14:48 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
发表于 2010-06-07 16:45 |显示全部楼层
回复 1# leaf1981


    请教lz,我碰到了你在“2.基于复制本机文件生成Centos5.4虚拟机”中描述的问题,并且也重新制作了initrd文件,但是仍然没办法启动虚拟机,还是会报如下错误:请教,是什么问题呢?

[root@Install01 boot]# xm create -c vm02
Using config file "/etc/xen/vm02".
Started domain vm02
Bootdata ok (command line is  root=/dev/sda1 ro )
Linux version 2.6.18-194.3.1.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-4) #1 SMP Thu May 13 13:49:53 EDT 2010
BIOS-provided physical RAM map:
Xen: 0000000000000000 - 0000000040800000 (usable)
No mptable found.
Built 1 zonelists.  Total pages: 264192
Kernel command line:  root=/dev/sda1 ro
Initializing CPU#0
PID hash table entries: 4096 (order: 12, 32768 bytes)
Xen reported: 2659.998 MHz processor.
Console: colour dummy device 80x25
Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
Software IO TLB disabled
Memory: 1013760k/1056768k available (2512k kernel code, 34088k reserved, 1396k data, 184k init)
Calibrating delay using timer specific routine.. 6654.60 BogoMIPS (lpj=1330921
Security Framework v1.0.0 initialized
SELinux:  Initializing.
selinux_register_security:  Registering secondary module capability
Capability LSM initialized as secondary
Mount-cache hash table entries: 256
CPU: L1 I cache: 32K, L1 D cache: 32K
CPU: L2 cache: 256K
CPU: L3 cache: 12288K
CPU: Physical Processor ID: 1
CPU: Processor Core ID: 10
(SMP-)alternatives turned off
Brought up 1 CPUs
checking if image is initramfs... it is
Grant table initialized
NET: Registered protocol family 16
Brought up 1 CPUs
PCI: setting up Xen PCI frontend stub
ACPI: Interpreter disabled.
Linux Plug and Play Support v0.97 (c) Adam Belay
pnp: PnP ACPI: disabled
xen_mem: Initialising balloon driver.
usbcore: registered new driver usbfs
usbcore: registered new driver hub
PCI: System does not support PCI
PCI: System does not support PCI
NetLabel: Initializing
NetLabel:  domain hash size = 128
NetLabel:  protocols = UNLABELED CIPSOv4
NetLabel:  unlabeled traffic allowed by default
NET: Registered protocol family 2
IP route cache hash table entries: 65536 (order: 7, 524288 bytes)
TCP established hash table entries: 262144 (order: 10, 4194304 bytes)
TCP bind hash table entries: 65536 (order: 8, 1048576 bytes)
TCP: Hash tables configured (established 262144 bind 65536)
TCP reno registered
audit: initializing netlink socket (disabled)
type=2000 audit(1275899989.072:1): initialized
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
Initializing Cryptographic API
alg: No test for crc32c (crc32c-generic)
ksign: Installing public key data
Loading keyring
- Added public key 7664334D64FC7447
- User ID: CentOS (Kernel Module GPG key)
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
pci_hotplug: PCI Hot Plug PCI Core version: 0.5
rtc: IRQ 8 is not free.
Non-volatile memory driver v1.2
Linux agpgart interface v0.101 (c) Dave Jones
brd: module loaded
Xen virtual console successfully installed as xvc0
Bootdata ok (command line is  root=/dev/sda1 ro )
Linux version 2.6.18-194.3.1.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-4) #1 SMP Thu May 13 13:49:53 EDT 2010
BIOS-provided physical RAM map:
Xen: 0000000000000000 - 0000000040800000 (usable)
No mptable found.
Built 1 zonelists.  Total pages: 264192
Kernel command line:  root=/dev/sda1 ro
Initializing CPU#0
PID hash table entries: 4096 (order: 12, 32768 bytes)
Xen reported: 2659.998 MHz processor.
Console: colour dummy device 80x25
Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
Software IO TLB disabled
Memory: 1013760k/1056768k available (2512k kernel code, 34088k reserved, 1396k data, 184k init)
Calibrating delay using timer specific routine.. 6654.60 BogoMIPS (lpj=1330921
Security Framework v1.0.0 initialized
SELinux:  Initializing.
selinux_register_security:  Registering secondary module capability
Capability LSM initialized as secondary
Mount-cache hash table entries: 256
CPU: L1 I cache: 32K, L1 D cache: 32K
CPU: L2 cache: 256K
CPU: L3 cache: 12288K
CPU: Physical Processor ID: 1
CPU: Processor Core ID: 10
(SMP-)alternatives turned off
Brought up 1 CPUs
checking if image is initramfs... it is
Grant table initialized
NET: Registered protocol family 16
Brought up 1 CPUs
PCI: setting up Xen PCI frontend stub
ACPI: Interpreter disabled.
Linux Plug and Play Support v0.97 (c) Adam Belay
pnp: PnP ACPI: disabled
xen_mem: Initialising balloon driver.
usbcore: registered new driver usbfs
usbcore: registered new driver hub
PCI: System does not support PCI
PCI: System does not support PCI
NetLabel: Initializing
NetLabel:  domain hash size = 128
NetLabel:  protocols = UNLABELED CIPSOv4
NetLabel:  unlabeled traffic allowed by default
NET: Registered protocol family 2
IP route cache hash table entries: 65536 (order: 7, 524288 bytes)
TCP established hash table entries: 262144 (order: 10, 4194304 bytes)
TCP bind hash table entries: 65536 (order: 8, 1048576 bytes)
TCP: Hash tables configured (established 262144 bind 65536)
TCP reno registered
audit: initializing netlink socket (disabled)
type=2000 audit(1275899989.072:1): initialized
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
Initializing Cryptographic API
alg: No test for crc32c (crc32c-generic)
ksign: Installing public key data
Loading keyring
- Added public key 7664334D64FC7447
- User ID: CentOS (Kernel Module GPG key)
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
pci_hotplug: PCI Hot Plug PCI Core version: 0.5
rtc: IRQ 8 is not free.
Non-volatile memory driver v1.2
Linux agpgart interface v0.101 (c) Dave Jones
brd: module loaded
Xen virtual console successfully installed as xvc0
Event-channel device installed.
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
ide-floppy driver 0.99.newide
usbcore: registered new driver hiddev
usbcore: registered new driver usbhid
drivers/usb/input/hid-core.c: v2.6:USB HID core driver
PNP: No PS/2 controller found. Probing ports directly.
i8042.c: No controller found.
mice: PS/2 mouse device common for all mice
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: bitmap version 4.39
TCP bic registered
Initializing IPsec netlink socket
NET: Registered protocol family 1
NET: Registered protocol family 17
XENBUS: Device with no driver: device/vbd/2049
XENBUS: Device with no driver: device/vif/0
Initalizing network drop monitor service
Write protecting the kernel read-only data: 483k
Red Hat nash version 5.1.19.6 starting
Mounting proc filesystem
Mounting sysfs filesystem
Creating /dev
Creating initial device nodes
Setting up hotplug.
Creating block device nodes.
Loading xenblk.ko module
Registering block device major 8
Loading xennet.ko module
netfront: Initialising virtual ethernet driver.
netfront: device eth0 has flipping receive path.
Loading ehci-hcd.ko module
Loading ohci-hcd.ko module
Loading uhci-hcd.ko module
USB Universal Host Controller Interface driver v3.0
Loading jbd.ko module
Loading ext3.ko module
Loading scsi_mod.ko module
SCSI subsystem initialized
Loading sd_mod.ko module
register_blkdev: cannot get major 8 for sd
Loading megaraid_sas.ko module
megasas: 00.00.04.17-RH1 Wed. Nov. 25, 11:41:51 PST 2009
Loading shpchp.ko module
shpchp: Standard Hot Plug PCI Controller Driver version: 0.4
Loading dm-mod.ko module
device-mapper: uevent: version 1.0.3
device-mapper: ioctl: 4.11.5-ioctl (2007-12-12) initialised: dm-devel@redhat.com
Loading dm-log.ko module
Loading dm-mirror.ko module
Loading dm-zero.ko module
Loading dm-snapshot.ko module
Loading dm-mem-cache.ko module
Loading dm-region_hash.ko module
Loading dm-message.ko module
Loading dm-raid45.ko module
device-mapper: dm-raid45: initialized v0.2594l
Waiting for driver initialization.
Scanning and configuring dmraid supported devices
Creating root device.
Mounting root filesystem.
EXT3-fs: INFO: recovery required on readonly filesystem.
EXT3-fs: write access will be enabled during recovery.
kjournald starting.  Commit interval 5 seconds
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with ordered data mode.
Setting up other filesystems.
Setting up new root fs
no fstab.sys, mounting internal defaults
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
exec of init (/sbin/init) failed!!!: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
[root@Install01 boot]#

论坛徽章:
0
发表于 2010-06-07 18:06 |显示全部楼层
一般来讲的话是IMG的问题,贴出你的xen conf文档看看

论坛徽章:
0
发表于 2010-06-08 10:28 |显示全部楼层
回复 9# leaf1981


    恩,问题找到了,是不能chroot到新建立的 / 下面,因为我的机器装的是64为的centos5.5,所以少拷贝了一个目录lib64.导致在切换过去的时候,报错~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP