QEMU-Running Debian in Debian

Source: Internet
Author: User

= Building Debian Images for QEMU =

Install qemu and debootstrap:

Apt-get install qemu debootstrap

Create image :

Qemu-img create disk. img 512 M

Associate image file with a loopback device:

Losetup. orig-f # take note of the filename returned
Losetup. orig/dev/loop0 disk. img # replace With name returned above

Create a ext2 filesystem on the image:

Mkfs. ext3/dev/loop0

Mount the image:

Mkdir-p/mnt
Mount/dev/loop0/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 defaults 0 0
/Dev/sda/ext3 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.32.tar.bz2
Tar-xvjf linux-2.6.32.tar.bz2

Compile kernel:

Cd linux-2.6.32 # 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/dev/loop0

Done! You can run QEMU using the following command:

Qemu-hda image. raw-kernel ~ /Linux-2.6.32/arch/i386/boot/bzImage-append "root =/dev/sda"


= 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 100 Mbit) (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 linus-2.6/arch/i386/boot/bzImage-append "root =/dev/sda"

Define the ip and route used by guest (virtual machine ):

Ifconfig eth0 18.00.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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.