Mount USB drive in hassio on raspberry pi

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:

  1. 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?
  2. 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

Install the ssh and web terminal addon.

Add the mount command in init_commands: part of the command.

Hi Nick,
I am attempting to figure out how to expose a USB flash drive that is connected to my RPi4 B.
I want to use the drive to be able to copy my snapshots should the SD card die. With you solution are you saying add it to the init_commands: in the ssh setup? Will this make the usb avail all the time?
New to this part of it. Sorry if this is a dumb question.
Thanks much!
Barak

Hi,
I am looking for the same solution. From the ssh terminal I couldn’t mount the usb drive as described in Configuration Backup to USB drive - Home Assistant 中文网. With “dmesg | grep sd” I couldn’t found my usb drive. The USB drive has a size of 64GB FAT32.

Anybody can help me?

Thanks!

Have the same problem.
Like to use a usb drive with Label “TVH_Record” as simple file path für tvheadend recording.

but in every case the drive will not mount. this drives me crazy.

So now i have an formatted ext4 USB Drive.
I run HA on RPI4 with dowloaded image.

are there instructions, to get access to the filesystem on sub drive?