TL;DR
This is basically the same guide as Install Home Assistant OS with KVM on Ubuntu headless (CLI only), but for VirtualBox
I was installing Home Assistant OS on an Ubuntu Server (20.04) and documented my steps along the way. I thought I’d share them. Special thanks to @Aephir for their topic, so I could use it as a template for this one.
Installing VirtualBox and deploying Home Assistant OS
Since the install page only describes how to use VirtualBox via a GUI, and I am using VirtualBox in a server setting, I thought I’d share a quick guide to how to do this from CLI only.
NOTE: This is for Ubuntu Server LTS 20.04, but I suspect it will work for many Debian-based systems. Please report both if you have success on other systems, and if not.
NOTE: I know very little about VMs. The reason I made this guide is because I could have used one If there is something wrong, or something that could be done smarter, please let me know!
1 - Preparation
I’ll assume you have your OS installed, and have sudo rights.
First, check that your CPU can run VMs.
egrep -c '(vmx|svm)' /proc/cpuinfo
As long as it doesn’t return 0
, then you’re good. Next, check that it can use KVM acceleration
kvm-ok
1.1 - Install VirtualBox
sudo apt-get -y install virtualbox
2 - Create and configure the VirtualBox VM
These steps basically follow the steps outlined in the installation guide.
2.1 - Create a new VM
VBoxManage createvm --name homeassistant --register
2.2 - Select OS type “Other Linux (64-bit)”
VBoxManage modifyvm homeassistant --ostype Linux_64
2.3 Set RAM and video memory
This command sets the RAM to 6GB (modify to your needs), video memory to 16MB (also modify to your needs)
VBoxManage modifyvm homeassistant --memory 6144 --vram 16
2.4 - Set 2 vCPUs
The minimum amount of vCPUs as described in the installation guide
VBoxManage modifyvm homeassistant --cpus 2
2.5 - Download the latest vdi image and extract it
The current latest version at the time of writing is 7.2. Get the latest link from the installation guide. From here on out, whenever haos_ova-7.2.vdi
is mentioned in a command, replace it with the correct filename (version) of the one you downloaded.
wget https://github.com/home-assistant/operating-system/releases/download/7.2/haos_ova-7.2.vdi.zip
sudo apt-get -y install unzip
unzip haos_ova-7.2.vdi.zip
rm haos_ova-7.2.vdi.zip
2.6 - Resize the harddisk to 100GB
You can skip this step if the default 32GB is enough for you
VBoxManage modifyhd "haos_ova-7.2.vdi" --resize 102400
2.7 Move the vdi image to a location of choice
mv haos_ova-7.2.vdi VirtualBox\ VMs/homeassistant/
2.8 - Add the SATA controller
VBoxManage storagectl homeassistant --name "SATA Controller" --add sata --controller IntelAHCI
2.9 - Attach the vdi image
VBoxManage storageattach homeassistant --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/homeassistant/haos_ova-7.2.vdi
2.10 Create the bridged adapter
Figure out what the name of your network adapter is with the ip a
command
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 34:64:a9:1b:8f:2a brd ff:ff:ff:ff:ff:ff
inet x.x.x.x/x brd x.x.x.x scope global dynamic enp2s0
valid_lft 2177sec preferred_lft 2177sec
[...]
The first one is the loopback, so for me it’s the second one: enp2s0
Replace that with the name of your adapter in the command below to create the bridged adapter
VBoxManage modifyvm homeassistant --nic1 bridged --nictype1 82540EM --bridgeadapter1 enp2s0
2.11 - Enable EFI
VBoxManage modifyvm homeassistant --firmware efi
2.12 - Set Intel HD Audio as Audio controller
VBoxManage modifyvm homeassistant --audiocontroller hda
2.13 - Start Home Assistant headless
VBoxManage startvm homeassistant --type headless
2.14 - Find the IP address of your VM
Theoretically (according to the internet) you should be able to find it by executing
VBoxManage guestproperty enumerate homeassistant "/VirtualBox/GuestInfo/Net/*"
But that didn’t work for me (the IP address was nowhere to be seen in the output. So what I did (a solution I found on the internet… there might be way more efficient ways).
Ping every IP in your current IP range (I assume this updates some info on your system), for me it was
for i in {1..254}; do ping -c 1 192.168.1.$i & done
Find the MAC address of the network card in your VM
VBoxManage showvminfo homeassistant | grep 'MAC:'
This should output something like:
NIC 1: MAC: 08002773348E, Attachment: Bridged Interface 'enp2s0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
So my MAC address is 08002773348E
. Convert that to lowercase and a :
after every two characters, so for me it becomes 08:00:27:73:34:8e
.
Install net-tools
sudo apt-get -y install net-tools
Search for the IP address based on the MAC address
arp -a | grep 08:00:27:73:34:8e
Point your browser to http://[ip-address]:8123
and you can continue the installation guide at the ‘Onboarding’ step.
I hope this helps someone. As I said, I’m not hugely familiar with VMs, but if you run in to any problems feel free to let me know. Also: Improvements to this guide are always w