您好,登錄后才能下訂單哦!
虛擬化技術的分類:
(1) 模擬:Emulation:
Qemu,PearPC,Bochs
(2) 完全虛擬化:Full Virtualization,Native Virtualization
HVM
VMware Workstation,VirtualBox,VMWare Server,Parallels Desktop,KVM,XEN
(3) 半虛擬化:ParaVirtualization
GuestOS:知曉自己是運行Virtualization
Hypercall
(4) OS級別虛擬化:
將用戶控件分割為多個,彼此間互相隔離;
容器級虛擬化
OpenVZ,LXC(LinuX Container),libcontainer,Virtuozzo,Linux V Servers
(5) 庫級別虛擬化
WINE
Type-I,Type-II
IaaS:Infrastructure,基礎架構服務
PaaS:Platfrom,平臺即服務
Xen:
劍橋大學,開源VMM
Xen組成部分:
(1) Xen Hypervisor
分配CPU、Memory、Interrupt
(2) Dom0
特權域,I/O分配
網絡設備
net-front(GuestOS),net-backend
塊設備
block-front(GuestOS),block-backend
Linux Kernel:
2.6.37:開始支持運行Dom0
3.0:對關鍵特性進行了優化
提供管理DomU工具棧
用于實現對虛擬機進行添加、啟動、快照、停止、刪除等操作;
(3) DomU
非特權域,根據其虛擬化方式實現,有多種類型
PV:半虛擬化
HVM:硬件輔助虛擬化
Xen的PV技術:
不依賴于CPU的HVM特性,但要求GuestOS的內核做出修改以知曉自己運行于PV環境;
運行于DomU中的OS:Linux(2.6.24+),NetBSD,FreeBSD,OpenSolaris
Xen的HVM技術:
依賴于Inter VT或AMD AMD-V,還要依賴于Qemu來模擬IO設備;
運行于DomU中的OS:幾乎所有支持此X86平臺的;
PV on HVM:
CPU為HVM模式運行
IO設備為PV模式運行
運行于DomU中的OS:只要OS能驅動PV接口類型的IO設備;
net-front,blk-front
Xen的工具棧:
xm/xend:在Xen Hypervisor的Dom0中藥啟動xend服務
xm:命令行管理工具,有諸多子命令;
create,destroy,stop,pause...
xl:基于libxenlight提供的輕量級的命令行工具棧;
xe/xapi:提供了對xen管理的api,因此多用于cloud環境,Xen Server,XCP
virsh/libvirt:
XenStore:
為各Domain提供的共享信息存儲空間,有著層級結構的名稱空間,位于Dom0
CentOS對Xen的支持:
RHEL 5.7-:默認的虛擬化技術為xen
kernel version:2.6.18
kernel-
kernel-xen
RHEL 6+:僅支持kvm
Dom0:不支持
DomU:支持
如何在CentOS 6.6上使用Xen:
(1) 編譯3.0以上版本的內核,啟動對Dom0的支持
(2) 編譯xen程序
制作好相關程序的項目:
xen4centos
xen made easy
Para Virt
Xen Para-virtualization Architecture
xen工具:
xm vs xl:
libvirtd管理工具:
xen工具棧:
Dom0 Kernel
CONFIG_ACPI_PROCFS=y
CONFIG_XEN=ye
CONFIG_XEN_MAX_DOMAIN_MEMORY=32
CONFIG_XEN_SAVE_RESTORE=y
CONFIG_XEN_DOM0=y
CONFIG_XEN_PRIVILEGED_GUEST=y
CONFIG_XEN_PCI=y
CONFIG_PCI_XEN=y
CONFIG_XEN_BLKDEV_FRONTENE=y
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_XEN_KBDDEV_FRONTEND=y
CONFIG_HVC_XEN=y
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_BALLOON=y
CONFIG_XEN_SCRUB_PAGES=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XEN_GNTDEV=y
CONFIG_XEN_BACKEND=y
CONFIG_XEN_BLKDEV_BACKEND=y
CONFIG_XEN_NETDEV_BACKEND=y
CONFIG_XEN_FS=y
CONFIG_XEN_COMPAT_XENFS=y
CONFIG_XEN_XENBUS_FRONTEND=y
CONFIG_XEN_PCIDEV_FRONTEND=y
DomU Kernel
CONFIG_XEN=y
CONFIG_PARAVIRT_GUEST=y
CONFIG_PARAVIRT=y
CONFIG_XEN_PVHVM=y
CONFIG_XEN_MAX_DOMAIN_MEMORY=128
CONFIG_XEN_SAVE_RESTORE=y
CONFIG_PCI_XEN=y
CONFIG_XEN_PCIDEV_FRONTEND=y
CONFIG_XEN_BLKDEV_FRONTEND=y
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
CONFIG_HVC_XEN=y
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_DEV_DETCHN=y
CONFIG_XEN_XENBUS_FRONTEND=y
grub配置:
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (3.7.4-1.el6xen.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin(dom0_mem指定dom0使用內存空間多大,cpufreq cpu由xen管理,dom0_max_vcpus dom0最多使用多少虛擬cpu)
module /vmlinuz-3.7.4-1.el6xen.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg0/root rhgb quiet
module /initramfs-3.7.4-1.el6xen.x86_64.img
title Red Hat Enterprise Linux (2.6.32-279.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg0/root rhgb quiet
initrd /initramfs-2.6.32-279.el6.x86_64.img
安裝完成后對grub的配置示例:
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.18.17-13.el6.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.18.17-13.el6.x86_64.img
grub.conf boot options:http://xenbits.xen.org/docs/unstable/misc/xen-command-line.html
官網Man手冊:http://wiki.xenproject.org/wiki/Xen_Man_Pages
工具棧:
xm/xend
xl
xl list:顯示Domain的相關信息
xen虛擬機狀態:
r: running
b:阻塞
p:暫停
s:停止
c:崩潰
d:dying,正在關閉的過程中
如何創建xen pv模式:
1、kernel
2、initrd或initramfs
3、DomU內核模塊
4、根文件系統
5、swap設備
將上述內容定義在DomU的配置文件
注意:xm與xl啟動DomU使用的配置文件略有不同;
對于xl而言,其創建DomU使用的配置指令可通過"man xl.cfg"獲取
常用指令:
name:域唯一的名稱
builder:指明虛擬機的類型,generic表示pv,hvm表示hvm
vcpus:虛擬cpu個數
maxcpus:最大虛擬cpu個數
cpus:vcpu可運行于其上物理CPU列表
memory-MBYTES:內存大小
maxmem-MBYTES:可以使用的最大內存空間
on_poweroff:指明關機時采取的action
destroy,restart,preserve
on_reboot="ACTION":指明"重啟"DomU執行操作
on_crash="ACTION":虛擬機意外崩潰時采取的action
uuid:DomU的唯一標識
disk=["DISK_SPEC_STRING","DISK_SPEC_STRING",...]:指明磁盤設備,列表;
vif=["NET_SPEC_STRING","NET_SPEC_STRING",...]:指明網絡接口,列表;
vfb=["VFB_SPEC_STRING","VFB_SPEC_STRING",...]:指明virtual frame buffer,列表;
pci=["PCI_SPEC_STRING","PCI_SPEC_STRING",...]:pci設備的列表
PV模式專用指令:
kernel="PATHNAME":內核文件路徑,此路徑為Dom0中路徑
ramdisk="PATHNAME":為kernel指定內核提供的ramdisk文件路徑
root="STRING":指明根文件系統
extra="STRING":額外傳遞給內核引導的參數
bootloader="PROGRAM":如果DomU使用自己的kernel及ramdisk,此時需要一個Dom0鐘的應用程序來實現其bootloader功能;
磁盤參數指定方式:
官方文檔:http://xenbits.xen.org/docs/unstable/misc/xl-disk-configuration.txt
[<target>,[<format>,[<vdev>,[<access>]]]]
<target>表示磁盤映像文件或設備文件路徑:/images/xen/linux.img, /dev/myvg/linux
<format>表示磁盤格式,如果映像文件,有多重格式,例如raw,qcow,qcow2
vdev:此設備在DomU被識別為硬件設備類型,支持hd[x],xvd[x],sd[x]
access:訪問權限
ro,r:只讀
rw,w:讀寫
disk=["/images/xen/linux.img,raw,xvda,rw",...]
使用qemu-img管理磁盤映像:
create [-f fmt] [-o options] filename [size]
可創建sparse格式的磁盤映像文件
示例:
創建一個pv格式的vm:
(1) 準備磁盤映像文件
qemu-img create -f raw -o size=2G /images/xen/busybox.img
mke2fs -t ext /images/xen/busybox.img
(2)根文件系統
編譯busybox,并復制到busybox.img映像中
mout -o /images/xen/busybox.img /mnt
cp -a $BUSYBOX/_install/ /mnt
mkdir /mnt/{proc,sys,dev,var}
(3) 提供配置DomU配置文件*
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
(4) 啟動實例:
xl [-v] create <DomU_Config_file> -n
xl create <DomU_Config_file> -c
Ctrl + ]
如何配置網絡接口:
vif = [ '<vifspec>', '<vifspec>',...]
vifspec: [<key>=<value>|<flag>,]
常用的key:
mac=: mac地址,要以00:16:3e開頭
bridge=<bridge>: 指定此網絡接口在Dom0被關聯至那個橋上
model=<MODEL>: rt8139、e1000;
vifname=: 接口名稱,在Domu0中顯示的名稱
script=: 執行的腳本
ip=: 指定ip地址,會注入到DomU中
rate=: 指明設備傳輸速率,通常為"#UNIT/s"格式
UNIT: GB, MB, KB, B for bytes,
Gb, Mb, Kb, b for bits,
注意:內核版本降至3.7.4,Sources/6.x86_64/xen4.1
網絡接口啟用:
vif = [ 'bridge=xenbr0', ]
xl的其他常用命令:
shutdown: 關機
reboot: 重啟
pause: 暫停
unpause: 解除暫停
console: 連接控制臺
save: 將DomuU內存中的數據轉存指定的磁盤文件中;
Usage: xl [-vf] save [options] <Domain> <CheckpointFile> [<ConfigFile>]
restore: 從指定的磁盤文件中恢復DomU內存數據
Usage: xl [-vf] restore [options] [<ConfigFile>] <CheckpointFile>
vcpu-list
vcpu-pin
vcpu-set
info: 當前xen hypervisor的摘要信息
domid
domname
top: 查看domain資源占用排序狀態命令
network-list: 查看指定域使用的網絡及接口
network-attach
network-detach
block-list: 查看指定域使用的塊設備的列表;
block-attach
block-detach
uptime: 運行時長
使用DomU自有kernel來運行啟動運行DomU:
制作磁盤映像文件:
losetup - set up and control loop devices
losetup -a: 顯示所有已用的loop設備相關信息
losetup -f: 顯示第一個空閑的loop設備文件
使用xl命令進行創建虛擬機并完成CentOS 6.6的系統安裝
(1) 創建磁盤映像文件
(2) 獲取安裝指定版本的系統所需要kernel及initrd文件
(3) 創建DomU配置文件,示例如下:
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = "ks=http://172.16.100.10/ks_config/CentOS-6.6-ks.cfg"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
(4) 安裝完成后,創建虛擬機的配置文件需要作出修改;
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
啟動圖形窗口:
在創建虛擬機的配置文件中定義vfb
(1) vfb = [ 'sdl=1' ]
(2) vnc
(a) yum install tigervnc
(b) vfb = [ 'vnc=1' ]
vnc監聽的端口為5900,相應的DISPLAYNUM為0
使用Dom0中物理磁盤分區為DomU提供存儲空間:
使用libvirt實現xen虛擬機管理;
yum install libvirt libvirt-damon-xen virt-manager python-virtinst libvirt-client
service libvirtd start
virt-manager, virsh, virt-install
實驗環境:
操作系統:centos6.6
內核版本:2.6.32-504.el6.x86_64
IP地址:172.16.100.6
CPU:4核心
內存:2G
在VMware Workstation操作需要開啟cpu虛擬化:
[root@xen ~]# hostname
xen.smoke.com
[root@xen ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=xen.smoke.com
[root@xen ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.100.6 xen.com xen.smoke.com
[root@xen ~]# uname -r
2.6.32-504.el6.x86_64
我這里使用http://archive.kernel.org/centos-vault/6.6/xen4/x86_64/Packages/ yum源安裝
[root@xen ~]# vim /etc/yum.repos.d/xen4.repo
[xen4centos]
name=Xen4 for CentOS 6
baseurl=http://archive.kernel.org/centos-vault/6.6/xen4/x86_64/
gpgcheck=0
gpgkey=http://archive.kernel.org/centos-vault/RPM-GPG-KEY-CentOS-6
repo_gpgcheck=0
enabled=1
[root@xen ~]# yum clan all
[root@xen ~]# yum makecache
[root@localhost ~]# yum -y install xen
[root@xen ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.18.17-13.el6.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=cf43ec31-f59f-423f-aa0b-d091c18b2fa4 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img
[root@xen xen]# shutdown -r now
重新啟動操作系統,啟動新內核:
現在運行在虛擬化環境中,看到的內核雖然是3.18.17-13.el6.x86_64,但是看到的是Dom0中的內核;
[root@xen ~]# uname -r
3.18.17-13.el6.x86_64
查看運行的虛擬機,r---- r代表運行狀態;
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 2 r----- 69.1
xm命令以及廢棄,但是仍然是支持的,需要啟動xend服務才可以使用;
[root@xen ~]# xm list
WARNING: xend/xm is deprecated.
Error: Unable to connect to xend: No such file or directory. Is xend running?
[root@xen ~]# service xend start
[root@xen ~]# xm list
WARNING: xend/xm is deprecated.
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 2 r----- 81.6
[root@xen ~]# service xend stop
[root@xen ~]# mkdir -p /images/xen/
選項-o ?可以查看支持的格式;
[root@xen ~]# qemu-img create -f raw -o ? /images/xen/busybox.img
Supported options:
size Virtual disk size
preallocation Preallocation mode (allowed values: off, falloc, full)
[root@xen ~]# qemu-img create -f raw -o size=2G /images/xen/busybox.img
查看為0G,最大可以為2G,稀疏格式的磁盤映像文件;
[root@xen ~]# du -sh /images/xen/busybox.img
0 /images/xen/busybox.img
[root@xen ~]# rm -rf /images/xen/busybox.img
[root@xen ~]# qemu-img create -f raw /images/xen/busybox.img 2G
[root@xen ~]# du -sh /images/xen/busybox.img
0 /images/xen/busybox.img
不分區將整個磁盤當做一個分區使用;[root@xen ~]# mke2fs -t ext2 /images/xen/busybox.img
格式化以后就會部署上元數據,這個磁盤沒有分區表;
[root@xen ~]# du -sh /images/xen/busybox.img
33M /images/xen/busybox.img
本地回環設備掛載使用-o loop選項;[root@xen ~]# mount -o loop /images/xen/busybox.img /mnt
[root@xen ~]# ls /mnt/
lost+found
[root@xen ~]# yum -y groupinstall "Development Tools" "Server Platform Development"
下載busybox,并上傳,官網:https://busybox.net/downloads/ 這里使用busybox-1.22.1
[root@xen ~]# tar xf busybox-1.22.1.tar.bz2
[root@xen ~]# cd busybox-1.22.1
將busybox編譯靜態格式,不讓它依賴于其他庫,靜態格式需要安裝glibc-static;
[root@xen busybox-1.22.1]# yum -y install glibc-static
[root@xen busybox-1.22.1]# make menuconfig
Busybox Settings --->Build Options --->[*] Build BusyBox as a static binary (no shared libs)
不使用共享的額外庫文件;
[root@xen busybox-1.22.1]# make
[root@xen busybox-1.22.1]# make install
[root@xen busybox-1.22.1]# ls _install/
bin linuxrc sbin usr
[root@xen busybox-1.22.1]# cp -a _install/* /mnt/
[root@xen busybox-1.22.1]# ls /mnt/
bin linuxrc lost+found sbin usr
[root@xen busybox-1.22.1]# cd /mnt/
[root@xen mnt]# mkdir proc sys dev etc var boot home
[root@xen ~]# chroot /mnt/ /bin/sh
/ # ls
bin dev home lost+found sbin usr
boot etc linuxrc proc sys var
/ # exit
[root@xen ~]# cd /boot/
[root@xen boot]# ln -s vmlinuz-2.6.32-504.el6.x86_64 vmlinuz
[root@xen boot]# ln -s initramfs-2.6.32-504.el6.x86_64.img initramfs.img
[root@xen boot]# cd /etc/xen/
[root@xen xen]# cp xlexample.pvlinux busybox
[root@xen xen]# vim busybox
name = "busybox-001"
kernel = "/boot/vmlinuz" pv模式可以使用Dom0中的內核
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
#vif = [ '' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
測試虛擬機是否可以跑起來;
[root@xen xen]# xl -v create busybox -n
Parsing config from busybox
{
"domid": null,
"config": {
"c_info": {
"type": "pv",
"hap": "<default>",
"oos": "<default>",
"ssidref": 0,
"name": "busybox-001",
"uuid": "10e85dda-f56e-45ec-9b45-d7593cd53d60",
"xsdata": {
},
"platformdata": {
},
"poolid": 0,
"run_hotplug_scripts": "True",
"pvh": "<default>",
"driver_domain": "<default>"
},
"b_info": {
"max_vcpus": 2,
"avail_vcpus": [
0,
1
],
"cpumap": [
],
"nodemap": [
],
"numa_placement": "<default>",
"tsc_mode": "default",
"max_memkb": 262144,
"target_memkb": 262144,
"video_memkb": -1,
"shadow_memkb": 4096,
"rtc_timeoffset": 0,
"exec_ssidref": 0,
"localtime": "<default>",
"disable_migrate": "<default>",
"cpuid": [
],
"blkdev_start": null,
"device_model_version": "unknown",
"device_model_stubdomain": "<default>",
"device_model": null,
"device_model_ssidref": 0,
"extra": [
],
"extra_pv": [
],
"extra_hvm": [
],
"sched_params": {
"sched": "unknown",
"weight": -1,
"cap": -1,
"period": -1,
"slice": -1,
"latency": -1,
"extratime": -1
},
"ioports": [
],
"irqs": [
],
"iomem": [
],
"claim_mode": "True",
"event_channels": 0,
"u": {
"kernel": "/boot/vmlinuz",
"slack_memkb": -1,
"bootloader": null,
"bootloader_args": [
],
"cmdline": "root=/dev/xvda ro selinux=0 init=/bin/sh",
"ramdisk": "/boot/initramfs.img",
"e820_host": "<default>"
}
},
"disks": [
{
"backend_domid": 0,
"backend_domname": null,
"pdev_path": "/images/xen/busybox.img",
"vdev": "xvda",
"backend": "unknown",
"format": "raw",
"script": null,
"removable": 0,
"readwrite": 1,
"is_cdrom": 0
}
],
"nics": [
],
"pcidevs": [
],
"vfbs": [
],
"vkbs": [
],
"vtpms": [
],
"on_poweroff": "destroy",
"on_reboot": "restart",
"on_watchdog": "destroy",
"on_crash": "destroy"
}
}
[root@xen xen]# xl -v create busybox
[root@xen xen]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 2 r----- 2292.9
busybox-001 4 256 2 -b---- 1.5
[root@xen xen]# xl console busybox-001
/ # ls
bin dev home lost+found sbin usr
boot etc linuxrc proc sys var
/ # [root@xen xen]# (退出ctrl+])
[root@xen xen]# grep -v "^#" busybox | grep -v "^$"
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
關閉虛擬機;
[root@xen xen]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 2 r----- 2302.5
busybox-001 5 256 2 -b---- 2.7
[root@xen xen]# xl destroy busybox-001
DEBUG libxl__device_destroy_tapdisk 105 type=aio:/images/xen/busybox.img disk=:/images/xen/busybox.img
[root@xen xen]# xl create /etc/xen/busybox -c
/ #
/ # [root@xen xen]#
[root@xen xen]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:11:21:56
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2156/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17604 errors:0 dropped:0 overruns:0 frame:0
TX packets:17754 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3443094 (3.2 MiB) TX bytes:1829722 (1.7 MiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:11:21:60
inet addr:192.168.190.128 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2160/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:277920 errors:0 dropped:0 overruns:0 frame:0
TX packets:54903 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:378101310 (360.5 MiB) TX bytes:3362705 (3.2 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@xen xen]# cd /etc/sysconfig/network-scripts/
[root@xen network-scripts]# cp ifcfg-eth0 ifcfg-xenbr0
[root@xen network-scripts]# vim ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:11:21:56
TYPE=Ethernet
UUID=f343369c-4aa9-4975-81b3-3f38f4c56ef0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=xenbr0
[root@xen network-scripts]# vim ifcfg-xenbr0
DEVICE=xenbr0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.100.6
NETMASK=255.255.255.0
[root@xen network-scripts]# chkconfig --list NetworkManager 確認關閉NetworkManager服務
[root@xen network-scripts]# service network restart
默認在centos6.6的bridge-utils工具與3.18的內核可能有沖突導致啟動橋設備以后內核就會終止,內核就會死機;只能升級bridge-utils工具;
使用其他版本內核解決:
[root@xen ~]# yum list all kernel*
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirror.bit.edu.cn
已安裝的軟件包
kernel.x86_64 2.6.32-504.el6 @anaconda-CentOS-201410241409.x86_64/6.6
kernel.x86_64 3.18.17-13.el6 @xen4centos
kernel-devel.x86_64 2.6.32-754.6.3.el6 @updates
kernel-firmware.noarch 3.18.17-13.el6 @xen4centos
kernel-headers.x86_64 2.6.32-754.6.3.el6 @updates
可安裝的軟件包
kernel-abi-whitelists.noarch 2.6.32-754.6.3.el6 updates
kernel-debug.x86_64 2.6.32-754.6.3.el6 updates
kernel-debug-devel.i686 2.6.32-754.6.3.el6 updates
kernel-debug-devel.x86_64 2.6.32-754.6.3.el6 updates
kernel-devel.x86_64 3.18.17-13.el6 xen4centos
kernel-doc.noarch 3.18.17-13.el6 xen4centos
kernel-headers.x86_64 3.18.17-13.el6 xen4centos
kernel一定不要做升級,要做安裝,因為升級以后kernel不能使用將會導致系統無法啟動,即便有n個版本kernel也一定要安裝,而非升級,安裝kernel還會安裝kernel-firmware,它們是相匹配的,否則會導致內核版本無法實用;[root@xen ~]# yum -y install kernel-3.10.68 kernel-firmware-3.10.68
[root@xen xen]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
root (hd0,0)
kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img
[root@xen xen]# shutdown -r now
重啟后,使用新內核還是會死機,用原來內核啟動;
下載bridge-utils-1.5-2.el6.x86_64.rpm、kernel-xen-3.7.4-1.el6xen.x86_64.rpm、kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm、kernel-xen-release-6-4.noarch.rpm包;
[root@xen ~]# ls
anaconda-ks.cfg install.log
bridge-utils-1.5-2.el6.x86_64.rpm install.log.syslog
busybox-1.22.1 kernel-xen-3.7.4-1.el6xen.x86_64.rpm
busybox-1.22.1.tar.bz2 kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm
kernel-xen-release-6-4.noarch.rpm
嘗試升級本地的bridge-utils;
[root@xen ~]# rpm -Uvh bridge-utils-1.5-2.el6.x86_64.rpm
[root@xen ~]# rpm -q bridge-utils
bridge-utils-1.5-2.el6.x86_64
[root@xen ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=1 (更改默認啟動內核為3.18.17-13.el6.x86_64)
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
root (hd0,0)
kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=511ef4c6-c062-4fde-9ccc-984f0674e1b2 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img
[root@xen ~]# shutdown -r now
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7171 (7.0 KiB) TX bytes:9072 (8.8 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1270 (1.2 KiB) TX bytes:1344 (1.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@xen ~]# ifconfig eth0 0
[root@xen ~]# brctl addbr xenbr0
[root@xen ~]# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000000000000 no
[root@xen ~]# brctl addif xenbr0 eth0
[root@xen ~]# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000c2976d258 no eth0
[root@xen ~]# ifconfig xenbr0 172.16.100.6/24 up
升級bridge-utils后創建橋還是死機,降低內核;[root@xen ~]# rpm -ivh kernel-xen-3.7.4-1.el6xen.x86_64.rpm kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm kernel-xen-release-6-4.noarch.rpm --nodeps --force
[root@xen ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.7.4-1.el6xen.x86_64)
root (hd0,0)
kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.7.4-1.el6xen.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.7.4-1.el6xen.x86_64.img
title CentOS (3.10.68-11.el6.centos.alt.x86_64)
root (hd0,0)
kernel /xen.gz dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.10.68-11.el6.centos.alt.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.10.68-11.el6.centos.alt.x86_64.img
title CentOS (3.18.17-13.el6.x86_64)
root (hd0,0)
kernel /xen.gz dom0_mem=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
module /vmlinuz-3.18.17-13.el6.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
module /initramfs-3.18.17-13.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=657e9736-a990-4ad8-88c0-76a2f65da127 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img
[root@xen ~]# shutdown -r now
[root@xen ~]# uname -r
3.7.4-1.el6xen.x86_64
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1895 2 r----- 34.8
[root@xen ~]# ifconfig eth0 0
[root@xen ~]# brctl addbr xenbr0
[root@xen ~]# brctl addif xenbr0 eth0
[root@xen ~]# ifconfig xenbr0 172.16.100.6/24 up
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:600 (600.0 b) TX bytes:1930 (1.8 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:283 errors:0 dropped:0 overruns:0 frame:0
TX packets:172 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:23729 (23.1 KiB) TX bytes:17208 (16.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
[root@xen ~]# cd /etc/sysconfig/network-scripts/
[root@xen network-scripts]# vi ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:76:D2:58
TYPE=Ethernet
UUID=01e1be41-1948-41c6-8f29-9834f8c5586a
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE=xenbr0
[root@xen network-scripts]# vi ifcfg-xenbr0
DEVICE=xenbr0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=172.16.100.6
NETMASK=255.255.255.0
[root@xen network-scripts]# service network restart
[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # exit
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1608 2 r----- 46.7
[root@xen ~]# vim /etc/xen/busybox
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
vif = [ 'bridge=xenbr1' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a (還是沒有網卡,因為沒有網卡驅動)
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # uname -r
2.6.32-504.el6.x86_64
/ # exit
[root@xen ~]# mount -o loop /images/xen/busybox.img /mnt/
虛擬機內核實用的是2.6.32-504.el6.x86_64,因此在 /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/目錄找網卡驅動;
[root@xen ~]# cd /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/
[root@xen net]# mkdir /mnt/lib/modules -pv
查看depends選項有沒有依賴其他模塊,如果有要移過去;
[root@xen net]# modinfo xen-netfront.ko
filename: xen-netfront.ko
alias: xennet
alias: xen:vif
license: GPL
description: Xen virtual network device frontend
srcversion: 5C6FC78BC365D9AF8135201
depends:
vermagic: 2.6.32-504.el6.x86_64 SMP mod_unload modversions
[root@xen net]# cp xen-netfront.ko /mnt/lib/modules/
[root@xen net]# sync
[root@xen ~]# umount /mnt
[root@xen ~]# xl create /etc/xen/busybox -c
/ # ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:16:3E:30:08:CB
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:18
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
在網卡半虛擬化清空下Dom0添加網卡vif3.0,3.0代表Dom ID為3的dom上第0塊網卡的后半段;
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:216 errors:0 dropped:0 overruns:0 frame:0
TX packets:107 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:34587 (33.7 KiB) TX bytes:26570 (25.9 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2461 errors:0 dropped:0 overruns:0 frame:0
TX packets:1281 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:181386 (177.1 KiB) TX bytes:125444 (122.5 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vif3.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b) TX bytes:1434 (1.4 KiB)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:98 errors:0 dropped:0 overruns:0 frame:0
TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11710 (11.4 KiB) TX bytes:19076 (18.6 KiB)
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1608 2 r----- 57.3
busybox-001 3 256 2 -b---- 1.9
把虛擬機關閉,vif3.0接口沒有了,會自動被刪除;
/ # exit
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8736 errors:0 dropped:0 overruns:0 frame:0
TX packets:195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1431302 (1.3 MiB) TX bytes:33472 (32.6 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38504 errors:0 dropped:0 overruns:0 frame:0
TX packets:1717 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2505549 (2.3 MiB) TX bytes:179962 (175.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3253 errors:0 dropped:0 overruns:0 frame:0
TX packets:156 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:321520 (313.9 KiB) TX bytes:23874 (23.3 KiB)
[root@xen ~]# xl create /etc/xen/busybox -c
虛擬機ID號變為4;
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1608 2 r----- 367.6
busybox-001 4 256 2 -b---- 1.2
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8826 errors:0 dropped:0 overruns:0 frame:0
TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1439226 (1.3 MiB) TX bytes:42620 (41.6 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38632 errors:0 dropped:0 overruns:0 frame:0
TX packets:1771 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2514511 (2.3 MiB) TX bytes:185356 (181.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vif4.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3339 errors:0 dropped:0 overruns:0 frame:0
TX packets:219 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:327380 (319.7 KiB) TX bytes:32980 (32.2 KiB)
[root@xen ~]# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000c2976d258 no eth0
vif4.0
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:16:3E:6B:31:0A
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:18
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # ifconfig eth0 172.16.100.21 up
/ # ping 172.16.100.254
PING 172.16.100.254 (172.16.100.254): 56 data bytes
64 bytes from 172.16.100.254: seq=0 ttl=64 time=1.546 ms
64 bytes from 172.16.100.254: seq=1 ttl=64 time=0.652 ms
64 bytes from 172.16.100.254: seq=2 ttl=64 time=0.939 ms
^C64 bytes from 172.16.100.254: seq=3 ttl=64 time=1.663 ms
64 bytes from 172.16.100.254: seq=4 ttl=64 time=1.020 ms
^C64 bytes from 172.16.100.254: seq=5 ttl=64 time=0.867 ms
64 bytes from 172.16.100.254: seq=6 ttl=64 time=1.017 ms
64 bytes from 172.16.100.254: seq=7 ttl=64 time=0.260 ms
[root@xen ~]# xl destroy busybox-001
[root@xen ~]# cp /images/xen/busybox.img /images/xen/busybox2.img
[root@xen ~]# du -sh /images/xen/busybox2.img
4.0M /images/xen/busybox2.img
[root@xen ~]# cp /etc/xen/busybox /etc/xen/busybox2
[root@xen xen]# vim /etc/xen/busybox2
name = "busybox-002"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox2.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen ~]# brctl addbr xenbr1
[root@xen ~]# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000c2976d258 no eth0
xenbr1 8000.000000000000 no
[root@xen ~]# ifconfig xenbr1 up
[root@xen ~]# vim /etc/xen/busybox
vif = [ 'bridge=xenbr1' ]
[root@xen ~]# vim /etc/xen/busybox2
vif = [ 'bridge=xenbr1' ]
[root@xen ~]# xl create /etc/xen/busybox2
Parsing config from /etc/xen/busybox2
[root@xen ~]# xl create /etc/xen/busybox
Parsing config from /etc/xen/busybox
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 403.2
busybox-002 6 256 2 -b---- 1.3
busybox-001 8 256 2 -b---- 1.0
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12159 errors:0 dropped:0 overruns:0 frame:0
TX packets:3134 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1777571 (1.6 MiB) TX bytes:315554 (308.1 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:41158 errors:0 dropped:0 overruns:0 frame:0
TX packets:2489 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2689974 (2.5 MiB) TX bytes:253078 (247.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vif6.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vif7.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3767 errors:0 dropped:0 overruns:0 frame:0
TX packets:431 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:358705 (350.2 KiB) TX bytes:51636 (50.4 KiB)
xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::807b:9dff:fe55:b07f/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
[root@xen ~]# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000c2976d258 no eth0
xenbr1 8000.feffffffffff no vif6.0
vif7.0
[root@xen ~]# xl console busybox-001
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig eth0 172.16.100.21 up
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:3E:49:F2:49
inet addr:172.16.100.21 Bcast:172.16.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:384 (384.0 B) TX bytes:0 (0.0 B)
Interrupt:18
[root@xen ~]# ping 172.16.100.21
PING 172.16.100.21 (172.16.100.21) 56(84) bytes of data.
From 172.16.100.6 icmp_seq=1 Destination Host Unreachable
From 172.16.100.6 icmp_seq=2 Destination Host Unreachable
From 172.16.100.6 icmp_seq=3 Destination Host Unreachable
From 172.16.100.6 icmp_seq=4 Destination Host Unreachable
^C
--- 172.16.100.21 ping statistics ---
7 packets transmitted, 0 received, +4 errors, 100% packet loss, time 6639ms
pipe 4
/ # ifconfig eth0 10.0.11.1 up
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:3E:49:F2:49
inet addr:10.0.11.1 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:384 (384.0 B) TX bytes:0 (0.0 B)
Interrupt:18
[root@xen ~]# xl console busybox-002
/ # insmod /lib/modules/xen-netfront.ko
Initialising Xen virtual ethernet driver.
/ # ifconfig eth0 10.0.11.2 up
/ # ping 10.0.11.1
PING 10.0.11.1 (10.0.11.1): 56 data bytes
64 bytes from 10.0.11.1: seq=0 ttl=64 time=1.841 ms
64 bytes from 10.0.11.1: seq=1 ttl=64 time=1.293 ms
64 bytes from 10.0.11.1: seq=2 ttl=64 time=1.959 ms
64 bytes from 10.0.11.1: seq=3 ttl=64 time=1.389 ms
64 bytes from 10.0.11.1: seq=4 ttl=64 time=1.517 ms
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 408.0
busybox-001 8 256 2 -b---- 1.4
busybox-002 9 256 2 -b---- 1.4
關閉虛擬機,如果虛擬機有shutdown命令,但是這里使用busybox沒有shutdown命令;
[root@xen ~]# xl shutdown busybox-002
Shutting down domain 9
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 410.3
busybox-001 8 256 2 -b---- 1.7
busybox-002 9 256 2 -b---- 2.1
查看pci設備、暫停虛擬機、恢復暫停;
[root@xen ~]# xl pci-list busybox-002
[root@xen ~]# xl pause busybox-002
[root@xen ~]# xl unpause busybox-002
掛起虛擬機,從內存轉存到磁盤文件;
[root@xen ~]# xl save busybox-002 /tmp/busybox-002.img /etc/xen/busybox2
Saving to /tmp/busybox-002.img new xl format (info 0x0/0x0/1416)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536 100%
[root@xen ~]# xl save busybox-001 /tmp/busybox-001.img /etc/xen/busybox
Saving to /tmp/busybox-001.img new xl format (info 0x0/0x0/1415)
xc: Saving memory: iter 0 (last sent 0 skipped 0): 65536/65536 100%
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 418.0
恢復掛起的虛擬機,從磁盤文件恢復到內存;
[root@xen ~]# ls /tmp/ -h
busybox-001.img busybox-002.img yum.log
[root@xen ~]# xl restore /etc/xen/busybox /tmp/busybox-001.img
Loading new save file /tmp/busybox-001.img (new xl fmt info 0x0/0x0/1415)
Savefile contains xl domain config
Parsing config from /etc/xen/busybox
xc: Reloading memory pages: 65536/65536 100%
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 420.4
busybox-001 10 256 2 -b---- 0.0
[root@xen ~]# xl vcpu-list busybox-001
Name ID VCPU CPU State Time(s) CPU Affinity
busybox-001 10 0 3 -b- 0.2 all
busybox-001 10 1 2 -b- 0.2 all
綁定vcpu到物理cpu核心;
root@xen ~]# xl vcpu-pin busybox-001 0 3
[root@xen ~]# xl vcpu-list busybox-001
Name ID VCPU CPU State Time(s) CPU Affinity
busybox-001 10 0 3 -b- 0.3 3
busybox-001 10 1 2 -b- 0.3 all
可以設置使用vcpu的個數,不能隨便加,在啟動虛擬機實例配置文件已經指定最大cpu個數為2個,只能少于最大cpu個數;
[root@xen ~]# xl vcpu-set busybox-001 4
[root@xen ~]# xl vcpu-list busybox-001
Name ID VCPU CPU State Time(s) CPU Affinity
busybox-001 10 0 3 -b- 0.3 3
busybox-001 10 1 2 -b- 0.3 all
[root@xen ~]# xl vcpu-set busybox-001 1
[root@xen ~]# xl vcpu-list busybox-001
Name ID VCPU CPU State Time(s) CPU Affinity
busybox-001 10 0 3 -b- 0.4 3
busybox-001 10 1 - --p 0.3 all
[root@xen ~]# xl vcpu-set busybox-001 2
[root@xen ~]# xl vcpu-list busybox-001
Name ID VCPU CPU State Time(s) CPU Affinity
busybox-001 10 0 3 -b- 0.4 3
busybox-001 10 1 - --p 0.3 all
查看xen hypervisor摘要信息;
[root@xen ~]# xl info busybox-001
host : xen.smoke.com
release : 3.7.4-1.el6xen.x86_64
version : #1 SMP Wed Jan 23 15:52:51 EST 2013
machine : x86_64
nr_cpus : 4
max_cpu_id : 127
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 1
cpu_mhz : 2493
hw_caps : 1f8bfbff:28100800:00000000:00007f00:f7ba2223:00000000:00000001:00000283
virt_caps : hvm
total_memory : 2047
free_memory : 413
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 4
xen_extra : .2-5.el6
xen_version : 4.4.2-5.el6
xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset : Thu Apr 23 15:06:13 2015 +0100 git:a93c3fa-dirty
xen_commandline : dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
cc_compiler : gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
cc_compile_by : mockbuild
cc_compile_domain : centos.org
cc_compile_date : Mon Jul 27 12:16:07 UTC 2015
xend_config_format : 4
[root@xen ~]# xl domid busybox-001
10
[root@xen ~]# xl domname 10
busybox-001
[root@xen ~]# xl dmesg busybox-001
Xen 4.4.2-5.el6
(XEN) Xen version 4.4.2-5.el6 (mockbuild@centos.org) (gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)) debug=n Mon Jul 27 12:16:07 UTC 2015
(XEN) Latest ChangeSet: Thu Apr 23 15:06:13 2015 +0100 git:a93c3fa-dirty
(XEN) Bootloader: GNU GRUB 0.97
(XEN) Command line: dom0_men=1024M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin
(XEN) Video information:
(XEN) VGA is text mode 80x25, font 8x16
(XEN) Disc information:
(XEN) Found 1 MBR signatures
(XEN) Found 1 EDD information structures
(XEN) Xen-e820 RAM map:
(XEN) 0000000000000000 - 000000000009ec00 (usable)
(XEN) 000000000009ec00 - 00000000000a0000 (reserved)
(XEN) 00000000000dc000 - 0000000000100000 (reserved)
(XEN) 0000000000100000 - 000000007fee0000 (usable)
(XEN) 000000007fee0000 - 000000007feff000 (ACPI data)
(XEN) 000000007feff000 - 000000007ff00000 (ACPI NVS)
(XEN) 000000007ff00000 - 0000000080000000 (usable)
(XEN) 00000000f0000000 - 00000000f8000000 (reserved)
(XEN) 00000000fec00000 - 00000000fec10000 (reserved)
(XEN) 00000000fee00000 - 00000000fee01000 (reserved)
(XEN) 00000000fffe0000 - 0000000100000000 (reserved)
(XEN) System RAM: 2047MB (2096632kB)
(XEN) ACPI: RSDP 000F6A10, 0024 (r2 PTLTD )
(XEN) ACPI: XSDT 7FEE965B, 005C (r1 INTEL 440BX 6040000 VMW 1324272)
(XEN) ACPI: FACP 7FEFEE73, 00F4 (r4 INTEL 440BX 6040000 PTL F4240)
(XEN) ACPI: DSDT 7FEEB345, 13B2E (r1 PTLTD Custom 6040000 MSFT 3000001)
(XEN) ACPI: FACS 7FEFFFC0, 0040
(XEN) ACPI: BOOT 7FEEB31D, 0028 (r1 PTLTD $SBFTBL$ 6040000 LTP 1)
(XEN) ACPI: APIC 7FEEA8BD, 0742 (r1 PTLTD APIC 6040000 LTP 0)
(XEN) ACPI: MCFG 7FEEA881, 003C (r1 PTLTD $PCITBL$ 6040000 LTP 1)
(XEN) ACPI: SRAT 7FEE9757, 08A8 (r2 VMWARE MEMPLUG 6040000 VMW 1)
(XEN) ACPI: HPET 7FEE971F, 0038 (r1 VMWARE VMW HPET 6040000 VMW 1)
(XEN) ACPI: WAET 7FEE96F7, 0028 (r1 VMWARE VMW WAET 6040000 VMW 1)
(XEN) Domain heap initialised
(XEN) Processor #0 7:10 APIC version 21
(XEN) Processor #1 7:10 APIC version 21
(XEN) Processor #2 7:10 APIC version 21
(XEN) Processor #3 7:10 APIC version 21
(XEN) IOAPIC[0]: apic_id 128, version 32, address 0xfec00000, GSI 0-23
(XEN) Enabling APIC mode: Phys. Using 1 I/O APICs
(XEN) Not enabling x2APIC: depends on iommu_supports_eim.
(XEN) Using scheduler: SMP Credit Scheduler (credit)
(XEN) Detected 2493.508 MHz processor.
(XEN) Initing memory sharing.
(XEN) xstate_init: using cntxt_size: 0x340 and states: 0x7
(XEN) I/O virtualisation disabled
(XEN) ENABLING IO-APIC IRQs
(XEN) -> Using new ACK method
(XEN) Platform timer is 14.318MHz HPET
(XEN) Allocated console ring of 16 KiB.
(XEN) VMX: Supported advanced features:
(XEN) - APIC TPR shadow
(XEN) - Extended Page Tables (EPT)
(XEN) - Virtual-Processor Identifiers (VPID)
(XEN) - Virtual NMI
(XEN) - MSR direct-access bitmap
(XEN) - Unrestricted Guest
(XEN) HVM: ASIDs enabled.
(XEN) HVM: VMX enabled
(XEN) HVM: Hardware Assisted Paging (HAP) detected
(XEN) HVM: HAP page sizes: 4kB, 2MB
(XEN) Brought up 4 CPUs
(XEN) *** LOADING DOMAIN 0 ***
(XEN) Xen kernel: 64-bit, lsb, compat32
(XEN) Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x1d87000
(XEN) PHYSICAL MEMORY ARRANGEMENT:
(XEN) Dom0 alloc.: 0000000074000000->0000000078000000 (459256 pages to be allocated)
(XEN) Init. ramdisk: 000000007d43d000->000000007f9ff400
(XEN) VIRTUAL MEMORY ARRANGEMENT:
(XEN) Loaded kernel: ffffffff81000000->ffffffff81d87000
(XEN) Init. ramdisk: ffffffff81d87000->ffffffff84349400
(XEN) Phys-Mach map: ffffffff8434a000->ffffffff846fddd8
(XEN) Start info: ffffffff846fe000->ffffffff846fe4b4
(XEN) Page tables: ffffffff846ff000->ffffffff84726000
(XEN) Boot stack: ffffffff84726000->ffffffff84727000
(XEN) TOTAL: ffffffff80000000->ffffffff84800000
(XEN) ENTRY ADDRESS: ffffffff81745210
(XEN) Dom0 has maximum 2 VCPUs
(XEN) Scrubbing Free RAM: .done.
(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) Std. Loglevel: Errors and warnings
(XEN) Guest Loglevel: Nothing (Rate-limited: Errors and warnings)
(XEN) Xen is relinquishing VGA console.
(XEN) *** Serial input -> DOM0 (type 'CTRL-a' three times to switch input to Xen)
(XEN) Freed 284kB init memory.
[root@xen ~]# xl top
顯示網絡接口、網絡接口熱插拔;
[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr. handle state evt-ch tx-/rx-ring-ref BE-path
0 0 00:16:3e:4e:c6:cb 0 4 14 769/768 /local/domain/0/backend/vif/10/0
[root@xen ~]# xl network-attach busybox-001 bridge=xenbr0
[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr. handle state evt-ch tx-/rx-ring-ref BE-path
0 0 00:16:3e:4e:c6:cb 0 4 14 769/768 /local/domain/0/backend/vif/10/0
1 0 00:16:3e:23:d4:a1 1 4 8 1280/1281 /local/domain/0/backend/vif/10/1
[root@xen ~]# xl console busybox-001
/ # ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:16:3E:4E:C6:CB
inet addr:10.0.11.1 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:769 errors:0 dropped:0 overruns:0 frame:0
TX packets:758 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:62228 (60.7 KiB) TX bytes:72100 (70.4 KiB)
Interrupt:18
eth2 Link encap:Ethernet HWaddr 00:16:3E:23:D4:A1
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:26
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
[root@xen ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15541 errors:0 dropped:0 overruns:0 frame:0
TX packets:5753 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2063044 (1.9 MiB) TX bytes:620056 (605.5 KiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:76:D2:62
inet addr:192.168.190.130 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d262/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:42664 errors:0 dropped:0 overruns:0 frame:0
TX packets:2634 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2789515 (2.6 MiB) TX bytes:266230 (259.9 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:784 (784.0 b) TX bytes:784 (784.0 b)
vif10.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:28 (28.0 b) TX bytes:468 (468.0 b)
vif10.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:0 (0.0 b) TX bytes:618 (618.0 b)
xenbr0 Link encap:Ethernet HWaddr 00:0C:29:76:D2:58
inet addr:172.16.100.6 Bcast:172.16.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe76:d258/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6942 errors:0 dropped:0 overruns:0 frame:0
TX packets:3046 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:559406 (546.2 KiB) TX bytes:337324 (329.4 KiB)
xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::807b:9dff:fe55:b07f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:56 (56.0 b) TX bytes:468 (468.0 b)
[root@xen ~]# xl network-list busybox-001
Idx BE Mac Addr. handle state evt-ch tx-/rx-ring-ref BE-path
0 0 00:16:3e:4e:c6:cb 0 4 14 769/768 /local/domain/0/backend/vif/10/0
1 0 00:16:3e:23:d4:a1 1 4 8 1280/1281 /local/domain/0/backend/vif/10/1
[root@xen ~]# xl network-detach busybox-001 1
/ # net eth2: xennet_release_rx_bufs: fix me for copying receiver.
/ # ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:16:3E:4E:C6:CB
inet addr:10.0.11.1 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:769 errors:0 dropped:0 overruns:0 frame:0
TX packets:758 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:62228 (60.7 KiB) TX bytes:72100 (70.4 KiB)
Interrupt:18
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
[root@xen ~]# qemu-img create -f qcow2 -o ? /images/xen/busybox1.2.img
Supported options:
size Virtual disk size
backing_file File name of a base image
backing_fmt Image format of the base image
encryption Encrypt the image
cluster_size qcow2 cluster size
preallocation Preallocation mode (allowed values: off, metadata, falloc, full)
[root@xen ~]# qemu-img create -f qcow2 -o size=5G,preallocation=metadata /images/xen/busybox1.2.img
Formatting '/images/xen/busybox1.2.img', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='metadata'
[root@xen ~]# ll -h /images/xen/
總用量 40M
-rw-r--r--. 1 root root 5.1G 11月 25 06:37 busybox1.2.img
-rw-r--r--. 1 root root 2.0G 11月 25 05:34 busybox2.img
-rw-r--r--. 1 root root 2.0G 11月 24 07:00 busybox.img
[root@xen ~]# du -sh /images/xen/
40M /images/xen/
[root@xen ~]# du -sh /images/xen/busybox1.2.img
972K /images/xen/busybox1.2.img
[root@xen ~]# xl block-list busybox-001
Vdev BE handle state evt-ch ring-ref BE-path
51712 0 10 4 13 8 /local/domain/0/backend/qdisk/10/51712
[root@xen ~]# xl block-attach busybox-001 '/images/xen/busybox1.2.img,qcow2,xvdb,w'
[root@xen ~]# xl block-list busybox-001
Vdev BE handle state evt-ch ring-ref BE-path
51712 0 10 4 13 8 /local/domain/0/backend/qdisk/10/51712
51728 0 10 4 8 1281 /local/domain/0/backend/qdisk/10/51728
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvdb doesn't contain a valid partition table
/ # fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI, OSF or GPT disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that the previous content
won't be recoverable.
Command (m for help): p
Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-652, default 8): Using default value 8
Last cylinder or +size or +sizeM or +sizeK (8-652, default 652): +1G
Command (m for help): p
Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvdb1 1 7 56196 83 Linux
/dev/xvdb2 8 130 987997+ 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
xvdb: xvdb1 xvdb2
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
Disk /dev/xvdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvdb1 1 7 56196 83 Linux
/dev/xvdb2 8 130 987997+ 83 Linux
[root@xen ~]# xl block-detach busybox-001 51728
[root@xen ~]# xl block-list busybox-001
Vdev BE handle state evt-ch ring-ref BE-path
51712 0 10 4 13 8 /local/domain/0/backend/qdisk/10/51712
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
[root@xen ~]# xl uptime busybox-001
Name ID Uptime
busybox-001 10 0:38:46
[root@xen ~]# xl destroy busybox-001
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 436.8
[root@xen ~]# qemu-img create -f qcow2 -o size=5G,preallocation=metadata /images/xen/busybox3.img
Formatting '/images/xen/busybox3.img', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 preallocation='metadata'
顯示已用的回環設備、顯示空閑loop設備、關聯loop設備;
[root@xen yum.repos.d]# losetup -a
[root@xen yum.repos.d]# mount -o loop /images/xen/busybox.img /mnt
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131076 (/images/xen/busybox.img)
[root@xen yum.repos.d]# umount /mnt
[root@xen yum.repos.d]# losetup -f
/dev/loop0
[root@xen yum.repos.d]# losetup /dev/loop0 /images/xen/busybox3.img
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen yum.repos.d]# fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xad46703f.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/loop0: 5369 MB, 5369757696 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xad46703f
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-652, default 8):
Using default value 8
Last cylinder, +cylinders or +size{K,M,G} (8-652, default 652): +1G
Command (m for help): p
Disk /dev/loop0: 5369 MB, 5369757696 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xad46703f
Device Boot Start End Blocks Id System
/dev/loop0p1 1 7 56196 83 Linux
/dev/loop0p2 8 139 1060290 83 Linux
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 22: 無效的參數.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
顯示loop設備分區信息;
[root@xen yum.repos.d]# kpartx -av /dev/loop0
add map loop0p1 (253:0): 0 112392 linear /dev/loop0 63
add map loop0p2 (253:1): 0 2120580 linear /dev/loop0 112455
[root@xen yum.repos.d]# ls /dev/mapper/
control loop0p1 loop0p2
[root@xen yum.repos.d]# mke2fs -t ext2 /dev/mapper/loop0p1
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系統標簽=
操作系統:Linux
塊大小=1024 (log=0)
分塊大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
14056 inodes, 56196 blocks
2809 blocks (5.00%) reserved for the super user
第一個數據塊=1
Maximum filesystem blocks=57671680
7 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961
正在寫入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@xen yum.repos.d]# mke2fs -t ext2 /dev/mapper/loop0p2
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系統標簽=
操作系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265072 blocks
13253 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在寫入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@xen yum.repos.d]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen yum.repos.d]# mkdir /mnt/{boot,sysroot}
[root@xen yum.repos.d]# mount /dev/mapper/loop0p1 /mnt/boot/
[root@xen yum.repos.d]# mount /dev/mapper/loop0p2 /mnt/sysroot/
[root@xen yum.repos.d]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/loop0p1 on /mnt/boot type ext2 (rw)
/dev/mapper/loop0p2 on /mnt/sysroot type ext2 (rw)
[root@xen yum.repos.d]# cp /boot/vmlinuz-2.6.32-504.el6.x86_64 /mnt/boot/vmlinuz
[root@xen yum.repos.d]# cp /boot/initramfs-2.6.32-504.el6.x86_64.img /mnt/boot/initramfs.img
[root@xen yum.repos.d]# grub-install --root-directory=/mnt /dev/loop0
Probing devices to guess BIOS drives. This may take a long time.
/dev/loop0 does not have any corresponding BIOS drive.
[root@xen yum.repos.d]# ls /mnt/boot/
grub initramfs.img lost+found vmlinuz
[root@xen yum.repos.d]# ls /mnt/boot/grub/
device.map fat_stage1_5 iso9660_stage1_5 minix_stage1_5 stage1 ufs2_stage1_5 xfs_stage1_5
e2fs_stage1_5 ffs_stage1_5 jfs_stage1_5 reiserfs_stage1_5 stage2 vstafs_stage1_5
[root@xen yum.repos.d]# vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title BusyBox(kernel-2.6.32)
root (hd0,0)
kernel /vmlinuz root=/dev/xvda1 ro selinux=0 init=/bin/sh
initrd /initramfs.img
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/sysroot/
[root@xen ~]# cd /mnt/sysroot/
[root@xen sysroot]# ls
bin linuxrc lost+found sbin usr
[root@xen sysroot]# mkdir lib/modules dev proc sys etc var tmp -p
[root@xen sysroot]# cp /lib/modules/2.6.32-504.el6.x86_64/kernel/drivers/net/xen-netfront.ko lib/modules/
[root@xen sysroot]# sync
拆除loop設備;
[root@xen sysroot]# cd
[root@xen ~]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen ~]# umount /mnt/boot/
[root@xen ~]# umount /mnt/sysroot/
[root@xen ~]# losetup -d /dev/loop0
[root@xen ~]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen ~]# kpartx -d /dev/loop0
[root@xen ~]# ls /dev/mapper/
control
[root@xen ~]# losetup -f
/dev/loop0
[root@xen ~]# cd /etc/xen/
[root@xen xen]# cp busybox busybox3
[root@xen ~]# which pygrub
/usr/bin/pygrub
[root@xen xen]# vim busybox3
name = "busybox-003"
#kernel = "/boot/vmlinuz"
#ramdisk = "/boot/initramfs.img"
#extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox3.img,qcow2,xvda,rw' ]
#root = "/dev/xvda ro"
bootloader = '/usr/bin/pygrub'
[root@xen xen]# xl create busybox3 -c
Parsing config from busybox3
libxl: error: libxl_device.c:1225:libxl__wait_for_backend: Backend /local/domain/0/backend/qdisk/0/51712 not ready
libxl: error: libxl_bootloader.c:405:bootloader_disk_attached_cb: failed to attach local disk for bootloader execution
libxl: error: libxl_bootloader.c:276:bootloader_local_detached_cb: unable to detach locally attached disk
libxl: error: libxl_create.c:1022:domcreate_rebuild_done: cannot (re-)build domain: -3
虛擬機啟動不了的原因是使用losetup方式對qcow2格式的映像文件進行分區、格式化、掛載、虛擬機xen的xl是識別不了這個分區。
[root@xen xen]# cd /images/xen/
[root@xen xen]# ls
busybox1.2.img busybox2.img busybox3.img busybox.img
[root@xen xen]# rm busybox3.img
rm:是否刪除普通文件 "busybox3.img"?y
[root@xen xen]# qemu-img create -f raw -o size=2G /images/xen/busybox3.img
Formatting '/images/xen/busybox3.img', fmt=raw size=2147483648
[root@xen xen]# losetup -f
/dev/loop0
[root@xen xen]# losetup /dev/loop0 /images/xen/busybox3.img
[root@xen xen]# losetup -a
/dev/loop0: [0802]:131079 (/images/xen/busybox3.img)
[root@xen xen]# fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x07f78d24.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/loop0: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x07f78d24
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8-261, default 8):
Using default value 8
Last cylinder, +cylinders or +size{K,M,G} (8-261, default 261): +1G
Command (m for help): p
Disk /dev/loop0: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x07f78d24
Device Boot Start End Blocks Id System
/dev/loop0p1 1 7 56196 83 Linux
/dev/loop0p2 8 139 1060290 83 Linux
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 22: 無效的參數.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
[root@xen xen]# kpartx -av /dev/loop0
add map loop0p1 (253:0): 0 112392 linear /dev/loop0 63
add map loop0p2 (253:1): 0 2120580 linear /dev/loop0 112455
[root@xen xen]# ls /dev/mapper/
control loop0p1 loop0p2
[root@xen xen]# mke2fs -t ext2 /dev/mapper/loop0p1
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系統標簽=
操作系統:Linux
塊大小=1024 (log=0)
分塊大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
14056 inodes, 56196 blocks
2809 blocks (5.00%) reserved for the super user
第一個數據塊=1
Maximum filesystem blocks=57671680
7 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961
正在寫入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@xen xen]# mke2fs -t ext2 /dev/mapper/loop0p2
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: 完成
文件系統標簽=
操作系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265072 blocks
13253 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在寫入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@xen xen]# mount /dev/mapper/loop0p1 /mnt/boot/
[root@xen xen]# mount /dev/mapper/loop0p2 /mnt/sysroot/
[root@xen xen]# cp /boot/vmlinuz-2.6.32-504.el6.x86_64 /mnt/boot/vmlinuz
[root@xen xen]# cp /boot/initramfs-2.6.32-504.el6.x86_64.img /mnt/boot/initramfs.img
[root@xen xen]# cd
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/sysroot/
[root@xen ~]# mkdir /mnt/sysroot/lib/modules -p
[root@xen ~]# modinfo xen-netfront
filename: /lib/modules/3.7.4-1.el6xen.x86_64/kernel/drivers/net/xen-netfront.ko
alias: xennet
alias: xen:vif
license: GPL
description: Xen virtual network device frontend
srcversion: 746EC04CBED591C2D0F65D1
depends:
intree: Y
vermagic: 3.7.4-1.el6xen.x86_64 SMP mod_unload modversions
[root@xen ~]# cp /lib/modules/3.7.4-1.el6xen.x86_64/kernel/drivers/net/xen-netfront.ko /mnt/sysroot/lib/modules/
[root@xen ~]# cd /mnt/sysroot/
[root@xen sysroot]# mkdir -p dev proc sys tmp var home boot
[root@xen sysroot]# sync
[root@xen sysroot]# xl create /etc/xen/busybox -c
/ #
[root@xen ~]# xl block-attach busybox-001 '/images/xen/busybox3.img,raw,xvdb,w'
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvdb1 1 7 56196 83 Linux
/dev/xvdb2 8 139 1060290 83 Linux
/ # mount /dev/xvdb1 /etc/
EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
/ # ls /etc/
initramfs.img lost+found vmlinuz
/ # umount /etc
[root@xen ~]# xl block-list busybox-001
Vdev BE handle state evt-ch ring-ref BE-path
51712 0 14 4 13 8 /local/domain/0/backend/qdisk/14/51712
51728 0 14 4 14 28 /local/domain/0/backend/qdisk/14/51728
[root@xen ~]# xl block-detach busybox-001 51728
[root@xen ~]# xl block-list busybox-001
Vdev BE handle state evt-ch ring-ref BE-path
51712 0 14 4 13 8 /local/domain/0/backend/qdisk/14/51712
[root@xen ~]# grub-install --root-directory=/mnt /dev/loop0
Probing devices to guess BIOS drives. This may take a long time.
/dev/loop0 does not have any corresponding BIOS drive.
[root@xen ~]# ls /mnt/boot/
grub initramfs.img lost+found vmlinuz
[root@xen ~]# vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title BusyBox(kernel-2.6.32)
root (hd0,0)
kernel /vmlinuz root=/dev/xvda1 ro selinux=0 init=/bin/sh
initrd /initramfs.img
[root@xen ~]# sync
[root@xen ~]# vim /etc/xen/busybox3
[root@xen ~]# which pygrub
/usr/bin/pygrub
[root@xen xen]# vim busybox3
name = "busybox-003"
#kernel = "/boot/vmlinuz"
#ramdisk = "/boot/initramfs.img"
#extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/busybox3.img,raw,xvda,rw' ]
#root = "/dev/xvda ro"
bootloader = '/usr/bin/pygrub'
[root@xen ~]# xl create /etc/xen/busybox3 -c
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1352 2 r----- 1634.9
busybox-001 14 256 2 -b---- 66.0
[root@xen ~]# xl destroy busybox-001
下載Centos6.6的vmlinuz和initrd.img文件,可以將Centos6.6操作系統iso文件解壓后再isolinux目錄中找到
[root@xen ~]# ls
anaconda-ks.cfg busybox-1.22.1.tar.bz2 install.log.syslog vmlinuz
bridge-utils-1.5-2.el6.x86_64.rpm initrd.img kernel-xen-3.7.4-1.el6xen.x86_64.rpm
busybox-1.22.1 install.log kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm
[root@xen ~]# mkdir /images/kernel
[root@xen ~]# mv vmlinuz initrd.img /images/kernel/
[root@xen ~]# cp /etc/xen/busybox /etc/xen/centos
[root@xen ~]# qemu-img create -f qcow2 -o size=120G,preallocation=metadata /images/xen/centos6.6.img
Formatting '/images/xen/centos6.6.img', fmt=qcow2 size=128849018880 encryption=off cluster_size=65536 preallocation='metadata'
[root@xen ~]# vim /etc/xen/centos
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = ""
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen ~]# xl create /etc/xen/centos
Parsing config from /etc/xen/centos
[root@xen ~]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1350 2 r----- 1656.1
centos-001 18 512 2 -b---- 8.8
[root@xen ~]# xl console centos-001
配置虛擬機ip地址;
使用URL安裝,我這里將cenots6.6的ios文件進行解壓,搭建http服務器;
設置web服務器url;
安裝完成;
初始化,進行下面的初始化就可以了,我這里就不安裝了;
[root@xen xen]# xl destroy centos-001
使用Kickstart自動化安裝虛擬機操作系統,Kickstart部署詳細見:https://blog.51cto.com/smoke520/2325660
[root@xen ~]# vim /etc/xen/centos
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = "ks=http://172.16.100.10/ks_config/CentOS-6.6-ks.cfg"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen ~]# xl create centos -c
e:09:ab:21 (CentOS6) via eth0
Aug 1 17:36:34 linux-node1 dhcpd: DHCPREQUEST for 172.16.100.33 (172.16.100.10) from 00:16:3e:09:ab:21 (CentOS6) via eth0
Aug 1 17:36:34 linux-node1 dhcpd: DHCPACK on 172.16.100.33 to 00:16:3e:09:ab:21 (CentOS6) via eth0
[root@xen xen]# vim centos
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
[root@xen xen]# xl destroy centos-001
[root@xen xen]# xl create centos -c
ctrl+]退回到宿主機;
[root@CentOS6 ~]# [root@xen xen]#
[root@xen xen]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 838 2 r----- 6347.0
centos-001 68 512 2 -b---- 8.2
[root@xen xen]# xl shutdown centos-001
Shutting down domain 68
[root@xen xen]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 838 2 r----- 6348.5
cloud-init專門為云實現初始化磁盤映像文件;
[root@xen xen]# yum info cloud-init
Name : cloud-init
Arch : x86_64
Version : 0.7.5
Release : 10.el6.centos.2
Size : 432 k
Repo : extras
Summary : Cloud instance init scripts
URL : http://launchpad.net/cloud-init
License : GPLv3
Description : Cloud-init is a set of init scripts for cloud instances. Cloud instances
: need special scripts to run during initialization to retrieve and install
: ssh keys and to let the user run various scripts.
[root@xen xen]# vim busybox
name = "busybox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr1' ]
disk = [ '/images/xen/busybox.img,raw,xvda,rw' ]
root = "/dev/xvda ro"
vfb = [ 'sdl=1' ]
[root@xen xen]# xl create busybox
[root@xen xen]# xl destroy busybox-001
[root@xen xen]# vim centos
[root@xen xen]# grep -v "#" centos | grep -v "^$"
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'sdl=1' ]
[root@xen xen]# xl create centos
[root@xen xen]# xl destroy centos-001
使用vnc,安裝vnc客戶端;
[root@xen xen]# yum -y install tigervnc
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'vnc=1' ]
[root@xen xen]# xl create centos
[root@xen xen]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 127.0.0.1:5900 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 127.0.0.1:6011 *:*
LISTEN 0 128 ::1:6011 :::*
LISTEN 0 128 127.0.0.1:6012 *:*
LISTEN 0 128 ::1:6012 :::*
[root@xen xen]# vncviewer :5900
[root@xen xen]# vim centos
name = "centos-001"
bootloader = "/usr/bin/pygrub"
memory = 512
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/images/xen/centos6.6.img,qcow2,xvda,rw' ]
vfb = [ 'vnc=1,vnclisten=0.0.0.0,vncpasswd=smoke520' ]
[root@xen xen]# xl create centos
[root@xen xen]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 *:5900 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 127.0.0.1:6011 *:*
LISTEN 0 128 ::1:6011 :::*
LISTEN 0 128 127.0.0.1:6012 *:*
LISTEN 0 128 ::1:6012 :::*
在Windows操作系統使用VNC Viewer連接虛擬機;
輸入vnc密碼smoke520;
正常登陸;
[root@xen xen]# xl destroy centos-001
使用宿主機分區作別DomU的磁盤;
[root@xen ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +30G
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@xen ~]# kpartx -a /dev/sdb
[root@xen ~]# pvcreate /dev/sdb1
[root@xen ~]# vgcreate myvg /dev/sdb1
[root@xen ~]# lvcreate -L 2G -n bbox myvg
[root@xen ~]# mke2fs -t ext2 /dev/myvg/bbox
[root@xen ~]# mount /dev/myvg/bbox /mnt/
[root@xen ~]# cp -a busybox-1.22.1/_install/* /mnt/
[root@xen ~]# cd /mnt/
[root@xen mnt]# mkdir proc dev sys tmp etc var boot
[root@xen mnt]# ll
總用量 100
drwxr-xr-x. 2 root root 4096 11月 24 05:51 bin
drwxr-xr-x. 2 root root 4096 12月 4 22:17 boot
drwxr-xr-x. 2 root root 4096 12月 4 22:17 dev
drwxr-xr-x. 2 root root 4096 12月 4 22:17 etc
lrwxrwxrwx. 1 root root 11 11月 24 05:51 linuxrc -> bin/busybox
drwx------. 2 root root 16384 12月 4 22:11 lost+found
drwxr-xr-x. 2 root root 4096 12月 4 22:17 proc
drwxr-xr-x. 2 root root 4096 11月 24 05:51 sbin
drwxr-xr-x. 2 root root 4096 12月 4 22:17 sys
drwxr-xr-x. 2 root root 4096 12月 4 22:17 tmp
drwxr-xr-x. 4 root root 4096 11月 24 05:51 usr
drwxr-xr-x. 2 root root 4096 12月 4 22:17 var
[root@xen mnt]# cd /etc/xen/
[root@xen xen]# cp busybox bbox
[root@xen xen]# vim bbox
name = "bbox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
memory = 256
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [ '/dev/myvg/bbox,raw,xvda,rw' ]
root = "/dev/xvda ro"
[root@xen xen]# xl create bbox -n
[root@xen xen]# xl create bbox -c
/ # ls
bin dev linuxrc proc sys usr
boot etc lost+found sbin tmp var
/ # fdisk -l
Disk /dev/xvda: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvda doesn't contain a valid partition table
/ # exit
使用libvirt實現xen虛擬機管理;
[root@xen xen]# yum -y install libvirt libvirt-daemon-xen
[root@xen xen]# service libvirtd start
[root@xen xen]# yum -y install virt-manager
[root@xen xen]# virt-manager
如果創建虛擬機時候出現Error:list.remove(x):x not in list;
[root@xen yum.repos.d]# ps -ef | grep python
root 4529 1 1 22:48 ? 00:00:23 /usr/bin/python /usr/share/virt-manager/virt-manager.py
root 6050 3049 0 23:12 pts/0 00:00:00 grep python
[root@xen yum.repos.d]# kill -9 4529
[root@xen yum.repos.d]# /usr/bin/python /usr/share/virt-manager/virt-manager.py
選擇使用pxe方式安裝(需要有Kickstart服務器);
選擇操作系統類型;
分配cpu、內存大小;
分配磁盤大小,不要立即指定磁盤空間(磁盤映像文件默認存放在/var/lib/libvirt/images/目錄);
使用PXE安裝Virt Type只支持全虛擬機類型;
如果沒有問題點擊Begin Installation開始安裝操作系統;
[root@xen yum.repos.d]# virsh list
Id Name State
----------------------------------------------------
4 centos running
[root@xen yum.repos.d]# virsh destroy centos
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。