Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5708540
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: LINUX

2006-09-13 15:46:48

首先从 下载 qemu-0.8.1-i386.tar.gz (Binary distribution for linux-i386 (untar it in '/')), 解压缩后直接按照目录结构复制到”/”下.

下载 freedos.img.bz2 (FreeDOS disk image (modified version from the Bochs project)), 解压后得到 freedos.img, 即可使用命令 qemu freedos.img 执行:


同时也可以看到命令行中有警告信息:

Could not open '/dev/kqemu' - QEMU acceleration layer not activated

说明 kqemu 并没有起作用.

接着就要安装 kqemu 了, 首先安装必要的开发环境:
......$ sudo apt-get install linux-headers-$(uname -r) build-essential gcc
我这边是 linux-headers-2.6.15-26, gcc 的版本是 4.0.3 .

然后下载 kqemu-1.3.0pre9.tar.gz - New version with full virtualization support

按照其中的文档 kqemu-doc.html 进行操作, 首先进行编译:
将压缩文件解压, 进入解压后的目录, 依次执行
./configure
make
sudo make install
此时已经能够看到 /dev/kqemu 了, 但是执行 qemu 的时候还是报告 “Could not open '/dev/kqemu' ”, 于是重启系统, 发现重启后 /dev/kqemu 就没有了, 经过仔细研究 kqemu-1.3.0pre9.tar.gz 中的 install.sh 文件, 发现可以这样解决:
将 install.sh 中的如下几句话写到 /etc/rc.local 中即可(注意要放在原有的最后一句“exit 0”之前):
# Create the kqemu device. No special priviledge is needed to use kqemu.
device="/dev/kqemu"
rm -f $device
mknod $device c 250 0
chmod 666 $device
然后在 rc.local 中再加上一句:
/sbin/modprobe kqemu
重新启动 Ubuntu, 可以看到 /dev/kqemu, 执行 qemu freedos.img 试验来一下, 果然没有出现 “Could not open '/dev/kqemu' ”, 在 qemu 的控制台(可以在 qemu 界面上使用热键 ctrl-alt-2 进入, 通过 “info kqemu” 命令验证了 kqemu 确实已经 enable 了:


建立一个 4G 的硬盘:
......$ qemu-img create -f qcow winxp.4G.img 4G
Formating 'winxp.4G.img', fmt=qcow, size=4194304 kB
使用 ISO 文件光盘启动, 安装 WinXP:
......$ qemu -cdrom DeepinXP-V4.iso -boot d -m 384 -net nic -net user  winxp.4G.img
在运行时可能会报告内存不足:
You do not have enough space in '/dev/shm' for the 384 MB of QEMU virtual RAM.
To have more space available provided you have enough RAM and swap, do as root:
umount /dev/shm
mount -t tmpfs -o size=400m none /dev/shm
按照提示重新 mount /dev/shm 就可以了

安装完毕后可以使用
 ......$ qemu -cdrom DeepinXP-V4.iso -boot c -m 256 -net nic -net user -kernel-kqemu  winxp.4G.img
启动 WinXP 了:



QEMU 具有两个选项控制 kqemu 加速器的行为, '-no-kqemu' 为不使用加速器, '-kernel-kqemu' 则是全加速模式, 如果这两个选项都没有, 那么就是只对 user code 进行加速, 而对 guest kernel 还是使用动态指令翻译的模式运行.

引用来自 的一段说明:

Full virtualization mode


This mode is activated with the '-kernel-kqemu' QEMU option. It is currently only supported for 32 bit guest OSes (the x86_64 code is not debugged yet). When KQEMU runs in full virtualization mode, both guest kernel and user code are executed directly on the host CPU. In normal mode, only the user code is executed directly and the kernel code is still dynamically translated by QEMU.

The full virtualization mode cannot work with all OSes because it makes some assumptions about the x86 instructions that the guest OS uses. Note that even if some assumptions are made on the guest OS, the full virtualization mode is secure by design: all the code is executed in user mode on the host processor which means it cannot break the host OS.

The requirements for a guest OS to work in full virtualization mode are very simple and most recent OSes (such as Linux or Windows 2000/XP) fulfill them. Interested OS writers can contact the author to get the necessary information to make their OS work in full virtualization mode in QEMU.


比较了以下 '-no-kqemu' 和 '-kernel-kqemu' 两个模式下的虚拟机运行速度, 区别还是很明显的 :)

阅读(3506) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~