How to use VirtualBox to build your home lab

By Elliot Alexander

How to use VirtualBox to build your home lab

If you're just getting started with your home lab, the process can feel overwhelming. You may still be deciding whether to buy new, second-hand, or pick up some cheap ex-enterprise hardware. Or maybe you will want to get a basic mini-PC, or even start on a Raspberry Pi, to avoid a big commitment upfront. It is common to make decisions about hardware that you'll regret later, like poorly sizing your machines, picking up noisy or power-hungry hardware, or starting with overly complex network hardware when all you needed was a 10/100 switch.

But there is another way to dip your toes into the world of homelabbing without commitment. Setting up VirtualBox on an existing home PC might seem like a silly idea, but it is a great way to plan or explore the world of running your home lab services without the commitment.

Now this won't be for everyone - if you've already got multiple machines, control over your own network, and a K8s cluster setup under your desk, then this probably isn't for you. But if you're interested in learning more about the basics of homelabbing, playing with some VMs without the need to follow overly complex tutorials, or managing everything remotely, this is a great place to start.

VirtualBox can be a test bed for your home lab

KISS principle at its finest

VirutalBox is a type 2 hypervisor (i.e. it runs within your existing operating system) and brings with it a host of great features that will make it easy to plan or test your home lab strategy, without the same commitment as buying new hardware.

There are some advantages to this. VirtualBox brings with it a lot of the same features you'd get on a dedicated type 1 hypervisor like Proxmox, including the ability to snapshot your VMs, set up more complex networking, and schedule up and downtime for your VMs. You can make use of your existing hardware and easily tweak the resources available to each virtual machine in your lab - just like you would on a dedicated hypervisor. If you've got the right hardware (i.e. a second network interface on your machine) you can even set up things like pfSense.

Related

Setting up pfSense at home is the best network upgrade I've done

Consumer-grade routers have come a long way over the years but the ISP-provided devices can still be temperamental or downright terrible. I ditched ISP routers at home more than a decade ago but I've yet to mess around with custom software and hardware outside of an office. Enter pfSense, which is now powering my entire home network, connecting all devices on the LAN with our FTTP link. It's powerful stuff, running on an MSI Cubi NUC 1M with an Intel Core 7 processor, 16GB of RAM, and two 2.5GbE ports. It's now a vital piece of equipment inside the home server cabinet and I couldn't be happier with the results. Not tried it yet? I highly recommend it.

Once you've got some basic services set up on VirtualBox, it's relatively easy to migrate your VMs to Proxmox or another type 1 hypervisor once you're ready to upgrade - you can simply export them to an .OVA file and reimport them in Proxmox.

How to set up a VM in VirtualBox

Now we won't rehash a full set of instructions for setting up a VM in VirtualBox, as that's been covered plenty of times before all over the internet, but we will run over some home lab specific elements that can help you get started with running services in VirtualBox.

We'll be assuming that most of the VMs you're running are Linux here, so your mileage may vary if you're running Windows machines. We'll be running VirtualBox in Windows, however, as we feel this is most applicable to the wider audience. Instructions on Linux should generally be similar, but there may be some differences.

Related

Is ex-enterprise gear worth it for your home lab?

Are you thinking of picking up some cheap second-hand gear for your home lab? Here's our advice on the do's and don'ts

Set up networking for your new VMs

The basics of setting up a VM for home use

For most of the VMs you'll run in VirtualBox, you will likely want them to receive an IP address from your router via DHCP, like a physical device connected to your network would. This will be different from the IP of your host machine and will also have its own MAC address, allowing you to set a static DHCP allocation on your router to ensure that the IP never changes.

To do this, you'll want to ensure your VM is set to use a bridged adapter in VirtualBox's Network tab. You can check this with the following steps.

Open VirtualBox and locate your machine. Go to Settings > Network.

Under Adapter 1, choose Attached to Bridged Adapter.

Boot your virtual machine. You can check the IP allocated to your Linux machine with the following: ip addr | grep "inet"

Use your Routers web console to allocate a static reservation to the device attached to that IP.

Your different virtual machines can speak to each other over your local network. While some configurations use a VirtualBox private network as a backbone, this may break compatibility with Proxmox (or another type 1 hypervisor) later and is a bit more of a limited use case.

Backing up your VMs

Remember to save the game at regular intervals!

Another great benefit of using any hypervisor is being able to take snapshots and backups of your virtual machines. This is great for a range of reasons. You can set up a 'base' VM with login and networking configured, and then use that as an easy template for spinning up more VMs. You can also make easy backups of your machines, so you can either move your VMs to another PC or recover them in an emergency.

Follow these steps to take an exportable snapshot of your virtual machine.

Open VirtualBox and power off your VM.

Right-click your target VM and select File > Export to OCI appliance.

Select the VM you want to back up in the Appliance Export Wizard.

Select your file format - we recommend OVA, which contains the whole VM and metadata.

Select a destination to save your file - remember to keep backups on a separate machine.

Click Export to export the VM.

To later import the VM, select File > Import Appliance in VirtualBox, then select your OVA file.

Run a virtual machine in headless mode

No more annoying windows hanging around on your desktop

Running virtual machines on your desktop doesn't have to be as intrusive or performance-hungry as you might think, as VirtualBox also natively supports running a virtual machine in headless mode. You can do this in the UI by right-clicking a VM and selecting Start > Headless start.

Alternatively, you can do this via the command line interface with the following command:

VBoxManage startvm "VM name" --type headless

If the "vboxmanage" command is not found in your Powershell Prompt, trying adding it to your path with: $env:PATH = $env:PATH + ";C:\Program Files\Oracle\VirtualBox"

You can similarly shut down a VM with:

VBoxManage controlvm "VM_NAME" acpipowerbutton

- if you want to shut down safely by simulating a power button press, or

VBoxManage controlvm "VM_NAME" poweroff

- if you want to force a shutdown immediately

Once a Virtual Machine is running in headless mode, you can restore its window by right-clicking the VM in the VirtuaBox UI, then selecting Show.

Schedule the startup and shutdown of your VMs

Bring services up automatically during the day and shut them down overnight

If you're running VMs on a PC that you use day to day, you may not want your services to be running 24/7. Luckily, VirtualBox allows you to manage your VMs via the command line, which will give you the option of running scheduled tasks to shut down and start up your VMs on a reasonable schedule. This might be done to ensure your VMs are shut down overnight, or to switch on at a certain time to perform a key task (like syncing with another device or server overnight).

If you're on Linux, you can automate a task using Cron. If you're on Windows, follow the steps below to automate running one of the above commands using the Windows Task Scheduler.

Open Task Scheduler by searching in the Windows Start menu.

Select Action > Create Basic Task from the top panel. Give the task a name and a description.

Configure when your task should run. I've configured mine to run Daily.

Then select Start a program for your task. In the next screen, paste the location of your VBoxManage binary. Make sure you include the ampersand and quotes to ensure the path is properly escaped. For example, mine is in: & 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' Then in the arguments section, add the following: startvm "VM_NAME" --type headless

Click Next to continue, then on the next screen, click Finish to create your task.

Now this task will only run when your user account is logged in. Allowing a task to run when not logged in can be more tricky, but is possible with a bit of Google-Fu.

Making use of local virtualization can be a great way to start playing with virtual machines

Now we're well aware that using VirtualBox to dip your toes into homelabbing won't be for everyone. If you're a seasoned user of type 1 hypervisors or have spare hardware lying around at home, then this probably isn't for you. But if you're using a single computer and want something you can easily learn with, test things out, and break without consequences, consider using local VMs in VirtualBox to whet your appetite for a proper home lab. It's free, low effort, and a useful way to start learning about how VMs, Linux, networking, and other essential home lab elements work.

VirtualBox isn't as all-powerful as some other tools out there, but it has a great CLI, which makes scripting around it relatively easy to get started with. It has all the options you're likely to need starting out, and is a great tool to learn on.

Previous articleNext article

POPULAR CATEGORY

industry

6242

fun

7978

health

6186

sports

8142