|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Set up Hass.io on top of a virtual machine" |
| 4 | +description: "A how-to about using Hass.io on x86_64 hardware in a virtualized way." |
| 5 | +date: 2017-11-29 06:00:00 +0000 |
| 6 | +date_formatted: "November 29, 2017" |
| 7 | +author: Fabian Affolter |
| 8 | +author_twitter: fabaff |
| 9 | +comments: true |
| 10 | +categories: How-To |
| 11 | +og_image: /images/blog/2017-11-hassio-virtual/social.png |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +The images for the Raspberry Pi family and the Intel NUC are an easy way to get started with [Hass.io](/hassio/). For a test or if you have a system which is already hosting virtual machines then the [**Hass.io installer**](/hassio/installation/#alternative-install-on-generic-linux-server) is an option to use Hass.io in a virtualized environment. In this guide the host is a Fedora 27 system with [libvirt](https://libvirt.org/) support and the guest will be running Debian 9. Hass.io will be installed on the guest. |
| 16 | + |
| 17 | +<!--more--> |
| 18 | + |
| 19 | +Assuming that you already have setup `libvirtd`. You might need to install `virt-builder` and `virt-viewer` additionally. |
| 20 | + |
| 21 | +```bash |
| 22 | +$ sudo dnf -y install libguestfs-tools-c virt-install virt-viewer |
| 23 | +``` |
| 24 | + |
| 25 | +We will create a virtual machine with Debian 9 and a 10 GB disk image in the QCOW format. Use `$ virt-builder --list` to get an overview about what's operating systems are available if you prefer to use a different system. |
| 26 | + |
| 27 | +```bash |
| 28 | +$ sudo virt-builder debian-9 \ |
| 29 | + --output /var/lib/libvirt/images/hassio.img \ |
| 30 | + --format qcow2 \ |
| 31 | + --size 10G \ |
| 32 | + --root-password password:test123 \ |
| 33 | + --hostname hassio \ |
| 34 | + --firstboot-command "dpkg-reconfigure openssh-server" |
| 35 | +[...] |
| 36 | +[ 147.6] Finishing off |
| 37 | + Output file: /var/lib/libvirt/images/hassio.img |
| 38 | + Output size: 10.0G |
| 39 | + Output format: qcow2 |
| 40 | + Total usable space: 9.3G |
| 41 | + Free space: 8.1G (87%) |
| 42 | +``` |
| 43 | + |
| 44 | +Now, we are making our new virtual machine available for `libvirtd`. If you get an error that the OS is unknown, use `$ osinfo-query os` to get the name to use with `--os-variant`. To access the virtual machine is connected to the bridge `bridge0`. |
| 45 | + |
| 46 | +```bash |
| 47 | +$ sudo virt-install --name hassio --import --ram 1024 \ |
| 48 | + --os-variant debian9 -w bridge=bridge0 \ |
| 49 | + --autostart --disk /var/lib/libvirt/images/hassio.img |
| 50 | +``` |
| 51 | + |
| 52 | +<p class='img'> |
| 53 | + <img src='/images/blog/2017-11-hassio-virtual/virtual-machine-manager.png' /> |
| 54 | + Hass.io virtual machine in Virtual Machine Manager |
| 55 | +</p> |
| 56 | + |
| 57 | +Depending on your preferences you can use the Virtual Machine Manager (`virt-manager`) or `virsh` to manage the created virtual machine. Log in and create an user with `# useradd ha` and set a password with `# passwd ha`. We will need that user to make a SSH connection to the virtual machine. |
| 58 | + |
| 59 | +Log in as `ha` with the given password. If your are using the default network of `libvirtd` then the DHCP range is defined in `/var/lib/libvirt/dnsmasq/default.conf`. In this guide the virtual machine is present at 192.168.0.109. |
| 60 | + |
| 61 | +```bash |
| 62 | +$ ssh ha@192.168.0.109 |
| 63 | +ha@192.168.0.109's password: |
| 64 | +Linux hassio 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) x86_64 |
| 65 | +[...] |
| 66 | +$ |
| 67 | +``` |
| 68 | +
|
| 69 | +Install the requirements after you switch the user to `root`. |
| 70 | +
|
| 71 | +```bash |
| 72 | +$ su |
| 73 | +Password: |
| 74 | +root@hassio:/home/ha# |
| 75 | +root@hassio:/home/ha# apt-get update |
| 76 | +root@hassio:/home/ha# apt-get install bash socat jq curl avahi-daemon \ |
| 77 | + apt-transport-https ca-certificates |
| 78 | +``` |
| 79 | +
|
| 80 | +We want the latest Docker release. This requires additional steps to set it up as unlike other distributions Debian is lacking behind with current packages. |
| 81 | +
|
| 82 | +```bash |
| 83 | +root@hassio:/home/ha# wget https://download.docker.com/linux/debian/gpg |
| 84 | +root@hassio:/home/ha# apt-key add gpg |
| 85 | +OK |
| 86 | +root@hassio:/home/ha# echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee -a /etc/apt/sources.list.d/docker.list |
| 87 | +root@hassio:/home/ha# apt-get update |
| 88 | +``` |
| 89 | +
|
| 90 | +Now, it's possible to install a current release of [Docker](https://www.docker.com/). |
| 91 | + |
| 92 | +```bash |
| 93 | +root@hassio:/home/ha# apt-get -y install docker-ce |
| 94 | +``` |
| 95 | + |
| 96 | +Start `docker` and enable it. |
| 97 | + |
| 98 | +```bash |
| 99 | +root@hassio:/home/ha# systemctl start docker && systemctl enable docker |
| 100 | +``` |
| 101 | + |
| 102 | +An [installation script](https://github.com/home-assistant/hassio-build/tree/master/install#install-hassio) will take care about the setup of all moving parts. |
| 103 | + |
| 104 | +```bash |
| 105 | +root@hassio:/home/ha# curl -sL https://raw.githubusercontent.com/home-assistant/hassio-build/master/install/hassio_install | bash - |
| 106 | +[INFO] Install supervisor docker |
| 107 | +[INFO] Install generic HostControl |
| 108 | +[INFO] Install startup scripts |
| 109 | +[INFO] Init systemd |
| 110 | +Created symlink /etc/systemd/system/multi-user.target.wants/hassio-supervisor.service → /etc/systemd/system/hassio-supervisor.service. |
| 111 | +[INFO] Start services |
| 112 | +``` |
| 113 | + |
| 114 | +If it's done, then there will be two new containers. |
| 115 | +
|
| 116 | +```bash |
| 117 | +root@hassio:/home/ha# docker ps |
| 118 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 119 | +ada5bbfc74f0 homeassistant/qemux86-64-homeassistant "/usr/bin/entry.sh..." 4 minutes ago Up 4 minutes homeassistant |
| 120 | +5954ac452ffc homeassistant/amd64-hassio-supervisor "/usr/bin/entry.sh..." 7 minutes ago Up 7 minutes hassio_supervisor |
| 121 | +``` |
| 122 | +
|
| 123 | +After a connection to the container which is containing Home Assistant is made, you will see the log output. |
| 124 | +
|
| 125 | +```bash |
| 126 | +root@hassio:/home/ha# docker attach --sig-proxy=false ada5bbfc74f0 |
| 127 | +2017-11-28 19:24:30 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sun.sun, old_state=<state sun.sun=below_horizon; next_dawn=2017-11-29T06:17:58+00:00,... |
| 128 | +``` |
| 129 | +
|
| 130 | +For further details about the container, `inspect` can help. |
| 131 | +
|
| 132 | +```bash |
| 133 | +root@hassio:/home/ha# docker inspect bb32b525d1ad |
| 134 | +[...] |
| 135 | + "OnBuild": null, |
| 136 | + "Labels": { |
| 137 | + "io.hass.arch": "amd64", |
| 138 | + "io.hass.machine": "qemux86-64", |
| 139 | + "io.hass.type": "homeassistant", |
| 140 | + "io.hass.version": "0.58.1" |
| 141 | + } |
| 142 | +[...] |
| 143 | +``` |
| 144 | +
|
| 145 | +Hass.io is now ready. The frontend is available at [http://192.168.0.109:8123](http://192.168.0.109:8123). Yes, the IP address is the one of the guest. |
| 146 | +
|
| 147 | +<p class='img'> |
| 148 | + <img src='/images/blog/2017-11-hassio-virtual/hassio.png' /> |
| 149 | + Hass.io overview |
| 150 | +</p> |
| 151 | +
|
| 152 | +Keep in mind that there are limitations with this approach. Not all [add-ons](/addons/) will work and some don't make sense to use as the hardware is not present. E.g., use the [SSH community add-on](https://github.com/hassio-addons/addon-ssh) instead of the default [SSH add-on](/addons/ssh/). |
| 153 | + |
0 commit comments