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

Tags: #<Tag:0x00007f325ccbea40> #<Tag:0x00007f325ccbe720> #<Tag:0x00007f325ccbe658> #<Tag:0x00007f325ccbe590> #<Tag:0x00007f325ccbe4c8>

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
5 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.

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.

1 Like

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
1 Like

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