Setting up FreeBSD environment on virtualbox

Hi all, In this post we will review the procedure of setting up FreeBSD environment on virtualbox along with setting up Internet on the guest OS(this was pretty tricky!).BTW, my host OS is Ubuntu 14.04

So, i am assuming you have already installed virtualbox as per your host OS and has downloaded the FreeBSD amd64 iso image(If not you can do it from here and extract it appropriately to get a .iso file.

Installing FreeBSD on virtualbox


Installing FreeBSD on virtual box is pretty straight forward, just insert use the downloaded iso to boot up the VM with default hardware settings for 64 bit FreeBSD OS. Following will be the bootup window:



Just press enter and follow default procedure. Don't attempt to configure network adapter at this stage ww'll do it later after complete installation.



Note: Please don't forget to remove the installation disc from virtual machine settings after complete installation. Otherwise, every time during bootup it will recall the install procedure.

Setting up Internet


We will be setting up host only adapter. Here's the common disadvantages of different type of network adapter types available:

NAT
Requires port forwarding if you want to connect to the vm from the host.

Host-only
The vm can not access the internet, unless the host is a router.

Bridged
Exposes the vm to the network; not portable.

Adding a virtualbox Host-only adapter

In VirtualBox > Preferences > Network, set up a host-only network.



 

Click on scredriver icon to edit the adapter settings. Add a new adapter if vboxnet0 isn't available



 

Disable DHCP server. Ckick on Ok and reboot the machine.

Also, on machine settings under network tab, select the settings as shown:



 

On host OS(Ubuntu)
sudo su
iptables -A FORWARD -o wlan0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

After these, you can verify the configuration by netstat and iptables as
uka_in@Madaari:~$ sudo iptables -L | grep 192.168.56.0
ACCEPT all -- 192.168.56.0/24 anywhere ctstate NEW
uka_in@Madaari:~$

uka_in@Madaari:~$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default www.mblaze.home 0.0.0.0 UG 0 0 0 wlan0
172.17.0.0 * 255.255.0.0 U 0 0 0 docker0
192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.56.0 * 255.255.255.0 U 0 0 0 vboxnet0
uka_in@Madaari:~$

On Guest OS(FreeBSD)

First check the interfaces available to FreeBSD by ifconfig:



so, my interface name is em0.

Then, we need to edit rc.conf file by ee /etc/rc.conf and add the below line to rc.conf
ifconfig_em0="inet 192.168.56.101 netmask 255.255.255.0"

So, finally here's how my rc.conf looks like:



Then reload the configurations by running /etc/rc.d/netif restart

Now final thing needed to be done is adding a default gateway which can be added like :
route add default 192.168.56.1

That's it it should now work! try ping 8.8.8.8.

Configuration can be verified by netstat as:



Notice the gateway mentioned. If gateway is not correctly setup errors like "no available route" will appear. Try pinging 192.168.56.1, if it worked and you still have no internet access you probably did some misconfig during packet forwarding in ubuntu.

Above procedure works for me, however, i had several issues while trying out other tutorials on internet. I guess, the best thing that help me debug out the problem was, Wireshark! It's really awesome. Don't hesitate to debug out problems and comment here with complete log in case of failure. Thanks.

Update:


Several common errors/issues:

SU:Sorry

Initially, with raw installation switching to root will give this error. One possible solution for this is to boot FreeBSD in single user mode and then enter the following commands:
mount -u -w /
pw usermod your_user_name -G wheel

and now, switching to root should work!

SSH From Host(Ubuntu) to Guest OS(FreeBSD in VirtualBox)

For this you should first have sshd_enable option enabled in your /etc/rc.conf file.

Then you need to add a port forwarding rule to VirtualBox network option like:

Now simply try ssh from your host machine like: ssh -p 2222 user_name@127.0.0.1 . If it shows ssh_exchange_identification: read: Connection reset by peer error try reloading rc.conf settings or restart the guest os.

References:

Comments

  1. You'll find that the shared folders doesn't work with FreeBSD guests. You'll need to set up nfs for Linux. For Windows I use mount_smbfs and mount my Windows host drive into FreeBSD.

    https://forums.freebsd.org/threads/10-2-vbox-shared-folders-mounting.55091/#post-365528

    ReplyDelete
  2. If you want a FreeBSD distribution with a GUI you have these options (All come with a graphical installer similar to FreeBSD):

    http://www.trueos.org - iXsystems has been sponsoring FreeBSD for a long time now. This is a rolling release from the CURRENT branch so it has all the latest Video Drivers. This has ZFS and a ton of bells and whistels turned on by default. The default desktop isn't everyones cup of tea (it's new but it's getting very good) but that can be easily changed using the package manager (is it still called AppCafe?). *warning* - I've had trouble developing on this in the past, especially with RTEMS.

    http://www.ghostbsd.org - This is a distro by a ericbsd. Currently he is matching RELEASE. Everything is nice and stable so far. I've got the RTEMS erc32 building on this platform. Ericbsd has been at this a while and has contributed alot to installers. Not surprisingly, he's been hired by ixSystems! The consequence is he's looking to port over to the TrueOS base on the CURRENT branch. I'd like him to support CURRENT too, so if you're keen, you should step onto the forums (forums.ghostbsd.org) and spark up the conversation.

    ReplyDelete
  3. Hi, Thanks for suggestion. Actually i am trying to setup FreeBSD environment for cross compiling current SDIO driver from https://github.com/kibab/freebsd/tree/mmcam-new for BBB. I am following your final build steps, mentioned here( http://narkive.com/dZ0TaVwR:8.1084.25). BTW, i encountered several errors of low swap space while buildworld, can you please share the specs of your build environment?

    ReplyDelete

Post a Comment

Popular posts from this blog

Understanding SD, SDIO and MMC Interface

Software licensing : Introduction and it's types

Implementing a MMC/SD/SDIO stack using CAM framework(Part 2)