Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using VirtualBox to Build FreeBSD VM on Debian

DZone's Guide to

Using VirtualBox to Build FreeBSD VM on Debian

In this post, we will outline how to install VirtualBox on Debian 9 (Stretch), and build a FreeBSD virtual machine to aid in the development process.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

Many virtualization software (aka hypervisors) can run on the host operating system of Linux. Notable open-source software includes VirtualBox, KVM, and Xen. This post outlines how to 1) install VirtualBox on Debian 9 (Stretch), and 2) build a FreeBSD virtual machine.

About VirtualBox

In 2010, Oracle acquired Sun Microsystems and, as a result, took over the ownership of several open-source technologies including VirtualBox and MySQL. Subsequently, VirtualBox was rebranded as Oracle VM VirtualBox, but the software has remained free and open-source.

VirtualBox, like KVM, is a type-2 hypervisor, meaning that it runs as a process on the host OS (Linux). In contrast, XEN is a type-1 hypervisor which runs directly on top of the bare-metal hardware. Type-1 hypervisors have an inherent advantage over type-2 regarding performance. Yet, type-2 hypervisors, such as VirtualBox, benefit from the continual advancement of their underlying OS.

Hypervisors typically support the same multitude of guest operating systems including Linux, BSD, Solaris, Mac OS X, and Windows. But, hypervisors vary in what host OSes they support. For instance, KVM only runs on Linux. VirtualBox, on the other hand, runs on multiple host platforms such as Linux, Solaris, macOS, and Windows.

Prepare for Installation

Perform the following steps prior to installing VirtualBox:

  1. Enable virtualization technology in BIOS.

  2. Download FreeBSD ISO.

Enable Virtualization in BIOS

In 2005, chip manufacturers introduced the instruction set extensions Intel VT and AMD-V to support hardware virtualization. Before that, all virtualization was done with software. VirtualBox supports both software and hardware virtualization. If hardware virtualization support is not available on a machine, VirtualBox will switch to software virtualization. Note that without hardware virtualization, VirtualBox can only create 32-bit virtual machines. In other words, a 64-bit virtual machine is only possible if hardware support is available.

To determine if your CPU supports hardware virtualization, run the following command: 

$ egrep '^flags.*(vmx|svm)' /proc/cpuinfo

The above command searches the CPU flags register for either 'vmx' (Intel VT) or 'svm' (AMD-V). If the result is non-nil, your machine does have hardware-assisted virtualization.

Even if your machine supports hardware virtualization, it does not necessarily mean that it is currently enabled. To confirm that it is enabled, reboot the machine and enter BIOS. Once inside the BIOS, look for an option to turn on virtualization technology.

Download FreeBSD ISO

VirtualBox is a full-virtualization hypervisor (as opposed to para-virtualization), meaning that the guest OS, FreeBSD in this case, can be used as is, without modification. Having said that,
you are responsible for downloading the guest OS yourself.

You can download the latest installer image (release 11.1) from the FreeBSD website. You have the options of downloading regular Installer Images, Virtual Machine Images, and SD Card Images. For this tutorial, use regular Installer Images (VirtualBox does not support all Virtual Machine image formats). Make sure that you select the right hardware architecture (amd64 vs i386).

Within the architecture, download the compressed disk image file with the disc1.iso.xz suffix and the corresponding SHA512 checksum file. The .xz file is about 40% smaller in size than the uncompressed version and will save you download time.

After you have downloaded the 2 files, decompress the disk image file and do a checksum using the respective commands below.

$ unxz FreeBSD-11.1-RELEASE-amd64-disc1.iso.xz
$ sha512sum -c CHECKSUM.SHA512-FreeBSD-11.1-RELEASE-amd64
...
FreeBSD-11.1-RELEASE-amd64-disc1.iso: OK
...

Install VirtualBox

The following commands need to be executed with root privilege.

  1. Add the source repository for VirtualBox.
    # echo deb http://download.virtualbox.org/virtualbox/debian stretch contrib > /etc/apt/sources.list.d/virtualbox.list
  2. Import the Oracle GPG public key.
    # wget -q https://www.virtualbox.org/download/oraclevbox2016.asc -O- | apt-key add -
     OK
  3. Install VirtualBox. 
     # apt update 
     # apt install virtualbox-5.2 

Create FreeBSD VM

After installing VirtualBox, run it for the first time by clicking Oracle VM VirtualBox in your menu system. For the Xfce desktop, the option is under the System submenu. Then, click New to create a virtual machine.

Next, provide a hostname, and specify the Type ( BSD), and Version ( FreeBSD 64-bit or 32-bit).

The remaining steps configure the memory size, create a virtual hard disk and specify its file format, its pathname and size, and whether storage is dynamic or fixed-sized. At each step, reasonable defaults are given and can be accepted unless your requirements dictate otherwise. Click Create at the end to create the virtual machine.

The virtual machine is in the powered-off state after creation. Next, power up the machine by clicking Start.

At this point, the VM has no operating system. Powering it on prompts you to insert a start-up disk. Click the folder icon to specify the file path for the disk image file downloaded earlier (FreeBSD-11.1-RELEASE-amd64-disc1.iso).

Continue by selecting Start. The FreeBSD boot-up screen appears. Hit Enter to boot.

Select Install to continue installation.

The FreeBSD installer now takes over and prompts you for information it needs to configure the system.

At the end, the installer will prompt you to reboot into the installed system. At this point, you should reboot, but, first, you must unmount the disk image file (otherwise, you will boot into the CD image again). The reboot procedure I recommend is as follows. First, close the VM window by clicking the X in the upper right-hand corner.

In the ensuing dialog box, select Power off the machine.

To unmount the CD disk image, click the Machine Tools down-arrow, and select Details.

In the Storage section, right-click the Optical Drive beside the IDE Secondary Master label, and select Remove disk from optical drive.

Now that the CD image is unmounted, you can click Start in the upper left-hand corner to boot the VM.

Post-Installation

If you experience audio or graphical issues after you boot into the virtual machine, follow the procedure below to install VirtualBox guest additions for FreeBSD.

Summary and Conclusion

VirtualBox is easy to install. With VirtualBox, Creating a FreeBSD virtual machine on a Linux host machine is straightforward. If you are looking for an open-source multi-platform hypervisor, VirtualBox should be high on your priority list.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
linux ,virtual box ,debian ,web dev

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}