How to increase the swap file size on Home Assistant OS

GitHub - TazzerMAN/increase_swap_addon: This add-on increases the swap space on your system initially created for Rasberry Pi. plugin may help, easy way of increasing swap

3 Likes

@deniselenok, you’ll get surprised to discover that add-on was created in this very topic :joy:
Check this post.

2 Likes

does anyone know about limitations of this workaround with newest versions of HA OS and HA Core?
I’m doing some test with a fresh new HA install, I’ve updated everything so HA OS is v13.1 and Core is v2024.9.1

I’ve updated the init command with the last version of the first post, setting a 2 GB swap file, but after RPi restart I still get a mere 200 MB of swap file.
This was instead working properly up until HA OS 7.5.

@Vinz87 I just upgraded and tested the OP line and it worked as expected. Go to the SSH add-on and see what the log says. Feel free to paste it in your response.

I have this configuration:

username: root
password: ""
authorized_keys:
  - >-
    REDACTED
sftp: true
compatibility_mode: false
allow_agent_forwarding: false
allow_remote_port_forwarding: false
allow_tcp_forwarding: false
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 && echo SWAP_NEW_FILE_CREATED_USED ; elif [[ !
    $(dmesg|grep _swap.swap) = *swap\ on* ]] ; then swapon /backup/_swap.swap &&
    echo SWAP_USING_OLD_FILE ; else swapoff /backup/_swap.swap && swapon
    /backup/_swap.swap && echo SWAP_FINAL_ELSE_STATEMENT ; fi

however my swap file dimensions are still ~140 MB

Protection Mode is disabled
This are the versions of my setup:

  • Core 2024.9.1
  • Supervisor 2024.08.0
  • Operating System 13.1
  • Frontend 20240906.0

Am I missing something?

also, where do the debug echo lines are printed?

That’s not the log from the add-on… You’re on the configuration tab but hit the log tab of that add-on.

I would also just wipe this add-on and re-install from scratch. After doing so, test one item at a time like your credentials before moving onto the INIT_COMMAND

I’m seeing this in my logs and are having some issues with my HA restarting, could this be the cause of that?

2024-09-11 10:19:49.947 INFO (SyncWorker_3) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:19:52.359 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:19:57.413 INFO (MainThread) [supervisor.core] Start Home Assistant Core
2024-09-11 10:19:57.561 INFO (SyncWorker_0) [supervisor.docker.manager] Starting homeassistant
2024-09-11 10:19:58.066 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:19:58.103 INFO (SyncWorker_6) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:19:58.601 INFO (MainThread) [supervisor.homeassistant.core] Wait until Home Assistant is ready
2024-09-11 10:20:00.397 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:00.928 INFO (MainThread) [supervisor.auth] Auth request from 'core_mosquitto' for 'mqtt_user'
2024-09-11 10:20:00.934 INFO (MainThread) [supervisor.auth] Home Assistant not running, checking cache
2024-09-11 10:20:02.595 INFO (MainThread) [supervisor.services.modules.mqtt] Set core_mosquitto as service provider for mqtt
2024-09-11 10:20:05.871 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:05.890 INFO (SyncWorker_7) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:07.330 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:11.922 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:11.941 INFO (SyncWorker_4) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:13.503 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:18.149 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:18.169 INFO (SyncWorker_1) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:19.782 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:21.523 INFO (MainThread) [supervisor.resolution.evaluate] Starting system evaluation with state startup
2024-09-11 10:20:21.524 INFO (MainThread) [supervisor.resolution.evaluate] System evaluation complete
2024-09-11 10:20:23.841 INFO (MainThread) [supervisor.homeassistant.api] Updated Home Assistant API token
2024-09-11 10:20:23.869 INFO (MainThread) [supervisor.homeassistant.core] Home Assistant Core state changed to APIState(core_state='NOT_RUNNING', offline_db_migration=False)
2024-09-11 10:20:25.150 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:25.171 INFO (SyncWorker_7) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:26.960 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:31.831 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:31.852 INFO (SyncWorker_2) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:34.060 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:38.950 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:38.970 INFO (SyncWorker_5) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:40.843 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:45.964 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:45.983 INFO (SyncWorker_5) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:47.591 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:20:52.635 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:20:52.657 INFO (SyncWorker_6) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:20:55.386 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:21:00.395 WARNING (MainThread) [supervisor.addons.addon] Watchdog found addon Increase Swap is stopped, restarting...
2024-09-11 10:21:00.415 INFO (SyncWorker_0) [supervisor.docker.manager] Cleaning addon_27a7e4aa_increase_swap_addon application
2024-09-11 10:21:01.692 INFO (MainThread) [supervisor.docker.addon] Starting Docker add-on 27a7e4aa/aarch64-addon-increase_swap_addon with version 1.1.3
2024-09-11 10:21:06.095 ERROR (MainThread) [asyncio] Task exception was never retrieved
future: <Task finished name='Task-2215' coro=<Addon.watchdog_container() done, defined at /usr/src/supervisor/supervisor/addons/addon.py:1429> exception=AddonsJobError('Rate limit exceeded, more than 10 calls in 0:30:00')>
Traceback (most recent call last):
  File "/usr/src/supervisor/supervisor/addons/addon.py", line 1443, in watchdog_container
    await self._restart_after_problem(event.state)
  File "/usr/src/supervisor/supervisor/jobs/decorator.py", line 290, in wrapper
    raise on_condition(
supervisor.exceptions.AddonsJobError: Rate limit exceeded, more than 10 calls in 0:30:00

yes, without init_commands the add-on works as intended, I can access with SSH as expected.

However, in the Supervisor log I get this warning:

2024-09-11 18:37:13.523 INFO (SyncWorker_3) [supervisor.docker.manager] Stopping addon_a0d7b954_ssh application
2024-09-11 18:38:00.743 INFO (SyncWorker_3) [supervisor.docker.manager] Cleaning addon_a0d7b954_ssh application
2024-09-11 18:38:09.218 WARNING (MainThread) [supervisor.addons.options] Unknown option 'init_commands' for Advanced SSH & Web Terminal (a0d7b954_ssh)
2024-09-11 18:38:09.599 WARNING (MainThread) [supervisor.docker.addon] Advanced SSH & Web Terminal running with disabled protected mode!
2024-09-11 18:38:09.603 WARNING (MainThread) [supervisor.addons.options] Unknown option 'init_commands' for Advanced SSH & Web Terminal (a0d7b954_ssh)

The add-on version has been updated to v19.0.0.

And this is the add-on log in which I don’t see anything strange:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service base-addon-banner: starting

-----------------------------------------------------------
 Add-on: Advanced SSH & Web Terminal
 A supercharged SSH & Web Terminal access to your Home Assistant instance
-----------------------------------------------------------
 Add-on version: 19.0.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 13.1  (armv7 / raspberrypi3)
 Home Assistant Core: 2024.9.1
 Home Assistant Supervisor: 2024.08.0
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service init-ssh: starting
s6-rc: info: service init-mysql: starting
s6-rc: info: service init-mosquitto: starting
s6-rc: info: service init-docker: starting
[18:38:49] INFO: Docker support has been enabled.
s6-rc: info: service init-mysql successfully started
s6-rc: info: service init-mosquitto successfully started
s6-rc: info: service init-docker successfully started
[18:38:50] WARNING: 
[18:38:50] WARNING: Logging in with "root" as the username,
[18:38:50] WARNING: is security wise a bad idea!
[18:38:50] WARNING: 
[18:38:50] WARNING: Most attacks against SSH are attempts to login
[18:38:50] WARNING: using the "root" username.
[18:38:50] WARNING: 
[18:38:50] WARNING: 
[18:38:50] WARNING: Logging in with a SSH password is security wise, a bad idea!
[18:38:50] WARNING: Please, consider using a public/private key pair.
[18:38:50] WARNING: What is this? https://kb.iu.edu/d/aews
[18:38:50] WARNING: 
[18:38:51] NOTICE: SFTP access is enabled
s6-rc: info: service init-ssh successfully started
s6-rc: info: service init-user: starting
[18:38:52] NOTICE: Session sharing has been disabled!
s6-rc: info: service init-user successfully started
s6-rc: info: service ttyd: starting
s6-rc: info: service sshd: starting
s6-rc: info: service ttyd successfully started
s6-rc: info: service sshd successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[18:38:52] INFO: Starting the ttyd daemon...
[18:38:52] INFO: Starting the SSH daemon...
Server listening on 0.0.0.0 port 222.
Server listening on :: port 222.

So its the add-on that’s messing with you rather than my command. I would recommend uninstalling it then reinstalling per the instructions in the OP. Ive never seen this issue of init_commands not being respected.

I think I solved installing this other add-on suggested by @deniselenok
I had to retry installing it a couple of times, I think because of not enough free RAM to compile it, but now I have:

  • Increase Swap add-on runs correctly just once at restart, and I see a 2 GB swap file
  • Advanced SSH & Web Terminal add-on runs without init_commands providing SSH access