Topic: QEMU on FreeBSD

After scottro suggestion:
http://forums.bsdnexus.com/viewtopic.ph … 707#p13707
I wrote short qemu howto install/usage on FreeBSD as host os, and in this example with Win2000 as guest os. wink

changelog:
1. removed useless /etc/qemu-ifup script [it was used in older versions of qemu with tap/bridge interfaces]
2. added info about sound emumation inside qemu OS.
3. removed HACKS_CIRRUS from options [thx to scottro sugestion], reason here: http://forums.bsdnexus.com/viewtopic.ph … 036#p14036
4. sometimes OS installation requires unload of kqemu. short: install without kqemu and the use with kqemu

Install qemu with options showed below:

# cd /usr/ports/emulators/qemu && make install clean
Options for qemu:
 [X] KQEMU          Build with (alpha!) accelerator module
 [ ] HACKS_CIRRUS   Large display speedup (buggy!)
 [ ] RTL8139_TIMER  allow use of re(4) nic with FreeBSD guests
 [ ] SAMBA          samba dependency (for -smb)
 [X] SDL            SDL/X dependency (graphical output)
 [X] CDROM_DMA      IDE CDROM DMA

install and configure sudo:

# cd /usr/ports/security/sudo && make install clean

sudo config:

# cat > /usr/local/etc/sudoers << EOF
root            ALL=(ALL) ALL
username        ALL=(ALL) NOPASSWD: ALL
EOF

username is YOU.

load needed modules:

# sudo kldload aio
# sudo kldload kqemu

create Windows2000 install CD image, use cat or dd:

% cat /dev/acd0 > ~/qemu/win2k.iso
% dd bs=2048 if=/dev/acd0 of=~/qemu/win2k.iso

create qemu image for new OS:

% qemu-img create -f qcow2 ~/qemu/win2000.img 4G

install new os, Windows2000 in our example:

% qemu -boot d -hda ~/qemu/win2000.img -m 128 -cdrom ~/qemu/win2k.iso -win2k-hack -localtime

if You have any problems while installing the OS then unload kqemu module and install again, then after install, load the kqemu module again:

% sudo kldunload kqemu
% qemu -boot d -hda ~/qemu/win2000.img -m 128 -cdrom ~/qemu/win2k.iso -win2k-hack -localtime
% sudo kldload kqemu

typical usage of OS under qemu:

% qemu -hda ~/qemu/win2000.img -m 256 -localtime

typical usage of OS under qemu in snapshot mode [to commit made changes hit left_CTRL+left_ALT+2 and type commit]:

% qemu -hda ~/qemu/win2000.img -m 256 -localtime -snapshot

1. to switch focus between qemu mouse focus and X11 mouse focus use: left_CTRL+left_ALT
2. to ensure that You use kqemu kernel module in user mode hit left_CTRL+left_ALT+2 and type info kqemu, if everything is ok You will see:

kqemu support: enabled for user code

if not You will see:

kqemu support: disabled

if disabled it will work, but terribly slow, You will be running at Pentium 75 speed at host with CPU AthlonXP 1.66GHz.
3. to switch between qemu console and qemu os emualtion use left_CTRL+left_ALT+2 to go to console and left_CTRL+left_ALT+1 to back to emulation.
4. enabling network on emulated os, use DHCP configuration inside emulated os to get automatic IP adress 10.x.x.x

after You quit You os inside emulated os, or by qemu console left_CTRL+left_ALT+2 and type quit use this command to launch again Your emulated OS:

% qemu -hda ~/qemu/win2000.img -m 256 -localtime

How to have sound in qemu OS, You just need to launch qemu the way I listed above, only with -soundhw sb16 or -soundhw es1370 to emulate Sound Blaster 16, or Sound Blaster 128. You can also enable standart annoying BEEP with -soundhw pcspk. You can also enable all three of them like that:  -soundhw sb16,es1370,pcspk, or just BEEP + one of them: -soundhw es1370,pcspk, examples

% qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw pcspk
% qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw es1370,pcspk
% qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw es1370,pcspk,sb16

fluxbox add-on:
in ~/.fluxbox/apps:

# qemu
[app] (class=SDL_App)
  [Workspace]  {2}
  [Deco]       {BORDER}
[end]

resources:

man qemu-img
man qemu
man aio
man dd
man cat
http://kidsquid.com/cgi-bin/moin.cgi/QuickStartGuide

http://qemu-forum.ipi.fi/qemu-snapshots/
http://qemu-forum.ipi.fi/
http://qemu.org/user-doc.html
http://en.wikipedia.org/wiki/QEMU


The sameschema works for Solaris 10, You only do not use -win2k-hack.

feel free to point errors, typo and Your hints/suggestions here.

Last edited by vermaden (2007-02-05 03:34:49)

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

Excellent.  I don't quite understand the purpose of the qemu-ifup script though. When would it be run?

If I run it, whether qemu is running or not, I get the message that interface 0.0.0.0 does not exist.  The qemu Win2k install can't ping anything, but the Internet works.  (However, sad to say the main program for which I need Windows, a Nortel VPN client, doesn't work--it doesn't work in Win4BSD either, though they have said that their planned updates will fix that issue.)

Still you are right, it's come a long way since I last used it.  I think my main use for it will be to play with various Linux distros when I go through my distro swapping moods, which happens on occasion. 

Thank you for this howto it made it very simple.

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

scottro wrote:

Excellent.  I don't quite understand the purpose of the qemu-ifup script though. When would it be run?

I forgot that it was used in old qemu release, with bridge/tap interfaces, now it is useless, so I removed it, thx for point that out.

scottro wrote:

The qemu Win2k install can't ping anything, but the Internet works.

Qemu OS is treated like internal network computer so You will need to use NATD to get 'true' network, althou Opera works nice with this actual config, and Yes ping is dead:
http://vermaden.proplayer.pl/gfx/screen … n-qemu.png

scottro wrote:

Still you are right, it's come a long way since I last used it.  I think my main use for it will be to play with various Linux distros when I go through my distro swapping moods, which happens on occasion.

It is little polished comparing to 0.8.2, but still needs a lot work, especially to speed up display, CPU/MEM speed is decent.

scottro wrote:

Thank you for this howto it made it very simple.

No problem. wink

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

Ok, this is fun.  smile  I'm writing this from qemu, running a live CD of the Elive Linux distribution.

I am really glad you wrote this.

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

Enjoy wink

Any suggestions about topic of next howto? smile

BTW: I forgot, You used vmware3 lately, tell me the diffrence in speed between vmware and qemu.

Last edited by vermaden (2006-12-26 05:34:46)

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

VMware3 boots up a little faster.  I'd say it's slightly faster than qemu.   I haven't kept the Win2k install on--I plan to use the qemu for playing with various Linux distros, perhaps for a flash site that just won't work with FreeBSD (though those are becoming far fewer.)

However, I've kept Win4BSD which is basically qemu, perhaps with a few enhancements to make it install more easily and an automatic mapping of your $HOME directory.

Depending upon what you need your Win2k to do, the difference has become far less than it was several months ago, the last time I tried qemu. 

I wouldn't use either one for playing games, those seem to be slow.  As I need Windows for some work related things, I don't even enable sound. 

As for the next topic--if there's some question that keeps popping up on forums and I know the answers, it seems worthwhile to write something.  Another thing is where I set something up, and it takes me more research than I think it should have to get it working, for example, doing various things in mutt. 

Actually, just think of things that catch your interest that you know, and write about them.   Try to take it from the perspective of someone who hasn't done it before--otherwise, you wind up taking mental shortcuts that will confuse the newcomer to the application (or whatever it is that you're covering in your howto.)

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

scottro,

you didn't try this on current did you? It doesn't build for me sad

"An educator never says what he himself thinks, but only that which he thinks it is good for those whom he is educating to hear."
-Nietzsche

Re: QEMU on FreeBSD

RoddieRod, yes, I put qemu on CURRENT.  It built for me without problems.

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

RoddieRod wrote:

It doesn't build for me sad

What errors You get?

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

Hrrm.  If you like, I can do a pkg_create for you.  Would that help?  (I can do one for kqemu as well.)

On a side note, I noticed that I couldn't, on a Linux guest, get the Mod4 key working--one which I always use in my keyboard shortcuts in fluxbox.  I did a bit of reading--well, it didn't take much, it was in the qemu faq and found an old patch.  I repatched it for my Current FreeBSD installation and sent it off as a PR. 

If anyone wants it (it's a patch of sdl.c, a few lines to enable it to recognize the Mod4 key--useful in Windows for a few things as well) it's at http://www.scottro.net/patch.sdl.c

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

instead of doing cat > /usr/local/etc/sudoers << EOF
use visudo wink

Re: QEMU on FreeBSD

Here is my error:

atomizer# make install clean
===>  Building for qemu-0.8.2s.20061216
gmake -C i386-softmmu all
gmake[1]: Entering directory `/usr/ports/emulators/qemu/work/qemu-snapshot-2006-
12-16_05/i386-softmmu'
cc -O2 -fno-strict-aliasing -pipe -DNO_MALLOC_EXTRAS -march=opteron  -fno-strict
-aliasing -I/usr/local/include -mpreferred-stack-boundary=2 -fomit-frame-pointer
 -falign-functions=0 -fno-gcse -fno-reorder-blocks -fno-optimize-sibling-calls -
I. -I.. -I/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386
 -I/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05 -D_GNU_SOURCE -D_F
ILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DSMBD=\"/usr/local/sbin/smbd\" -I/usr/po
rts/emulators/qemu/work/qemu-snapshot-2006-12-16_05/fpu -DHAS_AUDIO -I/usr/ports
/emulators/qemu/work/qemu-snapshot-2006-12-16_05/slirp -c -o op.o /usr/ports/emu
lators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386/op.c
/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386/ops_sse.h
: In function `op_psrlq_mmx':
/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386/ops_sse.h
:213: error: unable to find a register to spill in class `GENERAL_REGS'
/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386/ops_sse.h                                                    :213: error: this is the insn:
(insn:HI 36 35 37 3 (parallel [
            (set (reg:DI 63 [ <variable>.q ])
                (lshiftrt:DI (reg:DI 63 [ <variable>.q ])
                    (subreg:QI (reg/v:SI 60 [ shift ]) 0)))
            (clobber (scratch:SI))
            (clobber (reg:CC 17 flags))
        ]) 309 {lshrdi3_1} (insn_list 33 (insn_list 35 (nil)))
    (expr_list:REG_DEAD (reg/v:SI 60 [ shift ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (expr_list:REG_UNUSED (scratch:SI)
                (nil)))))
/usr/ports/emulators/qemu/work/qemu-snapshot-2006-12-16_05/target-i386/ops_sse.h                                                    :213: confused by earlier errors, bailing out
gmake[1]: *** [op.o] Error 1
gmake[1]: Leaving directory `/usr/ports/emulators/qemu/work/qemu-snapshot-2006-1                                                    2-16_05/i386-softmmu'
gmake: *** [subdir-i386-softmmu] Error 2
*** Error code 2

Stop in /usr/ports/emulators/qemu.

And Scottro - I'll try a package. I seem to be getting strange errors building things lately. This is the only port I'm having trouble with sad

"An educator never says what he himself thinks, but only that which he thinks it is good for those whom he is educating to hear."
-Nietzsche

Re: QEMU on FreeBSD

Sounds like you might need to run memtest86 on your box.

Re: QEMU on FreeBSD

Venture37 wrote:

instead of doing cat > /usr/local/etc/sudoers << EOF
use visudo wink

Yes it is also possible, but I focused to make everything without 'leaving' the shell prompt to any interactive app, like text editor for example.

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

Venture37 wrote:

Sounds like you might need to run memtest86 on your box.

I sure hope not! I just bought this box in Feb! But, I'll give it a look....

"An educator never says what he himself thinks, but only that which he thinks it is good for those whom he is educating to hear."
-Nietzsche

Re: QEMU on FreeBSD

RoddieRod wrote:

Here is my error: (...)

What are Your CFLAGS/CXXFLAGS?

Also the code seems to broke on building SSE/MMX extensions, maybe try to build qemu with CPUTYPE=operton commented out in /etc/make.conf.

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

http://www.scottro.net/qemu-0.8.2s.20061216.tbz

http://www.scottro.net/kqemu-kmod-1.3.0.p9_3.tbz


If you need any other dependencies, let me know.  It could, of course, be hardware, but it's always possible that for some reason, your CURRENT installation is becoming recalcitrant.  I know I was going through that at one point, eventually, enough upgrades worked it out..  <shrug>

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

scottro wrote:

http://www.scottro.net/qemu-0.8.2s.20061216.tbz

http://www.scottro.net/kqemu-kmod-1.3.0.p9_3.tbz


If you need any other dependencies, let me know.  It could, of course, be hardware, but it's always possible that for some reason, your CURRENT installation is becoming recalcitrant.  I know I was going through that at one point, eventually, enough upgrades worked it out..  <shrug>

Thanks again Scottro.

I was thinking the same thing about my system. I debating a portupgrade -a....

"An educator never says what he himself thinks, but only that which he thinks it is good for those whom he is educating to hear."
-Nietzsche

Re: QEMU on FreeBSD

vermaden wrote:
Venture37 wrote:

instead of doing cat > /usr/local/etc/sudoers << EOF
use visudo wink

Yes it is also possible, but I focused to make everything without 'leaving' the shell prompt to any interactive app, like text editor for example.

visudo runs a bunch of checks on the input so that you can't create a broken sudoers file.  It will error out and tell you which line to fix.  Using cat will not.

Same goes for editing /etc/passwd directly.  Much safer to use vipw.

Don't let the vi in the name scare anyone.  It uses whatever editor is listed in the EDITOR env var.  So you can set it to anything you are comfortable with (personally, I set it to ee or pico/nano on every system I touch -- vi should die).

Last edited by phoenix (2006-12-28 00:03:13)

Re: QEMU on FreeBSD

good to know about vipw.

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

2. added info about sound emumation inside qemu OS [scottro suggestion wink].

Last edited by vermaden (2006-12-29 01:33:23)

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

changes:
3. removed HACKS_CIRRUS from options [thx to scottro sugestion], reason here: http://forums.bsdnexus.com/viewtopic.ph … 036#p14036
4. sometimes OS installation requires unload of kqemu. short: install without kqemu and the use with kqemu

"religions, worst damnation of mankind"
[color=Blue]Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for

Re: QEMU on FreeBSD

http://fabrice.bellard.free.fr/qemu/download.html

Should be interesting especially for FreeBSD. Kqemu is no open source and qemu arrived in a new version.

F!XMBR

Freedom is the sure possession of those alone who have the courage to defend it. --Pericles

Re: QEMU on FreeBSD

I thought I would add this bit of information.  If you are running qemu through vnc--that is, if you open a vnc server session on the host, go in with vnc, then launch qemu from the vnc session--the keyboard might be out of wack unless you specify it with the -k option covered in qemu's man page.  I want an English US layout.   The man page mentions this, but it's the sort of thing that you miss until you use it.  smile

(It's comment is that the -k option shouldn't be necessary save for certain special situations and mentions VNC as one of those situations).

At any rate, thought I'd pass this along as I was getting quite aggravated when my password wasn't working.   A bit of googling mentioned the -k option and only then did I go to the man page and see that they have this situation covered.

<@andre> i would be so much more efficient if i wasn't so stupid

Re: QEMU on FreeBSD

Qemu wrapper with networking support for a guest and ability of reentrant usage.
Tested on FreeBSD 7.0-STABLE.

#!/bin/sh
#
# Qemu wrapper
# (c) 2008 kflavour
#
netif=nfe0            # replace nfe0 to your physical network interface

OK='printf .\n'        # macro

err()
{
    printf "\nError $?\n"
    exit 1
}

echo "Qemu wrapper with network support"

[ `id -u` -ne 0 ] && echo 'Error: root privilegies required' && exit 1

if ! kldstat | grep kqemu.ko >/dev/null; then
    echo -n "-> Loading In-kernel emulation module"
    kldload kqemu || err
    $OK
fi

if ! kldstat | grep aio.ko >/dev/null; then
    echo -n "-> Loading async I/O module"
    kldload aio || err 
    $OK
fi

# Setup bridge net
if [ `ifconfig -a | egrep '^tap|^bridge' | wc -l` -lt 2 ]; then
    echo -n "-> Configure bridge for guest"
    tap=`ifconfig tap create`
    bridge=`ifconfig bridge create`
    ifconfig $bridge addm $tap addm $netif up || err
    ifconfig $tap 0        # Comment this if qemu-ifup used
    $OK
fi

if [ $# -ne 0 ]; then
    qemu -net nic -net tap $*
    else
    return 0
fi

Last edited by kflavour (2008-12-07 15:03:18)