木曜日, 4月 09, 2009

QEMU Cheat Sheet

QEMU Cheat Sheet

build a bootable ISO image file of linux system and use it on VMs

Install and use VirtualBox on Linux
  1. install virtualbox
    $ apt-get install virtualbox-ose
  2. add the current user to the group vboxusers
    $ adduser $USER vboxusers
  3. insert the relative modules to kernel
    $ /etc/init.d/vboxdrv start
  4. start virtualbox, follow the prompt, and boot a system from the iso file
    $ virtulbox


Use Qemu to boot iso file
  1. installed first
    $ apt-get install qemu
  2. boot the iso file
    $ qemu -m 128M -cdrom minios.iso -boot d -no-kqemu
    or boot a floppy image file
    $ qemu -m 64 -boot a -fda boot.img -no-kqemu
  3. to speed up the qemu, please install kqemu, the basic steps are:
    $ sudo apt-get install kqemu-source kernel-package linux-source build-essential
    $ cd /usr/src/linux
    $ sudo module-assistant prepare kqemu
    $ sudo module-assistant build kqemu
    $ sudo module-assistant install kqemu
    $ sudo depmod -a
    $ sudo modprobe kqemu
    $ sudo mknod /dev/kqemu c 250 0
    $ sudo chmod 666 /dev/kqemu

    now, there is no need to use the -no-kqemu option when using qemu and the
    running speed of qemu will be accelerated.


Build the network between VMs and the HOST system/Internet

Boot linux kernel with Qemu
  1. create a virtual disk image file
    $ qemu-img create -f qcow linux.img 1G

    In this command the -f option is for the disk image format. The following formats are supported: vfat, vpc, bochs, dmg, cloop, vmdk, cow, qcow, and raw, depending on the OS. See also: .img and .iso. The supported filesystem formats are abbreviations for:

    • vfat - Virtual VFAT
    • vpc - Virtual PC
    • bochs - BOCHS filesystem
    • dmg - macintosh Disk iMaGe
    • cloop - linux Compressed LOOP
    • vmdk - vmware Virtual Machine DisK format
    • qcow - Qemu Copy-On-Write
    • raw - RAW filesystem (no special format)
    • cow - user mode linux Copy-On-Write

  2. boot the kernel using qemu with the -S option
    sudo qemu -s -S -no-kqemu -kernel ../SSS/arch/i386/boot/bzImage -hda linux.img -append "root=/dev/hda"(See also Breakint at boot startup on qemu)
  3. switch it to the qemu command line via typing the
    following command to start the gdb server:
    $ gdbserver 1234
  4. start a new terminal on your HOST system and execute gdb to
    debug the linux kernel.
    $ gdb /path/to/vmlinux
    (gdb) target remote localhost:1234


一种方便的Linux内核调试方法:VirtualBox + KGDB

0 件のコメント: