Setting up Redhat to run Home Assistant

Today I’m going to look at installing Redhat on an Intel NUC and then setting up a virtual machine to run Home Assistant.

You’ll need to attach a keyboard, screen and mouse even if you eventually intend to run the server headless. You’ll also need to connect your NUC to your router with an ethernet cable.

The first thing you need is the Redhat ISO image. To get it, you need to sign up for a Redhat developer account, and then go to the download portal:

Download the binary DVD and then use a tool such as Balena Etcher to burn it onto a USB stick. Select your downloaded ISO file and the destination USB device and then “Flash!”:

Boot the NUC, holding F2 to enter the BIOS settings to check that it’s set to boot from USB.

Redhat has a graphical setup process, and that’s the easiest way to get started:

From the main setup screen, you can get most of the basics configured. The sections that need attention are highlighted, but you can also save yourself some time later by setting the timezone, hostname and network configuration at this stage:

Select “server” rather than “server with GUI” as the base environment, as you won’t need the graphical environment installed:

Make sure you add a user with administrative rights. You don’t need – and probably shouldn’t – set a root password. Your admin user will have sudo access to run commands as root:

I chose to accept the default storage layout for my 512GB drive, which configured the storage with 70GB for the root mount point and 400GB for home. That might seem like a lot for the root, but since it’s the default location for a number of services it doesn’t seem unreasonable. I’ll be using a directory under the /home mount point for my virtual machines.

Once installed, you can connect via SSH and do some essential post-install configuration. The following commands all have to be run as root. Rather than “sudo” each command, I’m quite lazy when I have a lot to do, and generally open a bash shell as root:

[sean@linuxdev ~]$ sudo -i bash

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for sean:
[root@linuxdev ~]#

Firstly, register with Redhat using your developer account credentials – you can do this during the install, but I find it easier to do from an SSH shell. I have a complex password, and it’s much easier to paste it from my password manager into the SSH window than to laboriously type it out when I’m setting up:

[root@linuxdev ~]# subscription-manager register --username=XXXXX--password=XXXXX
Registering to: subscription.rhsm.redhat.com:443/subscription
The system has been registered with ID:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The registered system name is: linuxdev.localdomain

You can then check that your machine is visible in the Redhat portal and add it to your subscription:

Click on the system name, then subscriptions and then “Attach Subscriptions”:

Then, back on your server,  update the list of enabled subscriptions and check that the main repositories are enabled:

[root@linuxdev ~]# subscription-manager repos --list-enabled
+----------------------------------------------------------+
    Available Repositories in /etc/yum.repos.d/redhat.repo
+----------------------------------------------------------+
Repo ID:   rhel-8-for-x86_64-appstream-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os
Enabled:   1

Repo ID:   rhel-8-for-x86_64-baseos-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os
Enabled:   1

You can then run an update to make sure that you’ve got the latest packages:

[root@linuxdev ~]# yum update

Not all updates require a reboot, but it’s good practice. I also think it’s good practice, in general, to reboot after major changes such as adding new services. There’s nothing worse than having to reboot at some later date and finding that a service doesn’t start because you forgot to make it persistent – it’s better to catch that early by testing that everything works after rebooting.

Now that Redhat is installed, you can install the packages required to run virtual machines and enable the virtualisation service:

[root@linuxdev ~]# yum module install virt
[root@linuxdev ~]# yum install virt-install
[root@linuxdev ~]# systemctl enable --now libvirtd

Confirm that your system is good to go:

[root@linux3 ~]# virt-host-validate
  QEMU: Checking for hardware virtualization                                 : PASS
  QEMU: Checking if device /dev/kvm exists                                   : PASS
  QEMU: Checking if device /dev/kvm is accessible                            : PASS
  QEMU: Checking if device /dev/vhost-net exists                             : PASS
  QEMU: Checking if device /dev/net/tun exists                               : PASS
  QEMU: Checking for cgroup 'cpu' controller support                         : PASS
  QEMU: Checking for cgroup 'cpuacct' controller support                     : PASS
  QEMU: Checking for cgroup 'cpuset' controller support                      : PASS
  QEMU: Checking for cgroup 'memory' controller support                      : PASS
  QEMU: Checking for cgroup 'devices' controller support                     : PASS
  QEMU: Checking for cgroup 'blkio' controller support                       : PASS
  QEMU: Checking for device assignment IOMMU support                         : PASS
  QEMU: Checking if IOMMU is enabled by kernel                               : PASS
  QEMU: Checking for secure guest support                                    : WARN (Unknown if this platform has Secure Guest support)

You’ll also need to set up a network bridge to allow your virtual machines to appear on your network.  Identify the network device that currently has the IP address attached – for an intel NUC it should be en01, but other devices may vary:

[root@linuxdev ~]# ifconfig -a
en01: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.99  netmask 255.255.255.0  broadcast 192.168.1.255

Now configure a new network bridge, make it a master for your existing network device, and transfer the IP address configuration to your new bridge:

[root@linuxdev ~]# nmcli connection add type bridge con-name br0 ifname br0
Connection 'br0' (2432fca4-dd62-48ed-aa24-68c444e5c304) successfully added.
[root@linuxdev ~]# nmcli connection modify eno1 master br0
[root@linuxdev ~]# nmcli connection modify br0 ipv4.addresses '192.168.1.99/24'
[root@linuxdev ~]# nmcli connection modify br0 ipv4.gateway '192.168.1.1'
[root@linuxdev ~]# nmcli connection modify br0 ipv4.dns '192.168.1.1'
[root@linuxdev ~]# nmcli connection modify br0 ipv4.method manual
[root@linuxdev ~]# nmcli connection up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

At this point, reboot again to ensure that your network settings take effect. You can do this without rebooting, but while you’ve got the screen and keyboard attached it’s a good idea to check that your network settings are correct. The last thing you want to do is disconnect the screen, keyboard and mouse, and then bring it up to discover that it can’t connect to the network.

Assuming that went well, you’re ready to set up your VM for Home Assistant. I chose to store my virtual machines under /home/vm/<name>, where <name> is the name of the VM – i.e. /home/vm/hass/ for Home Assistant:

[root@linuxdev ~]# mkdir -p /home/vm/hass
[root@linuxdev ~]# cd /home/vm/hass

Download the KVM image and then unzip it:

[root@linuxdev ~]# wget https://github.com/home-assistant/operating-system/releases/download/6.1/haos_ova-6.1.qcow2.xz
[root@linuxdev ~]# unxz haos_ova-6.1.qcow2.xz

Then to run the VM with 4GB of RAM and two virtual CPUs:

[root@linuxdev ~]# virt-install --import --name hassos --memory 4096 --vcpus 2 --cpu host --disk /home/vm/hass/haos_ova-6.1.qcow2,format=qcow2,bus=virtio --network bridge=br0,model=virtio --noautoconsole --boot=uefi

As you can see, there are a number of options you can set here, and I won’t go through them, but these are the ones that worked for me on my NUC.

To see running VMs, you can run:

[root@linuxdev ~]# virsh list

virsh list
 Id   Name     State
------------------------
 1    hassos   running

You’ll also want the VM to start automatically on boot:

[root@linuxdev ~]# virsh autostart hassos

You should then be able to connect to http://homeassisant.local:8123/ where you will see a setup message. Once setup is complete, you’ll see the first onboarding screen where you can create your user:

If you don’t see that screen, try using the IP address instead of “homeassistant.local” – you may need to view your router settings to see the IP address that has been assigned to your VM.

Now you’re ready to explore Home Assistant! Next time I’ll go through some of the basic post-installation steps, including setting up some integrations and building your first automation.

in Home Automation

One Comment

  1. chunkking mann 10th March 2022

Add a Comment

Your email address will not be published. All comments will be reviewed.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts