[Guide] Hass.IO on Windows 10 WSL2 (No more VMs!)

The reason I wanted to do this was for add-on development. I later found the documentation actually provides instructions for running HA in a a VS Code dev container. I ended up going this route, it was easier and allows me to debug the code.

Build an image with the dev container’s Dockerfile then once WSL2 is installed just run the image.

I don’t know what the caveats are of this method but using it within VS code does work great for add-on development :stuck_out_tongue:

Implementation of the WSL2 solution was successful, but Google Cast integration is not working there is no auto-discovery. I guess it is happening because the Hassio not host and it is a subsystem. Any suggestions on how to solve this? I know, that it is possible to integrate devices by IP address, but it would be still good to have auto-discovery somehow. Xiaomi Gateways are also just working for 2 hours, then they stop, but I am not sure if this is the same issue.

I would try to add the google cast ports in the networking script

According to this blog post, Chromecast uses the following ports:

  • TCP 8008 and 8009; and
  • UDP 32768 through 61000.

and maybe 8443 as well

Hey @cerebrate I couldn’t get bridged mode to work.

First off I don’t have Hyper V windows feature turned on so it doesn’t recognise set-vmswitch

when I enabled hype-v and run that command it doesn’t recognise wsl and a vm switch. Assume there is an easy way to find out what the switch is called?

Great work with genie btw!!

Ignore this I got bridged mode up and running. My issue was there was lingering virtualbox network adapter linkage, so I had a nightmare getting rid of that and getting everything reset.

Once sorted I got bridged mode running.

The only issue I have now is on host machine restart/start ups. It doesn’t seem as simple as just running the cmdlet

set-vmswitch -name wsl -NetAdapterName Ethernet

which I added AllowManagementOS to be explicit btw:

set-vmswitch -name wsl -NetAdapterName Ethernet -AllowManagementOS $true

This doesn’t seem to work for me on host start-up, I have to delete this previous set up and manually untick ‘Hyper-V extensible virtual switch’ in the adapter config, so bit of a reset and then all good again.

Just need to make it work without manual interaction. Gonna see if I can script that up maybe, cant figure out exact cmd’s I need yet

But all works, I have set a static IP in the wired.network config and HA all up n running on that with full internet and cast etc working

Great work!

Anyone else seeing recent errors from Supervisor addons to do with attempting to write to/create/access /dev/shm?

I attempted to update NodeRed, VS Code, NginX, Grafana and others, and got variations on the following errors in the logs for all of them. Eventually had to roll-back to a backup to get HA back running.

[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
mkdir: cannot create directory ‘/dev/shm’: File exists
[12:00:21] FATAL: Could not create cache folder
 Add-on: 
mkdir: cannot create directory ‘/dev/shm’: File exists
[12:00:21] FATAL: Could not create cache folder
 
-----------------------------------------------------------
mkdir: cannot create directory ‘/dev/shm’: File exists
[12:00:21] FATAL: Could not create cache folder
...
[cont-finish.d] 99-message.sh: executing... 
-----------------------------------------------------------
                Oops! Something went wrong.

 We are so sorry, but something went terribly wrong when
 starting or running this add-on.
 
 Be sure to check the log above, line by line, for hints.
-----------------------------------------------------------
[cont-finish.d] 99-message.sh: exited 0.
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

From what I’ve seen /dev/shm is a symlink to /run/shm on Ubuntu.
I can see /dev/shm in a terminal, but not /run/shm.

Is there any news to this working with USB devices?

@MongooseMan I have and I fixed it. This, unfortunately, won’t be fixed by the community as WLS2 is not supported. You need to take care of it yourself. Let me know if you want detailed instruction on how to fix it.

@aryankids , thanks, I’d appreciate that.

@MongooseMan The problem resides at this specific IF in a shell script:

       if [[ -d "${directory}" ]]; then
           return "${__BASHIO_EXIT_OK}"
       fi

As you can see the ‘if’ tries to determine whether the ‘directory’ exists or not. However, as you rightly mentioned above on WSL2 (or better said Ubuntu) the /dev/shm is NOT a directory and is a symlink thus the above if fails and causes the issue. Whilst expanding the IF above can fix the issue, as WSL2, and in particular, Ubuntu is not supported by HA, we cannot expect the support team to do that for us hence the commands below.

We need to change that symlink in the filesystem as follows.
N.B. These commands executed on Ubuntu 20.04:

#let’s find out how the directory linked 
cd /dev
ls -la  s*
lrwxrwxrwx 1 root root     8 Feb 10 23:10 /dev/shm -> /run/shm
lrwxrwxrwx 1 root root    15 Feb 10 23:10 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root    15 Feb 10 23:10 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root    15 Feb 10 23:10 /dev/stdout -> /proc/self/fd/1

In our case the /dev/shm is linked to /run/shm
so let’s see what we have got there:

ls -la  /run/shm 

drwxrwxrwt  3 root root  60 Feb 10 23:10 .
drwxr-xr-x 28 root root 920 Feb 13 08:53 ..
drwx------  4 root root 100 Feb 11 15:00 multipath

in my case I have only one directory there (multipath), you might have more, make sure to note them all.

# You need to run these commands as root so be ultra_careful
# rename the symlink 
sudo mv shm shm..hold

#  create a proper directory and give it proper rights
sudo mkdir shm
sudo chmod 777 shm
cd shm

# create the symlink for the directory within the shm (repeat the command for all directors you have noted above in /run/shm (if there are more ))

sudo ln -fs /run/shm/multipath /dev/shm/multipath
sudo ln -fs /run/shm/THE_SECOND_DIRECTORY /dev/shm/THE_SECOND_DIRECTORY

and that would be it. Now the /dev/shm is a proper directory, its integrity within the OS remained the same and should pass the ‘if’ above in that shell script. All your add-ons should upgrade now.

1 Like

Look
At
That
:slight_smile:

Thanks! Worked like a charm

1 Like

Where USB serial on WSL 2 is concerned, it is possible, but only via a moderately bizarre workaround.

You can’t share USB serial devices into WSL as devices currently, since the WSL pseudo-VM doesn’t support that. But what you can do is make use of a rather obscure service called USB/IP, which lets you connect to remote USB devices over an IP network as if they were local USB devices, and you can get IP into and out of WSL, obviously.

The first step is the bit I haven’t done, because I was using a remote Linux machine when I did this - but there’s no technical reason why you couldn’t share a USB device from the Windows host. There’s a Windows USB/IP server and instructions on how to set it up and share a device here:

cezanne/usbip-win: USB/IP for Windows (github.com)

Then you need a WSL 2 kernel that includes the USB/IP driver or loadable modules (for most serial widgets like Zigbee transceivers, those would be “usb_common”, “usbcore”, “usbip_core”, “usbserial”, and “ftdi_sio”. This means compiling yourself a custom kernel, or if you don’t want to do that and don’t care that it also has lots of extra stuff too, you can always grab mine. (Don’t forget that just installing the packages just sets it up in Linux; you’ll still need to copy it somewhere Windows can see it and edit .wslconfig!)

Having done all of that, set up the Windows server, started WSL running with your new kernel, and sudo modprobed in the modules you need, you should be able to install the usbip tools (using your distro’s package manager), and then run:

usbip list -r <server>

where server is the IP address of the Windows host, and get a list of the exported USB devices by bus ID, and then use:

usbip attach -r <server> -b <bus id>

to connect to them.

At which point you should be able to do whatever you wanted the USB device for in the first place!

(And pour yourself a drink. If you got here, you probably deserve it.)

2 Likes

can’t connect to Homkit. anyone knows?
maybe it needs -net=host option when starting docker image… but how i can do it?

  • solved: it was only a low memory problem. Setting 3GB to WSL (changing /.wslconfig) did the trick
    Hi, I was able to install HA in WSL2 and I played with it for some days. Now it seems broken and I got “Unable to connect to Home Assistant.”. No errors on logs (either ha core logs and ha supervisor log). What it seems changed is that previously ifconfig showed some vethXXXXXX: entry, now none.
    dmesg says
[31105.099892] device vethcb6e9a7 entered promiscuous mode
[31105.829342] eth0: renamed from vethc264c92
[31105.829787] IPv6: ADDRCONF(NETDEV_CHANGE): vethcb6e9a7: link becomes ready
[31105.829870] hassio: port 5(vethcb6e9a7) entered blocking state
[31105.829873] hassio: port 5(vethcb6e9a7) entered forwarding state

I tried to clear docker packages and reinstall all. Any idea on how to troubleshoot this? Thanks in advance!

Just a note for anyone trying to use knx virtual with HA.Install HA core on windows (no vm, no wsl) just straight Python. Configure KNX using 127.0.0.1. It works, some knx timeout errors on log is normal. Obviously you cannot use addons, so when you’re done with your testing, go back to HASS.IO.

The link to the translinux script doesn’t work anymore (https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh). Can you update the guide? I’m anxious to get started.

I was able to install Genie using the guides in GitHub. However bash installer.sh gives me an error: missing: network-manager docker jq

Hi MichaH77!

I was wondering what you did to get genie installed from github and if you ever found the resolution for the installer.sh? I’m on the step you must posted.

curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash
bash: line 1: syntax error near unexpected token newline' bash: line 1:

Hey guys,
I’ll be updating this guide in the coming days (hopefully tomorrow) and make sure everything here works properly.

Tested and updated the guide, everything should be working now.

1 Like