NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Reliable way to run emulated Linux under NetBSD



Hello,

Thank you everybody for your private and public feedback.

To dot my I's I'm going to give the solution for people looking for a solution 
how to run Linux in qemu / NetBSD and have it usable, so in my understanding 
with networking between guest and host and at serial connection.

To spell it out, finish the topic and don't produce off-topic over here 
(neither to go into non-generic details, so I will skip USB ports pass-through 
configuration-details), the formula is as follows:

1. Get ingredients:
- qemu from pkgsrc (tested with 2.0.0, from pkgsrc-2014Q2)
- get your favorite distro (Slackware64 14.1 confirmed to work)

2. Create image with for a hard disk [1]

qemu-img create -f qcow2 slack_hd.img 20G

NB. Full Slackware installation requires at least 8-10GB. 20GB is sufficient 
for basic hacking.

3. Install your favorite distro

NB. You may need X Window environment here.

Run installator inside your qemu machine:

qemu-system-x86_64 -cdrom image.iso -hda slack_hd.img -boot d

At the boot menu you must use (or the guest will crash down) additional kernel 
parameters 'noapic noacpi'. After system being loaded, perform standard 
installation.

4. Setup serial connection in your guest

Execute:
qemu-system-x86_64 -hda slack_hd.img

And now follow standard steps relevant for your solution, eg. 
http://docs.slackware.com/howtos:general_admin:serial_console for Slackware.

5. Setup tap-networking and bring the system up

In your NetBSD host:
ifconfig bridge0 create # Create bridge interface to link tap virtual devices
ifconfig tap0 create # Dedicated as a device piped with qemu's quest
ifconfig tap1 create # Dedicated as a virtual device for host
brconfig bridge0 add tap0 # Bind tap0 to bridge0
brconfig bridge0 add tap1 # Bind tap1 to bridge0
ifconfig tap1 192.168.0.2/24 # Setup host's interface address
ifconfig tap0 up # Bring it up
ifconfig tap1 up # Bring it up
ifconfig bridge0 up # Bring it up

Now run qemu as follows:
emu-system-x86_64 -hda slack_hd.img -net nic -net 
tap,ifname=tap0,script=no,downscript=no -monitor stdio -serial 
telnet:127.0.0.1:3000,server -nographic

This will run emulated x86_64 (amd64) system, with a network device over tap0, 
without up/down network interface scripts (we have done it manually) [2], 
qemu's monitor over stdout (it eases control over guest), serial connection set 
to telnet at localhost port 3000.

Now in your guest machine:
ip link set eth0 up # Bring it up
ip addr add 192.168.0.1/24 dev eth0 # Setup addressing

And try to ping host from guest or the other way around :-)

Cheers and EOT! Happy hacking,

[1] http://en.wikibooks.org/wiki/QEMU/Images
[2] http://en.wikibooks.org/wiki/QEMU/Networking


Home | Main Index | Thread Index | Old Index