qemu 在当前OS中运行其它的操作系统

来源:互联网 发布:笔记本怎么样卸载软件 编辑:程序博客网 时间:2024/06/07 03:33

 qemu从某种意义上功能类似于vmware/virtual box之类的软件,可以让你在当前OS中运行其它的操作系统,但是这仅仅是qemu的一种功能

qemu还可以模拟不同的cpu架构下的系统,比如在普通的个人pc上运行 arm linux之类,这个vmware之类的可能没有

关于qemu的使用
先到官网上下载qemu的源代码,目前是 1.2,如果使用的是linux系统,这个好办,直接编译安装,网上有不少说明的文档

使用的过程一般分为三步
1. 创建虚拟机文件系统
qemu-img create /f qcow2 xxx.img 10G

2. 在虚拟机文件系统中安装操作系统
qemu-system-i386 -hda xxx.img -cdrom xxx.iso -boot d  以xxx.img为文件系统,xxx.iso是系统安装ISO文件

3. 运行安装好的操作系统
qemu-system-i386 -hda xxx.img 运行xxx.img中的系统

以上的命令参数都比较简单,实际使用中需根据具体情况自己配置创建一个虚拟硬盘 $ qemu-img create -f qcow hda.img 10G  创建文件系统    sudo dd if=/dev/zero of=rootfs.img bs=1M count=100    sudo mkfs.ext2 -N 512 rootfs.img  安装Linux系统 $ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.gz -hda hda.img -append "root=/dev/ram"  运行Linux系统 $ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.img-2.6.18-6-versatile -hda hda.img -append "root=/dev/sda1" qemu-system-arm -kernel zImage.integrator -initrd arm_root.img -nographic -append "console=ttyAMA0" qemu-system-arm -kernel <path to the kernel image>/zImage-<kernel version>-qemu-arm -initrd ususe.img -nographic -append console=ttyAMA0 Framebuffer console: qemu-system-arm -kernel <path to the kernel image>/zImage-<kernel version>-qemu-arm -initrd ususe.img -append console=tty1

Creating a hard disk image

If you are using FILO, you must create a hard disk image containing the Linux kernel and optional initramfs that FILO loads.

Whether or not you use FILO, you may also wish to populate the disk image with the root filesystem of whatever Linux distribution you want to run.

Create an empty disk image:

$ qemu-img create -f raw disk.img 200M

Format it:

$ mkfs.ext2 -F disk.img 

The remaining steps must be performed as root. Create a temporary mountpoint and mount the image:

# mkdir /mnt/rootfs# mount -o loop disk.img /mnt/rootfs

Create a boot directory and copy your Linux kernel (vmlinuz) and initramfs (initrd) to it:

# mkdir /mnt/rootfs/boot# cp vmlinuz /mnt/rootfs/boot/vmlinuz# cp initrd /mnt/rootfs/boot/initrd

At this point, you can also copy a complete root filesystem to the disk image.

# cp -R /* /mnt/rootfs 

Alternatively, with Debian you can use the debootstrap command to create a basic root filesystem:

# debootstrap --arch i386 sarge /mnt/rootfs http://ftp.debian.org/debian/ 

If you are using a debootstrap filesystem, open the file /mnt/rootfs/etc/inittab and change runlevel to level 1:

id:1:initdefault: 

cd out of /mnt/rootfs and umount it:

# umount /mnt/rootfs

Exit from the root account:

# exit

Starting coreboot in QEMU

Execute QEMU using the following parameters:

$ qemu -bios path/to/coreboot.rom -hda disk.img -nographic

 

0 0
原创粉丝点击