I have Home Assistant running on my raspberry pi as hassio (first option in [Raspberry Pi - Home Assistant (home-assistant.io)] (Raspberry Pi - Home Assistant). However I read a lot of articles that it is a bad idea to keep your database on the SD card (and indeed, I already killed one). So I would like to move the database to an USB disk, plugged in in my raspberry pi. But I don’t manage to mount this USB disk to put the database there. This is how far I got:
I understand that the hassio setup is a complete docker configuration with mainly a container running home assistant and a container running supervisor. Add-on’s will create more containers. Underneath all this, there is a minimal operating system which you can reach by doing ‘login’ from the ssh add-on or from the console. The containers are visible by doing: docker ps in the underlying os.
I understand that everything running in the docker container is somewhat virtualized and has no direct access to the hardware of the underlying OS. As an example, the /config directory in home assistant is actually the folder /mnt/data/supervisor/homeassistant that is passed to the container as seen in the config file: /var/lib/docker/containers/[ha container_id]/hostconfig.json.
Wouldn’t it be nice if we could access an USB drive in the underlying OS, mount it as a file system and present that file system to the home assistant container, in the same way as how /config is presented to the container. Is this possible?
It would require 2 things, but I am struggling with this. Please help me understand:
- It would require the hostconfig.json file to be modified. However I don’t think it is a good idea to modify this file, as it is part of the standard setup of hassio. So I would go for an alternative. I could also mount my usb file system on e.g./mnt/data/supervisor/share/mymountpoint and see it as /share/mymountpoint in home assistant (because /share is also passed on to the container via the hostconfig.json file). After this, I could move my database to /share/mymountpoint and it would be on the USB disk. Good idea or not?
- But my main problem is mounting a file system in the underlying OS. After I start my raspberry pi and I go to the underlying OS I see my USB disk and I can format it via fdisk /dev/sda and create a file system. So far so good, but now I want to have this mounted at boot time. Normally you do that by adding an entry to /etc/fstab, mount /dev/sda1 to /mnt/data/supervisor/share/mymountpoint (or use UUID for device persistency). The problem is that /etc/fstab is a part of the root (/) file system and it is /dev/root which is mounted on / . But I see that in my case, Size is 98.8M, Used is 98.8M and Available is 0. Next to this, it is mounted read only. So modifying /etc/fstab doesn’t work on this read only file system. I see a lot of other mountpoints, for files that need to be writable (like /etc/hosts, /etc/udev/rules.d, etc). So it looks to me that it is intentional to make /etc/fstab read only. All the things that are allowed to be writable, have their own mountpoint.
So is it a bad idea to mount an USB drive like this?
What would be the way to have it mounted at boot time?
Or what is the correct way to have your database on an USB disk?
Note that I know you have more possibilities by installing Home Assistant in another way (like home assistant container). But they developed hassio as a simple, out of the box, solution and the recommended way to install Home Assistant on raspberry pi, so I would like to keep using that.
So who can answer my questions above?
Thanks a lot
Geert