Increasing the swapfile size (especially on a USB SSD attached to my test RPi 3B) is pretty typical when trying to get a Linux box to perform and generally be more stable…
After hanging around on this GitHub issue and watching the progress, I believe there’s a simple and repeatable way to increase the swapfile size.
This solution will survive reboots and upgrades. You also never have to actually open the shell itself.
Please keep in mind that this is strictly for HA OS not Raspberry Pi OS aka Raspbian which has plenty of instructions of how to create and manage swap space.
The simple steps:
Have a functional HA OS box
Enable “Advanced Mode” for the user profile in HA (click on the user on the bottom left navigation bar in HA and scroll down). If you don’t do this, you will not be able to see this SSH add-on. See the warning at the very bottom of add-ons which states to enable this when not seeing a full list.
Install an add-on called “SSH & Web Terminal” — this is the UNOFFICIAL add-on. The official one will not work.
Disable Protection Mode for the add-on
Under the Configuration for the add-on, make sure to press the ellipsis (3 dots) on the right of the word “Options” and select “Edit in YAML”
Change the username and password to something NOT simple because it does validate your entry against the “have I been pwned” database.
Also under the Configuration for the add-on in YAML edit mode, replace the init_commands: [] line at the very bottom with the following and start the add-on:
Nice toy @DavidFW1960 — exposed API to docker is pretty cool.
@tom_l the thing I posted is really for “start-up” logic of the add-on and HA. It’s not really made to be a sensor because there’s no real output here (well except an actual file). I guess what you could do is indeed spit out a file to /backup and have HA parse it. If you want to execute something every X then take a look at the Linux “watch” command.
I modified the command in the 1st post to have a bit more logic where it checks if swap is already on with dmesg and if so NOT to repeat the command. Otherwise the SSH add-on fails a restart… So this new update should make bullet-proof. Famous last words
Hi I have tried to put the string in the Addon
This is my configuration:
authorized_keys:XXXXXXXXXX
password: ‘’
server:
tcp_forwarding: false
init_commands: >-
if [ ! -f /backup/_swap.swap ]; then fallocate -l 4G /backup/_swap.swap &&
mkswap /backup/_swap.swap && chmod 0600 /backup/_swap.swap && swapon
/backup/_swap.swap ; elif [[ ! $(dmesg|grep _swap.swap) = swap on ]]; then
swapon /backup/_swap.swap; fi
But when it starts says this:
21-02-25 17:06:01 WARNING (MainThread) [supervisor.addons.options] Unknown options init_commands
Looks like you got it all right. I would open up the shell and run the command htop… On the top left you will swap space and it should be bigger than the 200MB’s that I believe is done by default. Here’s a screenshot of mine:
Wow, great. Made my day after the second host reboot within 3 days due to swap above 80%
Thanks a lot!
Now I can wait until the home assistant blue! is available.
@jzhass Hi, today there was an update for the terminal ssh.
After the restart, I got this protokoll:
[cont-init.d] ssh.sh: exited 0.
[cont-init.d] user.sh: executing...
[08:16:32] NOTICE: Session sharing has been disabled!
swapon: /backup/_swap.swap: Resource busy
[08:16:33] FATAL: Failed executing init command: if [ ! -f /backup/_swap.swap ]; then fallocate -l 2G /backup/_swap.swap && mkswap /backup/_swap.swap && chmod 0600 /backup/_swap.swap && swapon /backup/_swap.swap ; elif [[ ! $(dmesg|grep _swap.swap) = *swap\ on* ]]; then swapon /backup/_swap.swap; fi
[cont-init.d] user.sh: exited 1.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] 99-message.sh: executing...
-----------------------------------------------------------
Oops! Something went wrong.
We are so sorry, but something went terribly wrong when
starting or running this add-on.
Be sure to check the log above, line by line, for hints.
-----------------------------------------------------------
[cont-finish.d] 99-message.sh: exited 0.
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
s6-nuke: fatal: unable to kill: No such process
I deleted the init command, Started successful and added it again.
packages: []
init_commands:
- >-
if [ ! -f /backup/_swap.swap ]; then fallocate -l 2G /backup/_swap.swap &&
mkswap /backup/_swap.swap && chmod 0600 /backup/_swap.swap && swapon
/backup/_swap.swap ; elif [[ ! $(dmesg|grep _swap.swap) = *swap\ on* ]];
then swapon /backup/_swap.swap; fi
My question: will the addon be restarted during a normal HA restart or only when the host is restarted?
In the last case, the init command is only needed for a host restart. Can I let the command in the configuration so that it is used in case of a complete restart?