HOWTO: Debian Qemu (running Debian inside Debian)
==Building Debian Images for QEMU==
Install qemu and debootstrap:
apt-get install qemu debootstrap
Create image (replace “image.raw” with image filename and
qemu-img create image.raw size
Associate image file with a loopback device:
losetup.orig -f # take note of the filename returned
losetup.orig loop_device image.raw # replace
Create a ext2 filesystem on the image:
mke2fs loop_device
Mount the image:
mkdir -p /mnt
mount loop_device /mnt
Run debootstrap to install the Debian system :
debootstrap etch /mnt ftp://ftp.de.debian.org/debian/
Create a basic /mnt/etc/fstab on the image so the init scripts do not complain:
proc /proc proc defaults 0 0
/dev/hda / ext2 defaults,errors=remount-ro 0 1
== Compile kernel ==
Download and uncompress kernel source :
cd ~
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.tar.bz2
tar -xvjf linux-2.6.22.tar.bz2
Compile kernel :
cd linux-2.6.22 # inside kernel tree
make defconfig # make default configuration
make menuconfig # add what you want to use
make # compile kernel
make modules # compile modules
make modules_install INSTALL_MOD_PATH=/mnt # install modules in filesystem
== Booting ==
Umount filesystem:
umount /mnt
Detach loopback device:
losetup -d loop_device
Done! You can run QEMU using the following command:
qemu -hda image.raw -kernel ~/linux-2.6.22/arch/i386/boot/bzImage -append “root=/dev/hda”
Wrote by:
Anderson Lizardo
Francisco Alecrim (INDT)
== Connecting host<->guest ==
Recompile the kernel with the network drivers available. I don’t remember the correct option, so active all in :
-> Device Drivers
-> Network device support (NETDEVICES [=y])
-> Ethernet (10 or 100Mbit) (NET_ETHERNET [=y])
Define ip used by host(real machine) in (/etc/qemu-ifup) :
#!/bin/sh
sudo -p “Password for $0:” /sbin/ifconfig $1 192.168.0.1
Boot up your virtual system again adding(-net tap -net nic)
sudo qemu -net tap -net nic -hda image.raw -kernel ~kernel/tree/linux-linus-2.6/arch/i386/boot/bzImage -append “root=/dev/hda”
Define the ip and route used by guest(virtual machine):
ifconfig eth0 182.168.0.2 netmask 255.255.255.0
route add default gw 192.168.0.1
Test it:
ping 192.168.0.1
Define DNS servers:
scp 192.168.0.1:/etc/resolv.conf /etc/resolv.conf
That’s it!!
Show de bola esse tutorial. Muito bom mesmo. Me ajudou bastante. Valeu Kepler pelo ótimo tutorial.
hahahaahhahhahaahhahah