I’m trying to install and set up HA for the first time. I have just followed the procedure at Raspberry Pi - Home Assistant to install HA for the first time on a Raspberry Pi 4B (2Gb memory, 16Gb SD card). The HA OS version is 9.5, and the HA core is 2023.3.2.
Files I add or change are lost when I reboot. Although others have asked a similar question, I’m not finding a definitive solution so I hope it’s OK to ask again.
As a simple test I created a file in /root called “example”. The file is definitely there:
[core-ssh ~]$ ls -lL
total 24
drwxr-xr-x 2 root root 4096 Mar 9 14:32 addons
drwxr-xr-x 2 root root 4096 Mar 9 14:32 backup
drwxr-xr-x 7 root root 4096 Mar 9 18:46 config
-rw-r--r-- 1 root root 5 Mar 9 19:00 example
drwxr-xr-x 2 root root 4096 Mar 9 14:32 share
drwxr-xr-x 2 root root 4096 Mar 9 14:32 ssl
[core-ssh ~]$ cat example
abcd
If I now reboot with “reboot” or using Developer Tools/Restart the file has disappeared on logging in again.
I see that others have complained of a similar problem, and that a faulty SD card has been suggested. This is highly unlikely as: (1) I have just written a new card with a large OS; (2) other system changes such as to its hostname persist across boots; (3) installing the Terminal & SSH add-on persists across reboots.
I also see suggestions that this may be because a lot of things are being held in containers. If so, it would be helpful if there were instructions somewhere on how to work around this.
I strongly suspect that some component is recreating a lot of critical files/directories. For example, links in /root and various system files in /etc have been recreated at boot time:
[core-ssh ~]$ ls -lt /root
total 0
lrwxrwxrwx 1 root root 7 Mar 9 19:17 addons -> /addons
lrwxrwxrwx 1 root root 7 Mar 9 19:17 backup -> /backup
lrwxrwxrwx 1 root root 7 Mar 9 19:17 config -> /config
lrwxrwxrwx 1 root root 6 Mar 9 19:17 share -> /share
lrwxrwxrwx 1 root root 4 Mar 9 19:17 ssl -> /ssl
[core-ssh ~]$ ls -lt /etc
total 264
-rw-r--r-- 1 root root 1229 Mar 9 19:17 passwd
-rw-r----- 1 root shadow 564 Mar 9 19:17 shadow
drwxr-xr-x 1 root root 4096 Mar 9 19:17 profile.d
drwxr-xr-x 1 root root 4096 Mar 9 19:17 ssh
-rw-r--r-- 1 root root 59 Mar 9 19:17 resolv.conf
-rw-r--r-- 1 root root 9 Mar 9 19:17 hostname
-rw-r--r-- 1 root root 236 Mar 9 19:17 hosts
lrwxrwxrwx 1 root root 12 Mar 9 19:17 mtab -> /proc/mounts
-rw-r--r-- 1 root root 206 Mar 9 14:32 asound.conf
...
There are strange mounts, e.g. /dev/mmcblk0p8 is mounted all over the place.
Any idea what’s going on? Thanks!
All add-ons are docker containers, including the ssh one. So when you installed the ssh addon and ssh’ed in you’re in a docker container. HA itself runs in a completely separate docker container, as does supervisor and every other addon.
The reason your file is lost is because nothing on the host system is mounted to /root
. Therefore it is transient. Every time you restart an addon the container is stopped and removed and then remade from the image. So the only files you can create which survive restart are the ones where a folder on the host is mounted to:
- /addons
- /backups
- /config
- /media
- /share
- /ssl
Those are also the only places you can put files which HA can see. The /root folder you see while ssh’ed is only visible to the ssh addon. Any files you put in there are only visible to you while you are ssh’ed until that addon restarts. There is an entirely different /root folder in the HA container that you cannot see while ssh’ed
4 Likes
Many thanks for the helpful clarification.
That’s unfortunately quite a limitation. For example, I would normally expect to create ~/.bashrc to provide useful aliases. I can do this, but it won’t survive a reboot. It also means I can’t permanently add a non-root user so I can use the system remotely at minimal risk of disturbing things.
Presumably there is no way round this or you would have said.
The ssh addon in the community addon store (as opposed to the one you’re using from the official add-ons store) can handle this. It has an option to run a script when the addon starts. What I do is I have a custom .zshrc
file in /share
and my init script copies it from there to /root/.zshrc
every time the addon starts.
Community ssh addon handles this too. It’s actually the default to use a non-root user, you have to explicitly change it to root.
Although there are some limitations if you do this, namely that scp
doesn’t work for pulling/pushing files to/from HA. That was the one I ran into, not sure what others exist.
Again, many thanks for the helpful suggestions. I accidentally discovered that I can store files like .bashrc permanently in /data. I’m now reading this in /data/.bash_profile to get what I need on logon.
I’ll investigate the community add-on for ssh. At first sight, it looks quite comprehensive. Since there doesn’t seem to be any sudo, I’d presumed that a non-root user couldn’t become a root user - at least, during a login session.
Given that ssh runs in a transient docker container, I’m wondering about the value of ssh anyway (though the community version looks fairly capable). I’m just so accustomed to doing this kind of thing with a “standard” Linux installation in order to control it…
Main purpose of the ssh addon is to enable usage of the HA CLI. Which either does. You can also use it to modify the configuration files in vim, nano or the editor of your choice. I do that sometimes but I prefer using studio code server for that. Besides that I use it for a variety of miscellaneous tasks:
- Getting files to and from HA via scp (prefer that over samba addon personally)
- Poking around in
.storage
when necessary, often using jq
to find stuff in those giant json files
- Generating my custom caddy binary for the caddy 2 addon. And my json config from its yaml form
- Testing DNS as HA sees it. Or other network things as HA sees them
Idk hard to describe. I use it a lot. The community ssh addon more so then the official one since it also has access to the docker CLI. I use that a fair amount to debug stuff and fix things when there are issues.
You can set up ssh access to the host if you want but its kind of pointless. HA OS is an appliance install, the intent is for you to manage the system entirely via HA and its CLI. As such the actual host OS is extremely locked down. It has an extremely barebones set of packages and services installed (basically exactly what it needs to run), there is no package manager available for installing things you might want and most of the filesystem is read-only. The only parts not read-only are the parts which are mounted into HA containers, which you could already modify from the SSH addon.
The only reason I have host SSH setup is to use journalctl
. Since all logs go to the system journal so you can see logs there from much further back. Although even this use case is basically legacy now since ha host logs
uses the systemd-journal-gatewayd service and has filtering options to get to whatever logs you want from whatever time range you want.