How to increase the swap file size on Home Assistant OS

Open the terminal window and run htop command… or install adding called Glances. Provide a screenshot from one or both. We will see if the swap file is indeed large.

Here it is

Grab a screenshot of your addin like so and might as well take the Configuration page too:

It seems that the add-on is now running properly however no effect on the swap file it seems.

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
cont-init: info: running /etc/cont-init.d/00-banner.sh
-----------------------------------------------------------
 Add-on: SSH & Web Terminal
 SSH & Web Terminal access to your Home Assistant instance
-----------------------------------------------------------
 Add-on version: 11.0.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 8.2  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2022.7.2
 Home Assistant Supervisor: 2022.07.0
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/01-log-level.sh
cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0
cont-init: info: running /etc/cont-init.d/docker.sh
[10:59:30] INFO: Docker support has been enabled.
cont-init: info: /etc/cont-init.d/docker.sh exited 0
cont-init: info: running /etc/cont-init.d/mosquitto.sh
cont-init: info: /etc/cont-init.d/mosquitto.sh exited 0
cont-init: info: running /etc/cont-init.d/mysql.sh
cont-init: info: /etc/cont-init.d/mysql.sh exited 0
cont-init: info: running /etc/cont-init.d/ssh.sh
cont-init: info: /etc/cont-init.d/ssh.sh exited 0
cont-init: info: running /etc/cont-init.d/user.sh
[10:59:43] NOTICE: Session sharing has been disabled!
cont-init: info: /etc/cont-init.d/user.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun sshd (no readiness notification)
services-up: info: copying legacy longrun ttyd (no readiness notification)
[10:59:44] INFO: Starting the ttyd daemon...
s6-rc: info: service legacy-services successfully started
[10:59:44] INFO: Starting the SSH daemon...
Server listening on 0.0.0.0 port 22.

Server listening on :: port 22.

[2022/07/09 10:59:45:2978] N:  Using foreign event loop...

Check again that you truly don’t have swap enabled. I don’t see errors in your log paste so not sure where you were catching that error.

Lastly try using a simpler config… meaning just take the stock config, change the password to something other than empty and just copy in my init_command line. Meaning just test with that first w/o the ssh key, etc. Here’s mine:

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 ; else swapon /backup/_swap.swap ; fi
packages: []
share_sessions: false
ssh:
  allow_agent_forwarding: false
  allow_remote_port_forwarding: false
  allow_tcp_forwarding: false
  authorized_keys: []
  compatibility_mode: false
  password: sumthngdifficult321@
  sftp: false
  username: admin
zsh: true

Still the same issue

No there is no issue… have you looked under the swap space section of your screenshot? 2.45GB means it worked…

Ah indeed, good job! But how come it’s still so much full? I think it is coming from MotionEye but I have only one camera…

That’s a different issue altogether… turn off different add-ons and pay attention to the usage of swap.

@JZhass I just wanted to say thank you for creating this thread and for your solution to increase swap size in Hassos. I eventually got it right and it seemed to cure a problem that I was having when HA froze up and crashed repeatedly. Seems that it was caused by swap usage at 100%.

Really grateful for your method, keep up the good work! :slightly_smiling_face:

1 Like

Thanks @Fete, much appreciated! Very happy to hear the positive experience with my work.

1 Like

Unfortunately i’m getting this error:

/etc/cont-init.d/user.sh: eval: line 93: syntax error near unexpected token then’
/etc/cont-init.d/user.sh: eval: line 93: 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 ; else swapon /backup/_swap.swap ; fi' [09:56:11] FATAL: Failed executing init command: 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 ; else swapon /backup/_swap.swap ; fi cont-init: info: /etc/cont-init.d/user.sh exited 1 cont-init: warning: some scripts exited nonzero s6-rc: warning: unable to start service legacy-cont-init: command exited 1 /run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information. prog: fatal: stopping the container. s6-rc: info: service fix-attrs: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped

what should I do? :slight_smile:

Take a screenshot of the SSH configuration page…

Can’t even make a start! Normally I’m further in before crying for help.

I’m getting “502: Bad Gateway” as soon as I try to open web UI

Home Assistant Core 2022.6.7
Home Assistant Supervisor 2022.07.0
Home Assistant OS 8.1

Not sure what step you are at… each of those add-ins has a LOG tab that could have good info. Also look at this post which should get you running:

This is the result if you haven’t populated the password field. It needs to be anything except empty

Looks like one of my steps in the OP was ignored… thanks for weighing in @justcop

I have been using the increase swapfile on my RPI3B+ for past year. Was talking with @in2deep over at https://community.home-assistant.io/t/home-assistant-keeps-crashing/443119/9 about the risks to the SSD. I’m happy to put a bit of wear on my SSD ( and continue to use my 3B+) but have you any thoughts on it.

@Spiro, it’s actually really simple… forget HassOS for a sec and ask yourself this: can I use an SSD for Linux? The obvious answer is yes you can… and guess what, you’ll want swap space on it. Same goes for Windows, the page file is used all the time because some OS components are programmed NOT to use RAM and use the page file instead (if available, of course because it can be disabled).

My point is that you should never be afraid to “use” your hardware for its designated purpose. Will it die? Yes eventually but that could be 5 years, 10 years or even 20 years. The key to your dilemma is to have superior backup strategy where losing a drive can be easily recovered. So that’s my take on it :slight_smile:

Use something like Acronis True Image or one I’ve been loving lately DiskGenius to grab a bare metal backup. That’s the way to solve your worry.

3 Likes