Monday, January 04, 2010

FreeBSD under Hyper-V

OK.  I'm playing with FreeBSD 8.0 under Hyper-V R2.  I looked at FreeBSD 7.0 under Hyper-V R1 about this time last year and without a kernel patch, it had issues shutting down (and starting, and running...).  Well, the shutdown bug and the starting bug and all others seem to have been addressed fully aside from one slight networking issue.  So here's the lowdown on this one remaining issue...

As there's no synthetic network adapter driver for the "good" NIC in Hyper-V for FreeBSD (nor OpenBSD nor Linux), then you need to use the "bad" NIC - the Legacy Network Adapter.  The issue with this is that it is slow - only 100 Mbps.  Under FreeBSD it is detected as a "de" NIC - the first one being "de0".

You can either configure this during the initial setup of FreeBSD using sysinstall, or by manually editing the /etc/rc.conf file and adding ifconfig_de0="DHCP" to that file.

There seems to be an issue with the way Microsoft built this adapter as under FreeBSD it doesn't properly obtain a DHCP-assigned address no matter where the DHCP server is - on a Windows box, a *nix box or a firewall/router/modem device.  Real, physical "de" NICs work fine.  At least there's a workaround that allows the DHCP-assigned address to work - you need to stop, start and re-acquire the DHCP-assigned address by running:

ifconfig de0 down
ifconfig de0 up
dhclient de0

Now, you can run this manually every time after you reboot the box, however that means that the box is offline until you log into it using Hyper-V Manager.  A better way to handle this is to create an /etc/rc.local file, add these commands to it, then chmod 755 /etc/rc.local to make it an executable file for root.

Obviously, once this has been done, a portsnap fetch then portsnap extract is a good idea.  (Or whatever way you want to keep your FreeBSD ports up to date.)  And then installing any updated portss that are available using ports, portmanager or portupgrade or whatever method floats your boat.


The Outspoken Wookie


Chris Knight said...

Nice to know there's someone else trying to get FreeBSD running under Hyper-V.

My 7.2 VMs are running reasonably OK with the kernel patch and the PowerShell kill script for safety.

Unless you want to port the Linux IC source we'll just have to wait for one of the FreeBSD developers to get interested in doing this.

Networking speed for my FreeBSD VMs isn't important at the moment, so I have no motivation to do a port myself. When I do need networking performance I use ESXi or Workstation.

I am happy to help fund a port however.

Oh, and there's the time sync issue as well, but at least ntpdate/ntpd can help fix this.

Anonymous said...

did the installation really work? i try to get this done... but no chance... not even the current or 9.0 version... no x86 no amd64 iso will run in my hyper-v r2 environment. i got kerne trap error in compination with cpu errors.. whats the trick?


Hilton Travis said...

Anonymous - obviously the install really worked or I wouldn't have been able to write this blog entry!

There's no trick except for what I mentioned in the blog post - configuring the network adapter. Of course, the guest doesn't power down properly, but this is a known issue with FreeBSD under Hyper-V - there's a known PowerShell fix and kernel patch for this issue if it is causing grief.

Tim said...

I'm glad that you've all managed to get FreeBSD working under Hyper-V because I've got three Hyper-V hosts and NONE of them will let me install 8.1 or 8.0 into a virtual machine. I keep getting a "write failure" error when the OS tries to install. I've tried changing the network adapter (not that I think this would affect my issue) but it's made no difference.

Anyone come across this before? If so then I'd love to hear from you.

vgr said...

Has anyone successfully ported the hyperv drivers from linux to freebsd yet?

Anonymous said...

Just wanted to say this fixed worked for us on 2008R2 hyper-v with openBSD 4.7


Greg Elliott said...

Though not related to the networking, I saw comments regarding people not being able to even install FreeBSD in Hyper-V. I ran into the same issue where I got write failures during installation. My trick, while not ideal, is to create a fixed-size VHD rather than the usual dynamically-expanding VHD. I have FreeBSD 8.2 running in Hyper-V using a fixed 24GB VHD. I do have the shutdown hang issue that others have experienced, so I do need to use the PowerShell script.

Hilton Travis said...

G'day Greg,

Thanks for the info - it has been a while since I've done a FreeBSD install under Hyper-V, but this "fixed vs dynamic" info may well help sort the issue out for future installs. I'll be sure to post any experiences I have back here.

heuristik said...

AMD procs will fail on boot unless you add the following to the boot parameters:

Set hw.clflush_disable=1

At initial boot menu, escape to shell prompt, type that command then boot. once FreeBSD is installed, do the same routine to get into the OS, then to make the change permanent, vi /boot/loader.conf or loader.conf.local (whichever is specific to your install) and add the parameter to the file.