{"id":11481,"date":"2025-04-14T08:10:30","date_gmt":"2025-04-14T15:10:30","guid":{"rendered":"https:\/\/jasonsblog.ddns.net\/?p=11481"},"modified":"2025-04-14T08:10:30","modified_gmt":"2025-04-14T15:10:30","slug":"pi-star-sd-card-tweaks","status":"publish","type":"post","link":"https:\/\/jasonsblog.ddns.net\/index.php\/2025\/04\/14\/pi-star-sd-card-tweaks\/","title":{"rendered":"Pi-Star SD Card Tweaks"},"content":{"rendered":"\n<p>The things you forget. So I got around to putting the new Beta version of <a href=\"https:\/\/www.pistar.uk\/beta\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pi-Star<\/a> on my main digital hotspot after the recent upgrade. And with heavy disk reads and writes it was taking over the machine, and while compiling DMRGateway and Fastfetch it was becoming unresponsive and losing my Mosh connection, freezing due to no swap file and the limited memory of my Raspberry Pi 3A+. So I revisited some old tweaks to make the system work better and not fail when compiling software. The first tweak is to add the following statement to \/boot\/config.txt which I seem to remember tweaks the bus speed making the system more responsive while doing heavy disk reads and writes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>init_emmc_clock=250000000<\/code><\/pre>\n\n\n\n<p>Then you&#8217;ll need to reboot for it to take effect. You can write a file and then read it to test the speed improvements. You can also do these before adding the statement above so you can see what improvements were made. Also, I had a Pi where this actually lowered the speeds a tiny bit, but made the system more responsive none the less during heavy reads and writes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dd if=\/dev\/zero of=test.tmp bs=500K count=1024\ndd if=test.tmp of=\/dev\/null bs=500K count=1024<\/code><\/pre>\n\n\n\n<p>Instead of rewriting how to add a swapfile I&#8217;ll include the article below that will take you through setting up a swap file for when the computer runs out of memory so it can use the SD Card as extra memory. And these can be undone if you decide you don&#8217;t need these tweaks.<\/p>\n\n\n\n<p><a href=\"https:\/\/linuxize.com\/post\/create-a-linux-swap-file\">https:\/\/linuxize.com\/post\/create-a-linux-swap-file<\/a><\/p>\n\n\n<div class=\"wp-block-ub-divider ub_divider ub-divider-orientation-horizontal\" id=\"ub_divider_aeabc280-9587-4d4c-99fc-48663e9d62ab\"><div class=\"ub_divider_wrapper\" style=\"position: relative; margin-bottom: 2px; width: 100%; height: 2px; \" data-divider-alignment=\"center\"><div class=\"ub_divider_line\" style=\"border-top: 2px solid #ccc; margin-top: 2px; \"><\/div><\/div><\/div>\n\n\n<h1 class=\"wp-block-heading\">Create a Linux Swap File<\/h1>\n\n\n\n<p>Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space.<\/p>\n\n\n\n<p>Swap space can take the form of either a dedicated swap partition or a swap file. In most cases, when running Linux on a virtual machine, a swap partition is not present, so the only option is to create a swap file.<\/p>\n\n\n\n<p>This tutorial was tested on Linux systems with Ubuntu 18.04 and CentOS 7, but it should work with any other Linux distribution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-add-swap-file\">How to add Swap File<\/h2>\n\n\n\n<p>Follow these steps to add 1GB of swap to your server. If you want to add 2GB instead of 1 GB, replace <code>1G<\/code> with <code>2G<\/code>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a file that will be used for swap:<code>sudo fallocate -l 1G \/swapfile<\/code><\/li>\n<\/ol>\n\n\n\n<p>If <code>faillocate<\/code> is not installed or if you get an error message saying <code>fallocate failed: Operation not supported<\/code> then you can use the following command to create the swap file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=1048576<\/code><\/pre>\n\n\n\n<p>Only the root user should be able to write and read the swap file. To set the correct <a href=\"https:\/\/linuxize.com\/post\/chmod-command-in-linux\/\">permissions<\/a> type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod 600 \/swapfile<\/code><\/pre>\n\n\n\n<p>Use the <code>mkswap<\/code> utility to set up the file as Linux swap area:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkswap \/swapfile<\/code><\/pre>\n\n\n\n<p>Enable the swap with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon \/swapfile<\/code><\/pre>\n\n\n\n<p>To make the change permanent open the <code>\/etc\/fstab<\/code> file and append the following line:<\/p>\n\n\n\n<p>\/etc\/fstab<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/swapfile swap swap defaults 0 0<\/code><\/pre>\n\n\n\n<p>To verify that the swap is active, use either the <code>swapon<\/code> or the <a href=\"https:\/\/linuxize.com\/post\/free-command-in-linux\/\"><code>free<\/code> command<\/a> as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon --show<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME      TYPE  SIZE   USED PRIO\n\/swapfile file 1024M 507.4M   -1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo free -h<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>              total        used        free      shared  buff\/cache   available\nMem:           488M        158M         83M        2.3M        246M        217M\nSwap:          1.0G        506M        517M<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-adjust-the-swappiness-value\">How to adjust the swappiness value<\/h2>\n\n\n\n<p>Swappiness is a Linux kernel property that defines how often the system will use the swap space. Swappiness can have a value between 0 and 100. A low value will make the kernel to try to avoid swapping whenever possible, while a higher value will make the kernel to use the swap space more aggressively.<\/p>\n\n\n\n<p>The default swappiness value is 60. You can check the current swappiness value by typing the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/proc\/sys\/vm\/swappiness<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>60\n<\/code><\/pre>\n\n\n\n<p>While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.<\/p>\n\n\n\n<p>For example, to set the swappiness value to 10, you would run the following <a href=\"https:\/\/linuxize.com\/post\/sysctl-command-in-linux\/\"><code>sysctl<\/code><\/a> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sysctl vm.swappiness=10<\/code><\/pre>\n\n\n\n<p>To make this parameter persistent across reboots append the following line to the <code>\/etc\/sysctl.conf<\/code> file:<\/p>\n\n\n\n<p>\/etc\/sysctl.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vm.swappiness=10\n<\/code><\/pre>\n\n\n\n<p>The optimal swappiness value depends on your system workload and how the memory is being used. You should adjust this parameter in small increments to find an optimal value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-remove-swap-file\">How to remove Swap File<\/h2>\n\n\n\n<p>If for any reason you want to deactivate and remove the swap file, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, deactivate the swap by typing:<code>sudo swapoff -v \/swapfile<\/code><\/li>\n<\/ol>\n\n\n\n<p>Remove the swap file entry <code>\/swapfile swap swap defaults 0 0<\/code> from the <code>\/etc\/fstab<\/code> file.<\/p>\n\n\n\n<p>Finally, delete the actual swapfile file using the <a href=\"https:\/\/linuxize.com\/post\/rm-command-in-linux\/\"><code>rm<\/code><\/a> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm \/swapfile<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>You have learned how to create a swap file and activate and configure swap space on your Linux system.<\/p>\n\n\n\n<p>If you hit a problem or have feedback, leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The things you forget. So I got around to putting the new Beta version of Pi-Star on my main digital hotspot after the recent upgrade. And with heavy disk reads and writes it was taking over the machine, and while compiling DMRGateway and Fastfetch it was becoming unresponsive and losing my Mosh connection, freezing due [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-11481","post","type-post","status-publish","format-standard","hentry","category-tech"],"blocksy_meta":[],"featured_image_src":null,"author_info":{"display_name":"Jason","author_link":"https:\/\/jasonsblog.ddns.net\/index.php\/author\/jturning\/"},"_links":{"self":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/11481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/comments?post=11481"}],"version-history":[{"count":1,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/11481\/revisions"}],"predecessor-version":[{"id":11482,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/11481\/revisions\/11482"}],"wp:attachment":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/media?parent=11481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/categories?post=11481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/tags?post=11481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}