歡迎您光臨本站 註冊首頁

Centos5.4 xen虛擬化技術應用

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

Centos5.4 xen虛擬化技術應用

本人轉自我的博客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/dists/lenny/main/installer-i386/current/images/netboot/xen/vmlinuz

wget http://ftp.nl.debian.org/debian/dists/lenny/main/installer-i386/current/images/netboot/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# leaf1981


    請教lz,我碰到了你在「2.基於複製本機文件生成Centos5.4虛擬機」中描述的問題,並且也重新製作了initrd文件,但是仍然沒辦法啟動虛擬機,還是會報如下錯誤:請教,是什麼問題呢?

# 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 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #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=13309218)
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 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #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=13309218)
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: [email protected]
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!
#
《解決方案》

一般來講的話是IMG的問題,貼出你的xen conf文檔看看
《解決方案》

回復 9# leaf1981


    恩,問題找到了,是不能chroot到新建立的 / 下面,因為我的機器裝的是64為的centos5.5,所以少拷貝了一個目錄lib64.導致在切換過去的時候,報錯~~~

[火星人 ] Centos5.4 xen虛擬化技術應用已經有621次圍觀

http://coctec.com/docs/service/show-post-5268.html