Installing Home Assistant Supervised on headless ubuntu-server 18.04 (virtualbox)

Home Assistant has dropped native support for ubuntu.

So it is not possible to have supervised Home Assistant on ubuntu other then virtual machine.

There are plenty of guides for Home Assistant installation using virtualbox GUI, but it is not helpful for ubuntu-server headless computers. So we try to connect to our server via ssh and do all the work using command line only.

1. Install VirtualBox

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install virtualbox

We need to add our user to vboxusers group

$ sudo usermod -aG vboxusers user

As this instruction says, we need to do the following:

For VirtualBox create a new virtual machine, select “Other Linux (64Bit), assign it at least 2 GB of memory and “Use an existing virtual hard disk file”, select the VDI file from above, afterwards edit the “Settings” of the VM and go “System” then Motherboard and Enable EFI, then “Network” “Adapter 1” Bridged and your adapter.

2. Create virtual machine
Let’s create VM with name hass:

$ VBoxManage createvm --name hass --ostype Linux_64 --register

Set it’s bios to efi:

$ VBoxManage modifyvm hass --firmware efi

Set cpu number and memory:

$ VBoxManage modifyvm hass --cpus 2 --memory 2048

We need to bridge our virtual machine to existing network adapter.
Type ifconfig to know its name.
For me it is enp3s0.

So let’s connect VM’s virtual network card nic1 to real network card enp3s0:

$ VBoxManage modifyvm hass --nic1 bridged --bridgeadapter1 enp3s0

3. Download and connect Home Assistant image to our virtual machine

Virtualbox creates a folder in user home directory to store VM files.
/home/user/VirtualBox VMs
and there is a folder with our new created VM:
/home/user/VirtualBox VMs/hass/

We need to download a virtual VDI image from here, unpack and place it in VM’s folder
/home/user/VirtualBox VMs/hass/

Let’s create a sata controller

$ VBoxManage storagectl hass --name "SATA Controller" --add sata --bootable on

And connect our downloaded Home Assistant image to it:

$ VBoxManage storageattach hass --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium /home/user/VirtualBox VMs/hass/hassos_ova-4.12.vdi

4. Run

Now we can run our Home Assistant virtual machine:

$ VBoxManage startvm hass --type headless

If you need to stop it use:

$ VBoxManage controlvm hass poweroff

As we used bridged network, our VM is going to have it’s own IP address. So the easiest way to know it, is to look in your router interface. It would be better to fix its IP by static DHCP in the router.

When VM is running, we can connect to it via browser:

http://your_vm_ip:8123
9 Likes

Thank you for posting a helpful community guide. However, please replace the outdated term hass.io. It’s name was changed to Home Assistant OS months ago and the old term is no longer used in the official documentation. For new users, it’s misleading to see this deprecated terminology.

2 Likes

Thank you so much @ARNik . It work like a charm !

Hi,
another easy way to setup/install and manage virtual machine on headless server is to use:
RemoteBox

1 Like

This is great. Worked for me too.

Only one issue with the instructions which is that when mounting the drive the pathname needs quotes around it to deal with the space.

1 Like

I quickly ran out of space and needed to increase the size of the disk using this command.

VBoxManage modifyhd '/home/<username>/VirtualBox VMs/hass/hassos_ova-4.16.vdi' --resize 81920

Just mentioning it in case anyone else runs into that.

2 Likes

Can anyone help me get HA to start automatically. I followed the guide here which is straightforward and well-documented but HA fails to start. On investigation, I’m able to see this.

[email protected] - VirtualBox VM hass
     Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2020-12-14 21:55:39 GMT; 13min ago
    Process: 719 ExecStart=/usr/bin/VBoxManage startvm hass --type headless (code=exited, status=1/FAILURE)
      Tasks: 0 (limit: 9318)
     Memory: 24.2M
     CGroup: /system.slice/system-vbox_vm_start.slice/[email protected]

Dec 14 21:55:36 nuc VBoxManage[732]: WARNING: The character device /dev/vboxdrv does not exist.
Dec 14 21:55:36 nuc VBoxManage[732]:          Please install the virtualbox-dkms package and the appropriate
Dec 14 21:55:36 nuc VBoxManage[732]:          headers, most likely linux-headers-generic.
Dec 14 21:55:36 nuc VBoxManage[732]:          You will not be able to start VMs until this problem is fixed.
Dec 14 21:55:39 nuc VBoxManage[719]: VBoxManage: error: The virtual machine 'hass' has terminated unexpectedly during startup with exit code 1 (0x1)
Dec 14 21:55:39 nuc VBoxManage[719]: VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
Dec 14 21:55:39 nuc VBoxManage[719]: Waiting for VM "hass" to power on...
Dec 14 21:55:39 nuc systemd[1]: [email protected]: Control process exited, code=exited, status=1/FAILURE
Dec 14 21:55:39 nuc systemd[1]: [email protected]: Failed with result 'exit-code'.
Dec 14 21:55:39 nuc systemd[1]: Failed to start VirtualBox VM hass.

I’ve tried installing and reinstalling the components it suggests but it hasn’t fixed the problem.

Help appreciated!

I did not had to create any extra service to auto start virtual machines on my headless ubuntu server after a correct installation of virtual box and virtual box extension pack.
have a look at the links below:


for autostart:

For remote management you can see my post with RemoteBox up.

Thanks han3bi. I can muddle my way through linux but this proved to be a challenge for me! I ended up having to completely wipe my server and start again. On the fourth attempt, I found a solution that worked for me, so I’ll write it below in case it helps others or my future-self.

I installed Ubuntu 20.04 Server headless and the VirtualBox distribution that is installed using ARNik’s method does not include the autostart scripts. As such, I needed to install a different official version of VirtualBox.

Install Ubuntu

  1. Install Ubuntu from USB stick.

  2. Follow default settings, but include Open SSH when asked.

Install Virtual Box

This section based on Medo’s Guide.

  1. Install VirtualBox from virtualbox.org.
$ sudo wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
$ echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian focal contrib" \
    | sudo tee /etc/apt/sources.list.d/virtualbox.list
$ sudo apt update
$ sudo apt-get install --yes virtualbox-6.1
$ sudo systemctl status vboxdrv
  1. Add the current user to vboxusers.
$ sudo usermod -aG vboxusers $USER

Install VirtualBox Extension Pack

  1. Install Extension Pack from virtualbox.org.
$ VBOXVER=`vboxmanage -v | cut -dr -f1`
$ wget -P /tmp \
https://download.virtualbox.org/virtualbox/$VBOXVER/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVER.vbox-extpack
$ sudo vboxmanage extpack install /tmp/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVER.vbox-extpack

Create a Virtual Machine of Home Assistant

This is based on ARNik’s guide above.

  1. Create a VirtualMachine with name hass.
$ VBoxManage createvm --name hass --ostype Linux_64 --register
  1. Set it’s bios to efi
$ VBoxManage modifyvm hass --firmware efi
  1. Set cpu number and memory
$ VBoxManage modifyvm hass --cpus 2 --memory 2048
  1. Connect VM’s virtual network card nic1 to real network card enp3s0. You network card may be different.
$ VBoxManage modifyvm hass --nic1 bridged --bridgeadapter1 enp3s0
  1. Go to the hass virtual machine folder that’s been created. Change user in the line below.
$ cd '/home/user/VirtualBox VMs/hass'
  1. Get the latest VDI version from this page. This was written in December 2020 so there’s probably a later version to download.
$ sudo wget https://github.com/home-assistant/operating-system/releases/download/5.8/hassos_ova-5.8.vdi.xz
  1. Unpack it.
$ sudo unxz hassos_ova-5.8.vdi.xz
  1. Create a sata controller.
$ VBoxManage storagectl hass --name "SATA Controller" --add sata --bootable on
  1. Connect our downloaded Home Assistant image to it. Change user in the line below.
$ VBoxManage storageattach hass --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium '/home/user/VirtualBox VMs/hass/hassos_ova-5.8.vdi'
  1. Give everyone permission.
$ sudo chmod u+rwx,g+rwx,o+rwx *

Autostart configuration.

Based on Patrick Gaskin’s guide.

  1. Create an autostart configuration file.
$ sudo nano /etc/default/virtualbox
  1. Inside add the following lines.
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg
  1. Close and save.

  2. Create a autostart configuration file.

$ sudo nano /etc/vbox/autostart.cfg
  1. Inside add the following lines. Change default policy to deny to allow people on an individual basis.
default_policy = allow
# Create an entry for each user allowed to use autostart
USERNAME = {
allow = true
}
  1. Close and save.

  2. Make some changes that I don’t understand.

$ sudo chgrp vboxusers /etc/vbox
$ sudo chmod 1775 /etc/vbox
  1. For every allowed USERNAME set in step 20, issue the following. Change USER.
$ sudo usermod -aG vboxusers USER
  1. Log out and in again. If you’re in SSH then just quit.

  2. Set the autostartdbpath.

$ VBoxManage setproperty autostartdbpath /etc/vbox
  1. Set hass to autostart.
$ VBoxManage modifyvm hass --autostart-enabled on

Home Assistant should now run on startup!

To check if Home Assistant is running use this command.

$ vboxmanage list runningvms

To see if the autostart service is running use this command.

$ systemctl status vboxautostart-service
3 Likes

I followed your guide, however when i stopped the VM and tried to start it again, I am getting this error:

VBoxManage: error: The virtual machine 'hass' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

I tried restarting the host machine, doing apt update but nothing seems to work.

EDIT: Nevermind, I forgot to type --type=headless when starting the VM. It works fine now.

1 Like

Thank you, I swear I did this 3 times on my own and have my post about EXACTLY THIS drafted, and now I can save everyone the hassle. Thank you :slight_smile:

Thanks davida72, super helpful and worked great!

Here’s how you enable USB support for Zigbee sticks and Bluetooth etc.

Follow his guide first, then do this:

VBoxManage modifyvm hass --usb on

VBoxManage list usbhost

You’ll get a list of connected USB devices. Take note of the vendorid and productid of the device you want to add, and modify the command below.

VBoxManage usbfilter add 1 --target hass --name CC2652R --vendorid 0x8087 --productid 0x0026

3 Likes

I run HA OS in a VBox vm on Debian 10. Since I’ve installed it (4 months), time or sun-based automations fire late. From a few minutes to an hour. Its as if the VM or the OS goes to sleep, but I don’t see how that is possible. It is running on a re-purposed laptop,
Any idea on what might cause this?

Hello, awesome guide and I know it’s old but I have also been having this issue of time-based automations triggering late and found other forum posts of people reporting the same issue - Here’s a link to the relevant gh issue made for this. I thought I’d post the fix for this issue here since the post still gets attention and comes up on google searches:

The issue comes down to the “paravirtualization” option in VirtualBox. If you followed the guide and set it up via vboxmanage, simply run the following to fix the issue:

$ vboxmanage modifyvm hass --paravirtprovider none

If instead you’re using VirtualBox’s GUI, go to System > Acceleration > Paravirtualization Interface and set it to None. Hope this helps somebody!

2 Likes

Thanks for the update. I moved to VBox on a Windows 10 machine to fix the issue. (I’ve since moved to a HA Blue device, but glad to see it solved.)

I wish I had found this thread earlier! After much thrashing, I found that I had done much which was done here. My difference was that I was not confident with Ubuntu Server 22.04 so I installed Desktop. Installing VirtualBox was easy: sudo apt install virtualbox virtualbox-ext-pack and run it with windows-key virtual enter

I did all the configuration in the GUI.

To autostart it, I created a bash shell script in .config cleverly named autostart.sh. That script has the line vboxmanage startvm homeassistant changed it to executable sudo chmod +x autostart.sh Then using the Startup Application (windowsKey to bring up activities then type Startup Application) added the script to the list of programs that start at boot.

Now I had the advantage of having access to my box, so Desktop worked for me. I do have the overhead of running a GUI, but if I put VNC on it, I no longer need the KVM (keyboard video mouse) and can physically put my server anywhere, like next to my router which obviates WiFi. The computer I used is a refurbished I bought on Amazon for $100 (including 2 year warranty). Intel i5-4590 8GB RAM 500GB HDD This is cheaper than an RPi these days and a lot more horsepower! (though no I/O) Take-away, repurpose those old computers!

OSD

Why complicate things further? Imo it was already a pain in the A to install HA on ressource limited systems such as old notebooks, now they even need to run their own VM!?

Why?..

I don’t even know if my 2007 notebook (Intel® Pentium® T2390) can handle virtualization, but probably not… A shame.

EDIT: Nope, no virtualization.

$ sudo nano /etc/vbox/autostart.cfg

This parts doesn`t work for me . It says that there is no vbox folder. Ubuntu 22.04 lts desktop , last version of VirtualBox.