Xen的虛擬化分為半虛擬化以及全虛擬化技術,其中半虛擬化主要是通過修改 Linux 核心來完成的虛擬化技術.Xen 的半虛擬化技術主要是用在相同發行版本的 Linux 上,如果你想要使用半虛擬化的方式啟動多個虛擬機器,那麼虛擬機器全部都必須是相同的操作系統,甚至要求相同版本與相同核心的 Linux 發行版本.如果你想要安裝不同版本的 Linux 或者是其他的 OS ( Windows XP) 時,那就得要使用全虛擬化技術了.
全虛擬化技術必須滿足以下條件:
- 硬體支持 英特爾 的 VT 技術 (Virtualization Technology, 英特爾-VT);
- 硬體支持 AMD 的 SVM 技術 (Secure Virtual Machine, AMD-SVM or, AMD-V).
下面來切實體驗一下xen
一、確定你的cpu是否支持虛擬化技術
- # cat /proc/cpuinfo |grep flags |egrep -o 'pae|vmx|svm'
- pae
- svm
- pae
- svm
顯示了PAE以及SVM,說明我的CPU支持全虛擬化技術.
二、安裝Xen
1.安裝Xen的基本程序
- # yum install -y xen*
2.安裝Xen的內核
- # yum install -y kernel-xen*
3.安裝Xen的虛擬管理程序
- # yum install -y virt-manager
以上安裝完畢,就來配置Xen的環境了
三、配置Xen環境
修改grub.conf文件,以Xen的內核來啟動系統
- # grub.conf generated by anaconda
- #
- # Note that you do not have to rerun grub after making changes to this file
- # NOTICE: You do not have a /boot partition. This means that
- # all kernel and initrd paths are relative to /, eg.
- # root (hd0,0)
- # kernel /boot/vmlinuz-version ro root=/dev/sda1
- # initrd /boot/initrd-version.img
- #boot=/dev/sda
- default=0
- timeout=5
- splashimage=(hd0,0)/boot/grub/splash.xpm.gz
- hiddenmenu
- title CentOS (2.6.18-238.12.1.el5xen)
- root (hd0,0)
- kernel /boot/xen.gz-2.6.18-238.12.1.el5
- module /boot/vmlinuz-2.6.18-238.12.1.el5xen ro root=LABEL=/
- module /boot/initrd-2.6.18-238.12.1.el5xen.img
- title CentOS (2.6.18-238.el5)
- root (hd0,0)
- kernel /boot/vmlinuz-2.6.18-238.el5 ro root=LABEL=/
- initrd /boot/initrd-2.6.18-238.el5.img
修改完畢,重啟系統,shell界面就可以看到
- # uname -a
- Linux Xen 2.6.18-238.12.1.el5xen #1 SMP Tue May 31 14:02:29 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
再看一下
- # xm list
- Name ID Mem(MiB) VCPUs State Time(s)
- Domain-0 0 1228 2 r----- 444.8
Xen的log所在地
- # ll /var/log/xen/
- total 44
- drwx------ 2 root root 4096 May 10 05:30 console
- -rw-r--r-- 1 root root 9653 Jun 10 15:07 domain-builder-ng.log
- -rw-r--r-- 1 root root 36 Jun 10 14:53 xend-debug.log
- -rw-r--r-- 1 root root 17855 Jun 10 15:07 xend.log
- -rw-r--r-- 1 root root 36 Jun 10 15:07 xen-hotplug.log
四、建立虛擬機
準備工作
這裡我們安裝虛擬機採用NFS的方式,如果你對你的網路比較自信,也可以採用網路安裝的方式,視具體情況而定.
創建一個NFS Server並將光碟根目錄下的文件copy 進去,同時分享出來並允許Xen宿主機訪問,這個不是重點,就不寫過程了
下面進入真正的虛擬機安裝階段
- # virt-install -n centos -r 512 --vcpus=1
- > --nographic -f /opt/vm/centos.img -s 20 -p
- > -l nfs:192.168.1.249:/home/netinstall
解釋一下各參數的意義:
- -n 代表虛擬機的名字
- -r 分配給虛擬機的內存
- --vcpus 分配給虛擬機的CPU
- --nographic 不適用圖形界面
- -f 虛擬機磁碟映像的所在地
- -s 虛擬機磁碟映像的大小,單位記得是GB
- -p 半虛擬化的方式
- -l 安裝映像的路徑
PS:上面是採用NFS的方式,如果internet比較快,就換成internet上的源,門戶網站sohu,163均有開源的鏡像站點,另外中國科技大學的鏡像站點也不錯
- # 開源鏡像站點
- 163 http://mirrors.163.com
- sohu http://mirrors.sohu.com
- 科大 http://mirrors.ustc.edu.cn
運行上面的安裝虛擬機命令后,會提示以下的信息
- Starting install...
- Retrieving file vmlinuz... | 2.1 MB 00:00
- Retrieving file initrd.img... 85% [=========================== ] 5.6 MB/s | 6.7 MB 00:00 ETA
- Message from syslogd@ at Fri Jun 10 15:07:07 2011 ...
- Xen kernel: Disabling IRQ #16
- Retrieving file initrd.img... | 7.9 MB 00:00
- Creating storage file... | 20 GB 00:00
- Creating domain... | 0 B 00:00
- Connected to domain centos
- Escape character is ^]
- Bootdata ok (command line is method=nfs:192.168.1.249:/home/netinstall)
- Linux version 2.6.18-238.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu Jan 13 16:41:45 EST 2011
- BIOS-provided physical RAM map:
- Xen: 0000000000000000 - 0000000020800000 (usable)
- No mptable found.
- Built 1 zonelists. Total pages: 133120
- Kernel command line: method=nfs:192.168.1.249:/home/netinstall
- Initializing CPU#0
- PID hash table entries: 4096 (order: 12, 32768 bytes)
- Xen reported: 2812.790 MHz processor.
- Console: colour dummy device 80x25
- Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
- Inode-cache hash table entries: 65536 (order: 7, 524288 bytes)
- Software IO TLB disabled
- Memory: 496384k/532480k available (2529k kernel code, 27260k reserved, 1736k data, 196k init)
- Calibrating delay using timer specific routine.. 7050.28 BogoMIPS (lpj=14100572
)- 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: 64K (64 bytes/line), D cache 64K (64 bytes/line)
- CPU: L2 Cache: 1024K (64 bytes/line)
- CPU: Physical Processor ID: 0
- CPU: Processor Core ID: 1
- (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: 32768 (order: 6, 262144 bytes)
- TCP established hash table entries: 131072 (order: 9, 2097152 bytes)
- TCP bind hash table entries: 65536 (order: 8, 1048576 bytes)
- TCP: Hash tables configured (established 131072 bind 65536)
- TCP reno registered
- audit: initializing netlink socket (disabled)
- type=2000 audit(1307689628.858: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 C099FB4D84A418B6
- - 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 method
=nfs:192.168.1.249:/home/netinstall)- Linux version 2.6.18-238.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu Jan 13 16:41:45 EST 2011
- BIOS-provided physical RAM map:
- Xen: 0000000000000000 - 0000000020800000 (usable)
- No mptable found.
- Built 1 zonelists. Total pages: 133120
- Kernel command line: method=nfs:192.168.1.249:/home/netinstall
- Initializing CPU#0
- PID hash table entries: 4096 (order: 12, 32768 bytes)
- Xen reported: 2812.790 MHz processor.
- Console: colour dummy device 80x25
- Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
- Inode-cache hash table entries: 65536 (order: 7, 524288 bytes)
- Software IO TLB disabled
- Memory: 496384k/532480k available (2529k kernel code, 27260k reserved, 1736k data, 196k init)
- Calibrating delay using timer specific routine.. 7050.28 BogoMIPS (lpj=14100572)
- 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: 64K (64 bytes/line), D cache 64K (64 bytes/line)
- CPU: L2 Cache: 1024K (64 bytes/line)
- CPU: Physical Processor ID: 0
- CPU: Processor Core ID: 1
- (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: 32768 (order: 6, 262144 bytes)
- TCP established hash table entries: 131072 (order: 9, 2097152 bytes)
- TCP bind hash table entries: 65536 (order: 8, 1048576 bytes)
- TCP: Hash tables configured (established 131072 bind 65536)
- TCP reno registered
- audit: initializing netlink socket (disabled)
- type=2000 audit(1307689628.858: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 C099FB4D84A418B6
- - 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/51712
- XENBUS: Device with no driver: device/vif/0
- Initalizing network drop monitor service
- Write protecting the kernel read-only data: 498k
- Greetings.
- anaconda installer init version 11.1.2.224 starting
- mounting /proc filesystem... done
- creating /dev filesystem... done
- mounting /dev/pts (unix98 pty) filesystem... done
- mounting /sys filesystem... done
- anaconda installer init version 11.1.2.224 using /dev/xvc0 as console
- trying to remount root filesystem read write... done
- mounting /tmp as ramfs... done
- running install...
- running /sbin/loader
接下來的安裝就和平時的差不多了,順便也貼一下圖.
選擇語言,english
網路的配置界面
具體的IP信息
這裡選擇文本模式
歡迎界面
是否要初始化disk,當然要
這步,不要啥操作,選擇OK
選YES,就不翻譯了
選擇NO
也是NO
選擇OK
設置主機名
時區的配置
root口令設置
自定義軟體包
檢查依賴關係
格式化文件系統
安裝過程
安裝完畢,重啟.虛擬機完裝好了,安裝過程中可以通過ctrl ]回到宿主機.
五、虛擬機的一些管理命令
- xm dm xen的dmesg信息
- xm create centos 啟動虛擬機centos
- xm console centos 以文本方式連接至虛擬機
- xm reboot centos 重啟虛擬機
- xm shutdown centos 關閉虛擬機
- xm pause centos 暫停虛擬機
- xm resume centos 恢復被暫停的虛擬機
- ………
虛擬機的配置文件位於/etc/xen下以虛擬機的名字為名稱
要想Xen虛擬機隨開機自啟動,要這樣做
- name = "centos"
- uuid = "5ec1488a-42ec-87a7-8001-49243f29497f"
- maxmem = 512
- memory = 512
- vcpus = 1
- bootloader = "/usr/bin/pygrub"
- on_poweroff = "destroy"
- on_reboot = "restart"
- on_crash = "restart"
- disk = [ "tap:aio:/opt/vm/centos.img,xvda,w" ]
- vif = [ "mac=00:16:36:45:e1:b1,bridge=xenbr0,script=vif-bridge" ]
- # ln -s /etc/xen/centos /etc/xen/auto/
- # /etc/init.d/xendomains start
- Starting auto Xen domains: centosUsing <class 'grub.GrubConf.GrubConfigFile'> to parse /grub/menu.lst
- (skip)[done] [ OK ]
本文出自 「BSDerの-專註於開源領域」 博客,請務必保留此出處http://hellosa.blog.51cto.com/2698675/585091
[火星人 ] linux 虛擬化Xen初體驗已經有658次圍觀