Wednesday, May 5, 2010
Xen常用的基本命令(ZZ)
Xen常用的基本命令
RHEL5自带Xen,如果用上面的图形化操作也还是不错的。不过还是命令行比较方便——如果会的话。做下记录:
Xen的日志在/var/log/xen
一般是准备好一个虚拟硬盘在Domain-0上面,为安装System1做准备:dd if=/dev/zero of=/opt/Xen/system1.img bs=1024k count=10000 生成一个10g大小的硬盘(注:这一步可以省略,等virt-install来自己产生)。
开始安装:virt-install -n system1 -r 1024 --file=/opt/Xen/system1.img --nographic -l nfs:127.0.0.1:/media/cdrom
参数很好记忆。实在记不住,直接输入virt-install就可以,他会有文字提示一步步完成。或者也可以直接 virt-install -h看提示,里面有包括nfs,ftp,http的格式都有,所以其实不怎么费脑子。关键是要告诉xen,你装的虚拟机的名字,给他分多少内存,硬盘在哪,安装文件在哪,就够了。安装过程和正常装没什么区别。不过好像不能再选择在虚拟机里面装Xen了……
安装完成以后,在/etc/xen目录下,会产生类似 system1这样的目录,里面就是这个虚拟机的配置文件。通过观察配置文件,比如我这里的system1这个文件,就会发现其实里面记录的就是一些虚拟机的信息,比如硬盘在哪,网卡用什么mac地址,cpu,机器名等。
常用的命令:
xm list 查看当前机器里的全部虚拟机列表
xm create xxxx 启动名字为xxx的虚拟机
xm shutdown xxxxm
reboot xxxxm
pause xxxxm
resuem xxx
需要管理登入的时候:xm console xxxx就可以像在本机一样操作虚拟机了,如果要退出到Domain-0,按住Ctrl+] 就行
硬盘不够可以添加,添加了以后不用重启,直接生效,和插u盘一个效果xm block-list xxxx 查看xxx虚拟机的可用硬盘设备xm block-attach xxx tap:aio:/xxxx.img xvdb w这里可以参照一下之前的/etc/xen下的配置文件,对于之前用dd生成的文件挂载,貌似就是用tap:aio:这样的形式,如果是vmware的 vmdk文件就写上vmdk(我只尝试了dd产生的文件的形式),xen支持好些个虚拟机的硬盘格式转化。剩下的在虚拟机里面就可以看到新硬盘,然后就和实体机一样操作就好了。
注意:
xm list 在XEN3.1 CENTOS HOST上没法显示所有的VM. 还是要自己到/etc/xen下面去看已经有的配置文件。
Wednesday, December 9, 2009
A problem when insalling Xen kernel devel package on CentOS5
yum install kernel-xen-devel
However, after that, I still cannot compile the module. It turns out that the version of kernel-xen-devel is the newest (2.6.18-164.6.1) one while my kernel is the old one (2.6.18-128). It seems that the yum just insalled the newest package regardless of my current kernel.
Solution: install the new xen kernel (or update, but it takes a lot of space)
yum update kernel-xen
Thursday, November 5, 2009
Using qemu to find out physical address of a given virtual address for Xen
Environment: Xen 3.3 32bit PAE is installed as a QEMU virtual machine.
Input: 0xc0100000 (the virtual address of domain 0 kernel)
Output: the physical address of 0xc0100000.
Process:
1. Use "info registers" cmd in qemu monitor to get cr3. cr3 is 0x29cd00. This is the physical base addr of page directory pointer table (PDPT).
2. Get the top two bits of virtual address; it is the index for page directory pointer entry.
For 0xc0100000, the highest btye is 0xc, which is 1100(b). So the index is 11(b) = 3 .
3. The length of one entry of PDPT is 64bits (intel cpu manual 3a,3.8.5) = 8 byte. 3*8=24(d) = 0x18.
4. cr3+0x18 contains the entry for page directory table.
cr3+0x18 = 0x0029cd00+0x18 = 0x0029cd18.
xp /20hx 0x0029cd18 = 0x390b 6001. This is the base addr for page dir table.
5. Bits 21 to 29 of virtual address is the index for page dir table.
For 0xc010000, the top 4 bytes are 1100,0000,0001,0000 (b). Bits 21 to 29 are:00,0000,000(b). That is 0. So the index for page dir table is 0.
6. xp /20hx 0x390b,6000 (the lower byte(s) contains some flags, just ignore them for now.)
The output is 0x3dbc,a067.
7. Bits 20 to 12 of virtual address is the index for page table. (For 2MB pages, it is different)
That is 1,0000, 0000(b), which is 0x100. Since each entry is 8 byte (64bits). The position for page tabe is 0x100*8= 0x800.
8. The lower bits of 0x3dbc, a067 are some flags. Just ignore 067 for now. The physical address for page table is
0x3dbc,a000 + 0x800 = 0x3dbc,a800.
xp /20hx 0x3dbc, a800. The output is 0x3d10,0063. Again, the lower bits are flags. So we get final result: 0x3d10,0000. (I skipped the computation for offset with a page.)
Note: To verify that they are actually point the same data, use "x" and "xp" cmd in qemu monitor to show their content. E.g. x /20hx 0xc0100000 , and xp /20hx 0x3d100000. The output should be the same.
Reference:
Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3A
Friday, July 10, 2009
VM in VM: QEMU, Xen, VMware ESXi and HyperV
----------------------------------Xen------------ Hyper-V--------- VMware ESX i
Underlying virtualization:
QEMU 0.10.5 -----------------\/--------------- X-------------------------- X
Virtual Box 3 ------------------?-----------------X-------------------------- X
VMware WS 6.5 --------------\/----------------?---------------------------- \/
It means Xen can run in a QEMU VM, but hyper-v and ESXi cannot run on current QEMU.
Monday, March 30, 2009
build lxr for Xen
http://tread.wordpress.com/2007/08/25/howto-setup-lxr-on-linux-ubuntu-feisty/
2. Modify /usr/share/lxr/http/lxr.conf
#sourceroot: /usr/share/lxr/source/$v/linux/
#srcrootname: Linux
sourceroot: /usr/share/lxr/source/$v/xen/
srcrootname: Xen
Sunday, March 22, 2009
xentrace, xenmon
XenMon:
http://www.hpl.hp.com/techreports/2005/HPL-2005-187.html
http://lists.xensource.com/archives/html/xen-tools/2006-06/msg00006.html
Xentrace:
http://lists.xensource.com/archives/cgi-bin/extract-mesg.cgi?a=xen-users&m=2007-07&i=000001c7d05a%24817c75c0%2484756140%24%40buaa.edu.cn
http://lists.xensource.com/archives/html/xen-tools/2007-03/msg00004.html
http://lists.xensource.com/archives/html/xen-tools/2006-06/msg00007.html
http://lists.xensource.com/archives/html/xen-users/2007-07/msg00783.html
http://books.google.com/books?id=dKaBdb-xYcoC&pg=PA194&lpg=PA194&dq=how+to+use+xentrace&source=bl&ots=c7AbMSkRG8&sig=GirFTfx9oKDNoFaMgroo-3LHvmY&hl=en&ei=UnXGSd7_GI-stgf375hn&sa=X&oi=book_result&resnum=9&ct=result#PPA195,M1
Summary:
1) xentrace -e all trace.out (this command will record all the events)
2) cat trace.out| xentrace_format formats | more
xentrace_format is a program to translate the binary format of trace.out to text format.
The formats file is in /tools/xentrace/formats. In the same directory, there is a file called xentrace_format. It is not the "format" file, it is a python program. If you use it as format file, you will get an error "SyntaxError: Unexpected EOF while parsing".
Wednesday, March 4, 2009
Clone Xen VM
Here is the man page:
http://linux.die.net/man/1/virt-clone
Another post:
http://www.linuxquestions.org/questions/susenovell-60/cloneduplicate-a-xen-vm-domu-618921/
Monday, March 2, 2009
Friday, February 27, 2009
IO scheduler on Xen
http://books.google.com/books?id=XS-Jj7s2nhYC&pg=PA467&lpg=PA467&dq=CFQ+Xen&source=bl&ots=UUJJrX36AZ&sig=c3iyq1rNYh5WsXdz4pyKVMxE5pU&hl=en&ei=SxqoSZ2DEY-ctwfI7Pj7Dw&sa=X&oi=book_result&resnum=8&ct=result
Xen devel:
http://www.mailinglistarchive.com/xen-devel@lists.xensource.com/msg12022.html
http://lists.xensource.com/archives/html/xen-devel/2005-11/msg00371.html
Change the scheduler:
Q: I am experiencing a heavy slowdown of the entire dom0 and all other domUs if one domU gets under heavy load.Is there any way to tighten this domU by adjusting something like scheduling?
A: You can use elevator=cfq as the command line option for both the dom0 and domU kernels in grub.conf and /etc/xen domU config files respectively. This will force the use of cfq as the default scheduler. By default anticipatory is the scheduler in dom0 and noop in domU. Alternatively:echo "cfq" > /sys/block/sda/queue/scheduler
Monday, February 16, 2009
Install Xen3.3 on CentOS5 and ubuntu
http://driverentry.spaces.live.com/blog/cns!8F8079B325833D71!867.entry
Ref:
Ubuntu:
http://www.howtoforge.com/ubuntu-8.04-server-install-xen-from-ubuntu-repositories
http://bderzhavets.blogspot.com/2008/05/install-opensolaris-200805-domu-at.html
http://bderzhavets.wordpress.com/2008/11/13/backport-intrepid-xen-33-hypervisor-at-ubuntu-hardy-dom0-2624-21-xen/
CentOS 5
http://robinbowes.com/article.php/20081023014423777
http://bderzhavets.blogspot.com/2008/08/install-xen-3.html
http://book.xen.prgmr.com/mediawiki/index.php/3.3
Comiple xen 3.3 on CenOS 5
Ref: http://www.nikhef.nl/pub/projects/grid/gridwiki/index.php/Xen_on_CentOS_5_-_Notes
1. download two tar files from xen.org
2. Install mercurial src code version manager
wget http://www.selenic.com/mercurial/release/mercurial-0.9.5.tar.gz
tar xvfz mercurial-0.9.5.tar.gz
cd mercurial*
make install
export PYTHONPATH=/usr/local/lib/python2.4/site-packages:${PYTHONPATH}
(if not export that environment variable, you will get an error as this: ImportError: No module named mercurial).
3. Install prerequested packages:
yum install \
gcc make zlib-devel zlib python-devel curses libncurses-devel ncurses-devel openssl openssl-devel \
`yum search xorg-x11|grep dev|grep x86_64|awk -F . '{print $1}'` \
bridge-utils tetex tetex-latex transfig libtool-ltdl dev86 glibc-devel
( for i386 version, replace x86_64 with i386)
4. tar xzf xen*, cd xen*, make world
5. cd dist, sh ./install.sh
6. disable tls:
Put this in /etc/ld.so.conf.d/xen.conf:
# This directive teaches ldconfig to search in nosegneg subdirectories
# and cache the DSOs there with extra bit 0 set in their hwcap match
# fields. In Xen guest kernels, the vDSO tells the dynamic linker to
# search in nosegneg subdirectories and to match this extra hwcap bit
# in the ld.so.cache file.
hwcap 0 nosegneg
Note that the file name _must_ end ".conf". When you've done that, run
/sbin/ldconfig and reboot. The problem should go away.
7. reboot
Last updated: 12.8.2009
Sunday, February 15, 2009
Build Xen 3.3.1 src on Ubuntu 8.04
2. Install missing package:
apt-get install libssl-dev mercurial gettext-kde libx11-dev libncurses5-dev patch build-essential texlive-latex-base tetex-bin tetex-extra transfig fig2ps texinfo
3. make a soft link for xgettext:
ln -s /usr/bin/kde-xgettext /usr/bin/xgettext
4. go to xen src directory
make world
5. cd dist
sh ./install.sh
6. depmod 2.6.18.8-xen
update-initramfs -c -k 2.6.18.8-xen
update-grub
7. reboot
Result: can boot into Dom0, but failed to start xend. :(
Wednesday, February 4, 2009
Tuesday, January 27, 2009
debug Xen
http://lists.xensource.com/archives/html/xen-devel/2008-10/msg00195.html
2. build option :
Xen provides a number of build-time options which should be set as environment variables or passed on make's command-line.
- verbose=y
- Enable debugging messages when Xen detects an unexpected condition. Also enables console output from all domains.
- debug=y
- Enable debug assertions. Implies verbose=y. (Primarily useful for tracing bugs in Xen).
- debugger=y
- Enable the in-Xen debugger. This can be used to debug Xen, guest OSes, and applications.
- perfc=y
- Enable performance counters for significant events within Xen. The counts can be reset or displayed on Xen's console via console control keys.
http://en.opensuse.org/How_to_Capture_Xen_Hypervisor_and_Kernel_Messages_using_a_Serial_Cable
4. KDB
http://lists.xensource.com/archives/html/xen-devel/2008-11/msg00165.html
Thursday, January 22, 2009
Wednesday, January 21, 2009
Xen passthrough IO
http://forums.opensuse.org/install-boot-login/400984-xen-passthrough-nic.html#post1903926
http://lists.xensource.com/archives/html/xen-users/2007-11/msg00684.html
http://www.novell.com/communities/node/2880/assign-dedicated-network-card-or-pci-device-xen-virtual-machine
http://wiki.xensource.com/xenwiki/Assign_hardware_to_DomU_with_PCIBack_as_module