qemu 在當前OS中運行其它的操作系統

 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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章