After setting up the new VM, it was time to move the controller. There were lots of search results about moving a Unifi controller to a new server but none listed the exact steps. All of them said to move the configuration to the new controller and start it, but little about what that is. One useful bit of information is how the devices know how to connect to the new server. Someone reported that the devices have the current (first?) controller’s IP in their configuration along with a backup of connecting to “unifi”. The router I am using supports dynamic host names so setting the new controller to have the hostname of “unifi” would automatically register that with the local resolver.

I logged into the old controller and queried the unifi package to get a list of all of its files, hoping to find the configuration files to move. Nothing popped up so I checked a couple of common locations. First was /etc and there was no /etc/unifi. Searching for *unifi* in /etc also turned up nothing except startup files. Next was /var/lib and there was a /var/lib/unifi. I have two devices and there were two devices in /var/lib/unifi/devices, each with their own system.cfg file. Perfect, it looks like this was it. With no /var/lib in the package files list, I hoped I could simply copy everything over to the new controller. One concern was that it would be moving from ARMv7 to x86_64. The config files are in plain text but there were some database looking remnants in the /var/lib/unifi/db directory.

The other, bigger concern was MongoDB. The unifi package has a dependency on MongoDB but when dumping the database, it was empty. Furthermore, there was a log file named mongodb.log and it had a lot of activity logged. The controller was using MongoDB but no data was persisted. I opted to skip copying anything from MongoDB over and hope for the best.

The move. If everything else works, this is the process.

  1. Installed unifi on the new controller first.
  2. Stopped unifi.service on the old controller.
  3. Created a tarball of /var/lib/unifi, moved it to the new controller, and extracted it.
  4. Started unifi.service on the new controller.
  5. Opened http://unifi:8443 and got a connection failed error.

Back to debugging. I checked unifi.service and systemd said it was running. I checked open ports and only ssh had anything open. I tried restarting unifi.service to no avail. It dawned on me to check MongoDB and it did not start because there wasn’t enough space on /. It needed 3.7 GB free but there was only 2.4 GB available. MongoDB required a higher minimum though, unless you gave it a specific option to change it. I had set the VM to have a 4 GB disk size because I knew it didn’t need much; there was only ~2.5 GB used on the previous host. Ugh, I needed to resize the VM. The VM host however didn’t have qemu-img available plus it wasn’t running Linux. I compressed the raw, sent it back to my (Linux) laptop, de-compressed, resized, re-compressed, and sent it back. Booted the VM again, failed to start MongoDB, remembered to actually resize /, and then successfully started it. Restarted Unifi, opened it in the browser again, and this time success. I was able to log in and already both devices had registered.