HAOS in Virtual Box: help with maintenance tasks--DBs, swap, etc

I have HAOS running in a Virtual Box VM. It has 3 CPUs and 5GB of RAM (usually about 2G used). Disk is about 50% full. I’ve seen some swap errors on the console and in my research, it got me thinking about database maintenance as well. This got me down a rabbit hole of confusion.

I do not know Linux well, although I can follow directions.

I found this: How to increase the swap file size on Home Assistant OS

My question for the above post is why would one want to increase the swap size if it’s not necessary, and the script seems to run on startup, wouldn’t that keep increasing swap?

I then found these:

https://community.home-assistant.io/t/how-to-reduce-your-database-size-and-extend-the-life-of-your-sd-card/ (even though I’m not using an SD)

I am confused. I would simply like to ensure that the databases are regularly repacked, integrity checked, and optimized. I would also like to ensure that the swap size is sufficient (don’t even know at this time how to see the size of the swap and DBs and how much is utilized at this time).

I was hoping that there was an add-on or integration that can automate these tasks, but I have found none. I would very much appreciate some clarity and direction.


It will not increase the size as it re-uses the same file name — the default is 2GB in my script and you’re free to change it but 2 is a good number for this. The script also checks if the file/swap exists, etc.

1 Like

@JZhass thank you for responding! My current swap, presuming that it exists, might be corrupted. I’d like to delete the swap and start fresh with your script. How I might go about doing that? Cheers!

Open SSH, type in the following command to free up the file:

swapoff /backup/_swap.swap

Then delete the file with:

rm /backup/_swap.swap

When you restart the machine and the SSH addin logic runs, it will see that file is not there and re-create it.

1 Like

Alternative is if you take out my script from the command/config of that add-in. Then take a reboot, that file will NOT be busy and you can delete it then. Afterwards change config of the addin as you like to bring it back. Restarting the addon should bring it back.

1 Like

@JZhass I first implemented your script from the other thread in SSH & Web Terminal. The add-on restarted, ran the script and created a 2GB swap, which I thought was strange because I thought I already had a swap? In any case, I then used the commands in your above post to stop the swap and delete the file. After a restart, I can see in the log that a new swap was created. Everything looks good! Thank you very much.

Following up, is there a way for me to monitor how much swap is used? I realize that the nature of swap is dynamic and real-time, but I am curious to know if/when HAOS is running out of swap space.

Use Glances addin top mid right for SWAP — or use htop command from commandline.

Please understand that I create ANOTHER/extra swap file because the default on HA OS seems to be too low for some stuff to have breathing room. In fact, I can’t even touch the original one that comes with the OS.

1 Like

That makes more sense–hence “increase swap size”. So the swap that your script creates is an additional swap to the OS swap. Then, in the case where the OS swap is corrupted, is there anything that can be done?

I’ll check out the tools. I read somewhere that Glances has a lot of overhead, so I was staying away.

Many thanks.

Honestly, one of the best steps you can take — because it’s fastest and easiest… is take a backup of HA OS via the UI then format/restore as you please. Restoration of HA is one of the coolest aspects of this software. I can migrate my system in minutes.

1 Like

Great suggestion. I read that everything will get restored, including credentials, Z-wave devices (I believe the keys are stored in the dongle?), cloud accounts, integration configs, etc. etc. and I will not need to change ports or hw config if I am using the same vm on the same host?

In this post, @tom_l wrote that Occasionally the recorder database does not get backed up correctly… Have you encountered this issue?

This should be much less of an issue on HA OS11. See: Home Assistant OS 11: Low-latency scheduler and VM snapshot improvements