-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can i increase my swap file size? #968
Comments
Currently Home Assistant OS does not really support that use case. This is also taking a strain on your SD card as swap usually generates quite a bit of read and writes. Since we already have users which have problems with SD cards wearing out, in a lot of cases using swap on SD card does not make sense. By default HAOS configures a part of the RAM as compressed swap storage (using zram). This helps quite a bit for boards with low memory. That said, when you access HAOS directly (via SSH port 22222), you can create a swapfile and enable it as swap, but the swap will not be automatically re-enabled after a reboot:
|
hi, |
Do yourself a favor and switch over to an RPi4 with more than 1GB of RAM. You will only waste time with you trials on 1GB. The difference that more RAM makes is overwhelming. |
Yes i know, unfortunatly my z-stick gen5 is not compatible with rpi4 and i'm lazzy to rebuild all my zwave mesh (qubinos wire pilote on the wall behind heaters) |
Better yet, grab an ODROID N2 or N2+ |
Home assistant says on the getting started website that 1GB ram should work... And it would work if my swap file could be bigger. However there is no way to permanently change this, only the commands from @agners are a manual solution for now? |
@agners that standard solution doesn't seem to work... see the error which suggests that BusyBox and not the full version of swapon is what HassOS seems to be using. Error you get is invalid argument for swapon. FYI, swapon -a ran fine but did not use the newly created swap file either. With my SSD plugged into the RPI3B+, it'd be nice to be able to control the default swap behavior in HassOS. |
This works like a treat! On my ssd that should be perfect to prevent filling up the ram completely. Any idea on how to make this persistent? |
I do understand what @agners say and I do agree that if you use an SD card increasing the swap is not great but if you use an SSD then shouldn't be a problem. Since few months ago my pi3b+ is getting very slow and HA ends up not responding. Restart fixes it and then after 1 week or so again the same thing. I’m running an SSD with my pi so raising the swap size could reduce or even solve some of these issues. The default setting is just 25% of the real device memory (in this case 256Mb) and I think that it is probably having in SDcards in mind (and not SSD) I’ve managed to change it using the commands below and so far so good… the problem is that this is not persistent (and after restart goes back to original swap size). As far as I understood I would need to change the /usr/libexec/hassos-zram or /usr/lib/systemd/system/zram-swap.service but the filesystem is read-only. Is there any other way to do this?
|
Just a quick update to mention that increasing the swap size is working well so far. Now the RAM is stable 65% - 70% and the swap is between 30% - 35% so not that much from the forced 25% (the problem is that this configuration is lost when restarted) |
I got the exact same problem. It would be great to edit somenthing on hassio config file prior to boot to set up as SSD. |
I found a way to make this "persistant" using the SSH & Web Terminal Addon. When disabling protection mode for the addon you can simply place the swape file inside the Core folders (for example "/config" oder "/config/www") and issue the swapon command as initial command of the addon. The swapfile itself and the permissions survive the restarts. ##### Edit: Confirmed working solution:
Edit: Original post (not optimal, due to increased snapshot size (as described in the next post ))
|
@capstan1 it makes doing HA backups a pain... now there's a huge file rather than a few megs. Can the file reside in any other location outside of HA config folder? |
HI to all! |
@Bellavista notice that your init_command is not using the same file/location as you have on the swapon command. We seem to be getting lucky with how swap files are considered/packed by TAR. Notice that 1GB is down to 1MB when compressed: Seems like that 1MB of backup space is indeed a small price to pay for larger swap. However, after looking at init_commands, it made me wonder why not use that to run all of the necessary commands. Something worth trying... thanks for the more detailed steps, the INIT_COMMANDS piece was key for me. |
Hi, I changed the location to the
Surely, you could put all commands inside the init_commands. But as the swapfile itself is persistent throughout restarts, it's just not necessary. Don't know if it adds a lot of workload to a restart, though. Only advantage I can see: it's also executed after restoring a snapshot on a fresh install. So you won't need to SSH into the host once after restoring. |
@capstan1 and @Bellavista I'm so glad you both posted. It all led me to the final ONE-LINER resolution :) which is ultimately the best and most maintainable approach. Basically use the INIT_COMMANDS to run an if statement in the shell and you never really need to visit that shell yourself to make this work. It survives reboots and doesn't make my backups larger because I simply store it in the /backup folder anyway like suggested. It has a bit logic which will re-create the file if it's not there already, etc. BTW @capstan1 that makes perfect sense... swap file will be all zeros until it's actually used. Now that the uptime is longer it is indeed impacting the backup size like I initially suspected. Thanks again to you both! Here's the one-line solution which belongs on the Configuration page of the SSH & Web Terminal add-on in HA.
|
I am not sure why we have to act as an underground/resistance movement but You did it well;) Thank You. |
Great job from everyone. I am one of those users who knows little ... indeed nothing ... about programming and linux or yamal commands, I only have a scholastic knowledge ... (but I'm not young ... ;-) internet has been a turn fatal! Well! |
Please see the on-going thread here: https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226 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. Pasting it one last time here and will continue with the community post:
|
Thank you guys, it helped me a lot. I've a raspberry pi 3b and HASSIO was unstable and unavailable almost one time per day ... |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I can't understand it. PS |
I get the output |
Hi fellow HA users,
|
A lot of questions. Let me try to answer a few.
No comment on 3 and 5. |
Thanks bkbartk, |
Terminal & SSH Configuration Options were set as follows:
After a server reboot checked for swap space - no material change. Checked backup directory and no file _swap.swap Checked Supervisor log and found schema issue with init_commands and protection mode: Any thoughts gratefully received. |
I wish this thread/bug could be closed because the solution/links in previous posts keeps getting further and further buried. Please do NOT use protected_mode as an entry in the config of the SSH addon. It's a checkmark/slider on the Add-on and you should see it on the Info page of most add-ons. It's not allowed as a YAML entry AFAIK. Screenshot below along with a link that should be used as your source (I've updated the command since the last post here) of the command/script and instructions. I hope people stop continuing to comment and pose questions here and instead go to the HA community to post linked below. https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226 |
Protection mode: disable shouldn’t be Parton the init command. It should only be set with the toggle. `init_commands:
|
Thanks bkbartk and JZ-SmartThings for the info,
Apologies for following an out of date link but I didn’t know the newer link existed. I haven’t got the protection mode switch in the INFO tab of any of the installed addons. I must have missed something so I will remove the protection mode disable from the init command, look more closely at the replacement instructions link, and follow the instructions as closely as I can.
Can I get back to you by email if I hit snags that stop me? This RAM memory problem a key system stability issue for me as I may get a day or so operation but gradually the memory map fills up and eventually the system fails and can only be salvaged by a cold host boot.
BTW, short term I am trying to create the swap file in ../backup folder on the installed 128GB SD card. Later, to save the SD card I plan to shift the swap file, tar backups, etc to a portable disk as soon as I get time to read up how and go through the shift.
Thanks for your help,
Phil.
… On 2 Jan 2022, at 20:56, bkbartk ***@***.***> wrote:
Protection mode: disable shouldn’t be Parton the init command. It should only be set with the toggle.
`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
packages: []
share_sessions: false
ssh:
allow_agent_forwarding: false
allow_remote_port_forwarding: false
allow_tcp_forwarding: false
authorized_keys: [] …..`
—
Reply to this email directly, view it on GitHub <#968 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJSK5PPU27JR6XFAGBFH7ALUUAOM3ANCNFSM4TNVWLUA>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.
|
@PandJoKell please go to the link below and follow the instructions to a tee... specifically the name of the add-on that you're installing --- bullet 3. You want the unofficial SSH & Web Terminal not what you're trying to use: https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226 |
Got it thanks JZ-SmarthThings. Before yesterday I was using the wrong SSH now using the community one and with success. I’m also posting on the new thread.
Cheers.
… On 5 Jan 2022, at 13:24, JZ-SmartThings ***@***.***> wrote:
@PandJoKell <https://github.com/PandJoKell> please go to the link below and follow the instructions to a tee... specifically the name of the add-on that you're installing --- bullet 3. You want the unofficial SSH & Web Terminal not what you're trying to use:
https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226 <https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226>
—
Reply to this email directly, view it on GitHub <#968 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJSK5PM5H5KSUHWP4HQHADLUUOTWHANCNFSM4TNVWLUA>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.
|
Got it thanks bkbartk. Till yesterday I was using the wrong SSH but now using the community add-on with success. Also I’m posting on the new thread.
Cheers.
… On 6 Jan 2022, at 02:38, bkbartk ***@***.***> wrote:
<https://user-images.githubusercontent.com/17070805/148244745-d2d3930c-bd1d-498d-b265-e8bf90e53894.png>
you need the one in the green square,
not the other one, You can use both together, but for increasing the swap file you need the community add-on.
<https://user-images.githubusercontent.com/17070805/148245057-78c95d7a-0461-49f6-8c21-354a4e56c0c6.png>
there you will find the toggle in the red square.
—
Reply to this email directly, view it on GitHub <#968 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJSK5PNSXMIOQ256RE5BF7DUURQWBANCNFSM4TNVWLUA>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.
|
@Biont thanks for sharing this. I did something similar. For now, I am using a RPI 4 with 1GB of RAM (8GB versions are hard to get currently) and a 240 GB SSD. Here is what I did:
|
So you are telling the mkswap command stays persistent if referencing a whole partition? The swapsize, location and swappiness definitely need to be editable by the user via homeassistant-GUI and get persistent. |
Hi Folks,
I am interested in this latest development from @Biont and Sergej Sawazki but haven’t looked into the details or tried it out yet. I’ve been using the community SSH & Terminal addon approach for a year or so and only trouble I’ve had was when I upgraded the addon, loosing the swap file configuration. But once I got the config back and reinstated it everything has worked since then.
I use HassOS with an RPi 3B+ and a 2GB swap file on a 64GB SSD. My HA has been very stable and the UI much faster, although lots of trend graphs slow it down a bit with some taking up to a minute at times. An occasional restart seems to clear things out if it gets slow.
I’m sure that I would have had to upgrade my RPi to an RPi 4B+ with 4GB RAM had this community addon method not been devised. It’s been a saviour for my HA.
I plan to look into the new method and try it out soon on my dev system that uses an RPi 3B. Till then thanks for including me in the email thread.
Cheers,
Phil K.
…Sent from my iPad
On 18 Oct 2022, at 08:32, Sergej Sawazki ***@***.***> wrote:
This is all very nice, but I would still prefer a native solution that does not require us to install an unofficial addon. Looking through the documentation, it turns out that this OS isn't completely read-only. We can define network configs, kernel modules and more importantly, udev rules! And all those are persistent!
@Biont thanks for sharing this. I did something similar.
For now, I am using a RPI 4 with 1GB of RAM (8GB versions are hard to get currently) and a 240 GB SSD.
I decided to spend 16 GB for a SWAP partition (maybe thats too much, but I have plenty of disk space).
Here is what I did:
Resized the hassos-data partition to make space for a SWAP partition. Created the SWAP partition as partition number 9 at the end of the disk.
Lessens learned: don't use parted for that (HA will not boot), use fdisk instead.
In order to get ssh access to port 22222(!), created directory CONFIG inside the hassos-boot partition and copied my public key to file authorized_keys in this directory.
Launched HA and logged in to port 22222.
Ran mkswap /dev/sda9.
Rebooted, I checked that it actually worked:
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
@ce3a thank you, I tried it your way and it worked all fine on Raspberry Pi 3B+ v1.3. Here is my approach step by step. I also upgraded the SD card to a larger one in the process. You will need either a larger SD card with a USB reader or a USB drive (sized at least as the SD card you're using).
Hope this helps! |
Thanks for the idea of using udev for this!
Adding the label to the swap partition on my external drive worked perfectly in combination with this rule. |
Hi, did anyone succeed in using the swap command with the latest version 12.1.2 of the SSH & Terminal add-on? |
Hi, this is the first time I try increasing swap, and addon version is 12.1.2 and does not work. |
It doesn't work with the 12.1.3 version of the plugin. Please make it a part of the Native Home Assistant OS settings. WTH? 😜 |
actually it worked for me after updating to v12.1.3 |
I haven't had a chance to try it out yet. Hope to do so in next couple of weeks and report back then.
Cheers,
Phil.
… On 28 Nov 2022, at 13:50, Vinz ***@***.***> wrote:
actually it worked for me after updating to v12.1.3
—
Reply to this email directly, view it on GitHub <#968 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJSK5PMKVH5DOEN6SGSLITLWKUSI5ANCNFSM4TNVWLUA>.
You are receiving this because you were mentioned.
|
Here is how I did it, and since I failed for a few times I want to share my learnings. My setup is a Raspberry Pi Zero 2W with HassOS 8.5 (#2220). I wanted to add a 1G Swap Partition after resizing 'hassos-data'. Partition layout after resize of 'hassos-data' + adding a 1G Swap Partition: I did the resize and re-partitioning on my Desktop with a card reader. Wanting to know why fdisk works and parted not, I searched for an explanation. tl;dr Click me for details before and after resizeBefore resize
After resize
Click me for details how to fix itRecreate hybrid MBR using gdisk
With all that said, creating the swap partition was all I did, it was recognized automatically.
Please also note that this is just an experiment, for a robust and long running system you might want to adjust the swap priority. |
@jlunz that looks like so much work and who knows what will happen when you update the core or the OS --- meaning are you going to have to go through this gyration again? Seems like way too much work when compared to my little technique, which just works and puts this swap need behind you. Try this: https://community.home-assistant.io/t/how-to-increase-the-swap-file-size-on-home-assistant-os/272226 |
@JZ-SmartThings Absolutely, I wouldn't recommend it to someone who is interested in a stable and long-term working system. |
@jlunz definitely and very interesting actually. I just wouldn't do it due to complexity and unknown future up-keep :) kinda sad that we don't have this at the HASS OS level. More importantly, the default swap allocation is way too small for real-world use. |
Hi HAOS Swapfile fans, Have been tardy in not trying the more permanent fix Swap file issue solution by @Biont's posting on 14 Oct 2021, mainly because of unfamiliarity with Linux udev for managing partitions. My HA system (HAOS installed version 9.5) runs on a RPI 3B+ with a 32GB SD card for system and data storage. I haven't tried mounting a USB SSD per @Biont's posting which has the side benefit of creating a new data partition labelled "hassos-data" during the migration procedure. Pending a better understanding of udev I've been trying to re-create the swap area on HAOS startup per JZSmartthings posts over the last couple of years. It uses the community SSH & Web Terminal addon with an init_commands script to allocate a 2GB swap file in the Backup folder on startup. I couldn't get the community SSH & Web Terminal addon to save the script (both UI mode and YAML mode) and got an error message: I then tried running the individual commands via ssh checking the proper file creation occurred. The following are the command lines and return message: Then 'chmod /backup//_swap.swap' I then tried to add the init_command 'swapon /backup/_swap.swap' to the community addon but got the error: The init_commands script worked without hitch a year or so ago but not now. So this post is to enquire if I may have done something wrong or maybe later versions of the Home Assistant Community Add-on: SSH & Web Terminal (version is 13.0.2) don't allow the swap script to be inserted? Have other HA swapfile fans had issues with the init_commands in the Community addon SSH & Web Terminal lately and if so has anybody found a way to make it? |
@PandJoKell if you feel like troubleshooting it, please post it on the community thread on HA rather than GitHub. Post your screenshot of the YAML config. I'll also update mine and see if it breaks... so strange, but every time folks come with problems, turns out it's typically user error :) not insinuating, just informing. |
Thanks JZ-SmartThings,
Will post it on the community thread with the community addon YAML config. Could be I have made an error, so no problem with informing me :-).
Cheers,
@PandJoKell
… On 31 Jan 2023, at 07:38, JZ-SmartThings ***@***.***> wrote:
@PandJoKell <https://github.com/PandJoKell> if you feel like troubleshooting it, please post it on the community thread on HA rather than GitHub. Post your screenshot of the YAML config. I'll also update mine and see if it breaks... so strange, but every time folks come with problems, turns out it's typically user error :) not insinuating, just informing.
—
Reply to this email directly, view it on GitHub <#968 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJSK5PJYDGEEW6674P66UELWVARDTANCNFSM4TNVWLUA>.
You are receiving this because you were mentioned.
|
@jlunz You saved me. I decided to create a Swap partition directly on the microSD card as @jlunz mentionned. Below are the steps I did using resize2fs, fdisk and mkswap. It might help others in need. `omelette@omelette:~/Downloads$ sudo e2fsck -f /dev/sdc8 hassos-data: ***** FILE SYSTEM WAS MODIFIED ***** omelette@omelette:~/Downloads$ sudo fdisk /dev/sdc Welcome to fdisk (util-linux 2.37.2). A hybrid GPT was detected. You have to sync the hybrid MBR manually (expert command 'M'). Command (m for help): p Disk /dev/sdc: 59.69 GiB, 64088965120 bytes, 125173760 sectors Device Start End Sectors Size Type Command (m for help): d Partition 8 has been deleted. Command (m for help): n Created a new partition 8 of type 'Linux filesystem' and of size 48 GiB. Do you want to remove the signature? [Y]es/[N]o: N Command (m for help): n Created a new partition 9 of type 'Linux filesystem' and of size 4 GiB. Command (m for help): t Changed type of partition 'Linux filesystem' to 'Linux swap'. Command (m for help): w The partition table has been altered. omelette@omelette:~/Downloads$ sudo mkswap /dev/sdc9 |
HassOS release with the issue:
HassOS 4.15
Supervisor logs:
Journal logs:
Kernel logs:
Description of problem:
Hi everybody,
I am using home assistant on a RPI 4 with 1GB of ram. My swap file is only 230mb and fills up pretty fast, in the last week or so i had home assistant crashing a lot and i noticed my swap file is almost pretty full. While reading about this there are pretty clear instructions on the internet on how to increase the swap file on a standard RPI, but i cannot find it anywhere for HASSOS. Does anybody know a command or a setting i can change to increase this? I have a 128GB SD card which is A2 class so i dont mind creating a swap file of 1-2GB.
Thank you!
The text was updated successfully, but these errors were encountered: