Skip to content

Instantly share code, notes, and snippets.



Last active Apr 23, 2020
What would you like to do?
Move Home Assistant install to USB

Move Home Assistant install to USB

This document describes the moving of all the Home Assistant data to an USB storage device. Everything in this guide was done on a Raspberry Pi 3B+ with Raspbian. To get things started we want to be sudo for all of this with sudo -s.

This should apply to manual installs only.

This only moves the (Docker) data to the external disk, not the install itself.

Stopping everything

First we want to stop everything to ensure we are working with a non-running system:

systemctl stop hassio-supervisor
systemctl stop hassio-apparmor
docker stop $(docker ps -aq)
systemctl stop docker

Creating and setting up a disk

Than we check which mount we have on our new USB disk with fdisk -l. After that we can setup our new disk with fdisk: fdisk /dev/sda.

Note /dev/sda was my device, but this can vary among systems _fdisk controls: remove with d, create with n, write with w

We will have to create a new hard disk partition to make it writable for Linux:

mkfs.ext4 /dev/sda1
mkdir -p /var/data/usb
mount /dev/sda1 /var/data/usb

I'm chosing /var/data/usb as my easy to remember mount point. Finally we can this disk to fstab to make it mount on boot. First we will have to get the UUID for this disk with the command blkid. This gives us an unique id we can add to fstab with something like this:

UUID=7cce23fd-2a0c-4c3d-a101-a7645afa6e44   /var/data/usb  ext4  defaults  0  2

We can try and dry run this with the following commands:

umount /var/data/usb
mount -fav
mount -a

Moving everything over

When this is working, we move on to the tricky part. Which is copying everything over and restarting everything again. First of all, we start by copying all our data:

mkdir -p /var/data/usb/docker
cp -p -r /var/lib/docker/* /var/data/usb/docker/
cp -p -r /usr/share/hassio /var/data/usb/

After our data is copied over, we can verify the data by browsing these files. When you are satisfied with the result, we will have to move our existing data to another location. We could also already delete everything, but that's not something I would recommend. Moving everything is as easy as:

mv /usr/share/hassio /usr/share/hassio-old-data

After which we can create a symlink from the original data directory to our new data location with:

ln -s /usr/share/hassio /var/data/usb/hassio

You can test this easily with ls /usr/share/hassio/ and everything should be there now.

After we have pointed our Home Assistant data to the new location we will have to point Docker to the new location too. Which can be done by editing the Docker Daemon settings file. It can happen that this file is absent or empty, but not to worry. We will replace it with the following contents:

Normally the Docker daemon settings file is located in /etc/docker/daemon.json, but this can vary by install.

        "dns": ["", ""],
        "data-root": "/var/data/usb/docker/"

Restarting everything

When we are done with this, we can start with our final step, which is starting everything up again. In my install, this was something like this:

systemctl start docker
systemctl start hassio-supervisor
systemctl start hassio-apparmor

# Docker containers can differ per system, but remember to always start with the data
# storage, such as MariaDB or InfluxDB
docker start addon_core_mariadb addon_core_mosquitto addon_a0d7b954_influxdb
docker start homeassistant addon_a0d7b954_grafana addon_core_git_pull

Than we should be done. Testing on disk usage can easily be done with a tool such as nmon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment