Migrate your Hass.io from a Raspberry Pi to a Windows Virtual Machine
Today on the hookup I’m going to show you how to migrate your hassio installation from a raspberry pi to a windows virtual machine, and I’ll help you figure out whether it is the right decision for you.
I’ve been running home assistant since October 2017 and so much has changed since I first started. Up until last week I had been running my instance of hass.io on this raspberry pi model 3B, but for a few months I had been questioning whether it’s the best solution.
The raspberry pi is great because it is small, self contained and low power. But in my case I also have an always on computer that runs my plex server, stores all our media files, and handles backups for the rest of the computers in the house. It’s a powerful computer and it basically never reboots and it never turns off, so running hassio on this extra computer is a no brainer.
If you don’t have an always on computer a raspberry pi is a great solution, but if you do I’m going to show you how to migrate your raspberry pi hassio instance to a windows virtual machine relatively painlessly and keep it running reliably.
But before we begin, let me show you some of my favorite parts about running hassio on a virtual machine: Do you hate waiting for your raspberry pi to restart home assistant every time you make a change? Lets time a restart with the virtual machine.
From the time I pressed restart my raspberry pi would take around 2 minutes to come back up, the virtual machine take a fraction of… oh it’s done already? Nice.
My second favorite thing about running home assistant on a virtual machine is that it completely removes the terror that I feel every time I do an update. With a virtual machine you can easily just clone the hard disk, hit update, and if it breaks everything you can either swap back to the hard drive clone and pretend like it never happened, or you can start fixing everything that broke, but instead of having to block out a chunk of time to make sure you can fix it immediately, you can swap back and forth to your working and not working hard disks whenever it’s convenient for you.
If you end up trying out a virtual machine and you don’t like it, you can easily just plug your raspberry pi back in and you’ll be all set, but I’m guessing you’ll want to stick with the virtual machine.
Here we go. For the initial setup I’m going to follow the instructions put together by Mark M for the DrZzs live stream. I’ve posted a link to Mark’s walkthrough document in the description.
Mark M’s Document: https://www.dropbox.com/s/kwb9b3ji01leg96/Installing_HASSOS_on_VirtualBox.pdf?dl=0
First we’ll download and install virtual box and the extensions pack for virtual box. Nothing fancy in this step, just get it installed.
While that’s working it’s also a good time to download the VMDK image for hass.io from the home assistant website. For me, this was the first time I switched to HassOS, I had previously been using the original ResinOS version on my raspberry pi, but I didn’t notice any problems switching between the two OS types.
The other thing you’ll need to do is create a full snapshot of your current Hassio instance. Do this in the hassio menu using the snapshots tab, I’m going to call mine “Transfer”. If this is your first time installing hassio, or you want a fresh start you can skip this part.
Once everything is downloaded and installed you need to open virtual box and select “new”. You’re going to be creating a Linux virtual machine with Ubuntu as the specific distribution, if you have a 64 bit computer, Id suggest using 64 bit Ubuntu. The name is up to you, I’m going to call mine TheHookUpHA, you should avoid spaces in the name of your virtual machine.
On the next screen you can allocate the amount of RAM you want to allow your virtual machine to use. For reference a raspberry pi model 3 has 1 gig of SDRAM. My plex server has 16 gigs of ram, so I’m going to give 2 gigs to this virtual machine. 2 gigs is equal to 2048 megabytes. You can change this value later if you want, so don’t stress about it too much.
Click next and it will ask you about creating a hard disk. For this step you’ll select “use an existing virtual disk file” and then select the VMDK file that you downloaded earlier and click create.
Click OK, but don’t start the VM yet. Instead click “File” -> “Virtual Media Manager”, select the VMDK image and click “Copy”. On the pop up box click “next” then select VDI and click next. On the next screen you can choose between a dynamically allocated file and a fixed size file. Either one is fine, a dynamically allocated file will grow up to a maximum size as you use more space, but a fixed size starts out at the maximum size. I’m going to recommend dynamically allocated since as you saw earlier you’re are going to make copies of this file pretty often whenever you make a major change like an update.
I’m going to call mine “HA_VM”, using underscores instead of spaces, you should avoid spaces in this name also, when you click create nothing is going to happen, that’s fine. Exit the virtual media manager and right click your virtual machine to select settings. Then go to storage and on the SATA controller click the button that says “Add a hard disk”, then click on “choose existing disk” and select the vdi file that you just created and click open. You can then right click on the old VMDK file and select “remove attachment”.
Next, under the system tab you’re going to select “Enable EFI”. The system tab is also where you can change the amount of RAM allocated to the machine and under processor you can select how many CPU cores you want to allow your virtual machine to use, mine is running on an i7, so I’m going to give it 2 cores to make it extra snappy. Last, click on Network and select “bridged adapter” and then select the network adapter of the host PC (which is the computer that your virtual machine is installed on). Under advanced click the dropdown menu for promiscuous mode and select “allow all”.
Click “OK” then head back over to the virtual media manager one last time to change the size of the disk image. I put mine at 32 gigs, which should give me plenty of space for whatever addons I want to add, I wouldn’t go smaller than 16 gigabytes here, and remember that if you chose a dynamically allocated vdi image it won’t actually use the full size on your hard disk until you fill it up. Exit the media manager and now you’re ready to power up your new virtual machine.
Double click on it and you should see a window pop up with lots of system type messages that aren’t really important for you. When you see the messages “Starting version” and “Starting Eudev” that means your new machine is fully booted and ready to setup.
The next step is the scariest part of this whole thing:
You’ll need to disconnect your old home assistant from your network. Before you pull the power, you need to download the full snapshot that you took of your old HA, do this by going to your home assistant web interface and selecting hassio and then snapshots, select the snapshot that you just took and click the download button, put it somewhere you can find easily on your computer and keep in mind the file name won’t be anything recognizable.
If you have the IP address of your raspberry pi reserved via your router you should delete that reservation before unplugging your raspberry pi, some routers will not let to delete reservations for disconnected devices.
You want your new virtual machine to have the same IP address as our old server you don’t have to reconfigure all of your MQTT devices, So after you’ve freed up that ip address you can pull the plug on the raspberry pi and get your new virtual machine setup with a static ip address. To do this, click on the virtual machine window for your new hassio instance and press enter. It will ask you for a login and the default login will be “root”, press enter and it will give you the hassio ascii art, next you’ll type “login” to get access to the host system that runs hass.io.
We’re going to use the nmcli tool to set a static IP, so to do that we’ll type “nmcli con edit “HassOS default””, then type “print ipv4” to see your current configuration. To set a static ip address you’ll type “set ipv4.addresses” followed by the address that you want your virtual machine to have and then /24.
example: set ipv4.addresses 192.168.1.50/24
It’s also a good idea to set the gateway and DNS servers manually when using a static IP. To do this just type “set ipv4.dns” followed by the address of your router and “set ipv4.gateway” also using the ip address of your router. Then type “save” and “quit”.
Then in virtual box right click your virtual machine, select close, and power off. After that completes, double click on the virtual machine to start it back up. It may be helpful to check your router at this point just to make sure that your virtual machine picked up the right address. Navigate to that IP address port 8123 just as you would with any home assistant installation, then go to hass.io and install the samba addon. If you previously had the samba addon setup in home assistant you should use the same login and password that you did before, otherwise windows will get confused and send the wrong credentials. Click start and then wait for the addon to start up, it should be quick. If you click the refresh button in the logs it will tell you when it is running.
From your computer, access your network share, I usually do this by using the run command typing two backslashes and then the ip address of hassio. Navigate to your backups folder and drag the snapshot file that you downloaded from your raspberry pi to that folder.
Then head back over to the home assistant web interface and click hassio and then snapshots. In the upper right corner click on the refresh button, and your snapshot should show up in the available snapshots UI.
Click on that snapshot and then hit “restore selected”.
Depending on how many addons you had installed this could take anywhere from 1 minute to 20 minutes, but it will probably be closer to one. When home assistant comes back up it should be identical to your old home assistant instance, go ahead and test out the important things, click on some light switches, open up node-red, all that good stuff.
The last thing we need to do is setup your virtual machine as a service so it will automatically start whenever the host PC boots up. This means that your home assistant won’t go down for long if windows decides that your pc needs to reboot.
To do this you’ll download and install the VboxVmService. It automatically chooses the folder c:/vms, it’s not a big program, so I’d suggest keeping it the default folder so you can just copy and paste the commands we’re going to use without modification.
After the install finishes, navigate to that vms folder and open the VBoxVMService.ini file with notepad or your text editor of choice. Then under the [Vm0] heading type in the exact name of your virtualbox machine where it says “VmName=”, then under shutdown method I suggest using “acpipowerbutton” to make it easier to do a hard reset on your virtual machine if need be. Delete any unused vm definitions and save that file. Then open the command prompt by typing cmd and type in this command “C:vmsVmServiceControl.exe -i”, if you changed the install directory you’ll need to update the command. If you get an error about the specified service existing you can put in this command “C:vmsVmServiceControl.exe -u” followed by the command from before “C:vmsVmServiceControl.exe -i”. Any time you edit the .ini file you’ll need to run those commands to update the service.
These last two steps are totally optional, but I prefer them on my headless server. The first logs into windows automatically on restart, the service will run even from the login screen, but I have other programs that need to be logged in in order to work. To do this just open up the run command and type in netplwiz and unclick the box that says “users must enter a name and password to use this computer”.
The last optional step is to add the VM service tray icon to be able to easily start and stop your virtual machine. To do this, right click on the VMServiceTray.exe file in the vms folder and select “copy”, then open the run command and type shell:startup to open your startup folder, and then right click and select paste shortcut, now your vms tray icon will load each time you start windows.
If you run into any problems setting this up you please put it in a comment down below, that way we can get it figured out and others who may have the same problem can benefit from it as well.
Thank you to all my patrons over at patreon for your continued support, if you’re interested in supporting my channel like these wonderful people do, check out the links at the bottom of the description.
I won’t have a new video next week because I’ll be at CES in Las Vegas, follow me on twitter for updates about cool new smart home products that I discover while I’m there. If you’ll be at CES and you want to meet up one day, send me an email or hit me up on twitter.
If you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.