{"id":881,"date":"2026-10-20T09:00:00","date_gmt":"2026-10-20T09:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=881"},"modified":"2026-10-20T09:00:00","modified_gmt":"2026-10-20T09:00:00","slug":"add-swap-space-almalinux-10","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/20\/add-swap-space-almalinux-10\/","title":{"rendered":"How to Add Swap Space on AlmaLinux 10 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Add swap space on AlmaLinux 10 by creating a protected 2 GB swap file and enabling it at boot. The process takes about five to ten minutes and gives a memory-constrained VPS a disk-backed buffer when RAM is under pressure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>An AlmaLinux 10 VPS with at least 2 GB of free disk space for the example file; choose a smaller file if your disk is nearly full.<\/li>\n\n\n<li>An SSH connection as <code>root<\/code>, or a normal user that can run commands with <code>sudo<\/code>.<\/li>\n\n\n<li>The <code>\/swapfile<\/code> path must not already be in use as a regular file or active swap device.<\/li>\n\n\n<li>A fresh <a href=\"https:\/\/vpslake.com\/buy-vps\">Linux VPS from VPSLake<\/a> if you need an AlmaLinux server to work on.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is not a replacement for RAM. It is slower than memory, but it can provide breathing room during short-lived memory spikes and may help prevent an immediate out-of-memory failure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Check RAM, disk space, and existing swap<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the current state first so you do not create a duplicate swap area or fill the root filesystem.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/almalinux-release\nfree -h\nswapon --show\ndf -h \/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Typical output on a server without active swap looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AlmaLinux release 10.x (release name may vary)\n               total        used        free      shared  buff\/cache   available\nMem:            2.0Gi       420Mi       1.1Gi       12Mi       480Mi       1.4Gi\nSwap:              0B          0B          0B\nFilesystem      Size  Used Avail Use% Mounted on\n\/dev\/vda1        40G  6.2G   34G  16% \/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">An empty result from <code>swapon --show<\/code> means no swap is active. If it already lists <code>\/swapfile<\/code>, stop here and use the existing file; recreating it could interrupt processes that are using it. Any existing partition or logical volume listed as swap can remain enabled while you add a separate file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create and secure a 2 GB swap file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Allocate the file on the local filesystem, then restrict access before marking it as swap so ordinary users cannot read memory pages written to disk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fallocate -l 2G \/swapfile\nsudo chmod 0600 \/swapfile\nsudo mkswap \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>mkswap<\/code> command prints a new UUID. The UUID is informational for this path-based setup; the <code>\/etc\/fstab<\/code> entry in the next step will refer to <code>\/swapfile<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output includes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)\nno label, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>fallocate<\/code> is unavailable or the filesystem rejects the allocated file, create a fully written file instead. This performs more disk I\/O but avoids sparse-file problems on filesystems that require swap files to have allocated blocks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dd if=\/dev\/zero of=\/swapfile bs=1M count=2048 status=progress\nsudo chmod 0600 \/swapfile\nsudo mkswap \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only run the fallback after the first attempt has failed and <code>\/swapfile<\/code> is not active. The <code>dd<\/code> command replaces the file at that path.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Enable swap now and after every reboot<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the swap file to <code>\/etc\/fstab<\/code> for persistence, reload systemd\u2019s view of that file, and activate the file in the current session.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add this line on its own line, then save and exit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/swapfile none swap defaults 0 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now register the updated configuration and turn the file on:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo swapon \/swapfile\nsudo swapon --show<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see the new file in the active swap table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME      TYPE  SIZE USED PRIO\n\/swapfile file    2G   0B   -2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>defaults<\/code> entry makes the configuration available at boot, while <code>swapon<\/code> activates it without requiring a restart. Reloading systemd avoids stale mount-unit information after changing <code>\/etc\/fstab<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Optionally adjust swappiness<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> controls how readily the kernel reclaims memory into swap. The default is usually suitable, so change it only when your workload and disk performance justify the choice; setting it to zero can increase the risk of the OOM killer terminating a process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the current value before changing it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sysctl vm.swappiness<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a server where you want the kernel to prefer RAM and use swap mainly during pressure, test a value of 10 for the current boot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sysctl vm.swappiness=10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the result is appropriate for your workload, persist it in a dedicated configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/sysctl.d\/99-swap.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vm.swappiness = 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apply and check the saved setting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sysctl -p \/etc\/sysctl.d\/99-swap.conf\nsysctl vm.swappiness<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vm.swappiness = 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the parameter behavior and persistence options, see the <a href=\"https:\/\/docs.redhat.com\/en\/documentation\/red_hat_enterprise_linux\/10\/html\/managing_monitoring_and_updating_the_kernel\/configuring-kernel-parameters-at-runtime\" target=\"_blank\" rel=\"noopener\">RHEL 10 kernel parameter documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the swap file and boot configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm both halves of the setup: the kernel must report <code>\/swapfile<\/code> as active, and <code>\/etc\/fstab<\/code> must contain the persistent entry.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon --show\ncat \/proc\/swaps\nfree -h\nsudo grep -E '^[[:space:]]*\/swapfile[[:space:]]' \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Successful output includes a 2 GB <code>\/swapfile<\/code>, zero or low current usage, and the matching <code>fstab<\/code> line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME      TYPE  SIZE USED PRIO\n\/swapfile file    2G   0B   -2\n\nFilename      Type        Size   Used  Priority\n\/swapfile     file      2097148      0        -2\n\nSwap:          2.0Gi          0B     2.0Gi\n\/swapfile none swap defaults 0 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the AlmaLinux 10-compatible procedure and verification commands, refer to <a href=\"https:\/\/docs.redhat.com\/en\/documentation\/red_hat_enterprise_linux\/10\/html\/managing_storage_devices\/getting-started-with-swap\" target=\"_blank\" rel=\"noopener\">Red Hat\u2019s RHEL 10 swap documentation<\/a>.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Add memory headroom\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Linux VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Add memory headroom<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy an AlmaLinux VPS with room for applications, databases, and a secure swap file.<\/p>\n\t<\/div>\n\t<a class=\"vl-cta-banner__button\" href=\"\/buy-vps\" aria-label=\"View Linux VPS plans\">View Linux VPS plans<\/a>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>swapon: \/swapfile: swapon failed: Invalid argument<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The file may be sparse, have unallocated blocks, or be stored on a filesystem that does not support swap files in its current configuration. Confirm that it is not active, remove the failed file, then recreate it with the <code>dd<\/code> fallback from Step 2; do not delete it if <code>swapon --show<\/code> lists it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>fallocate: fallocate failed: No space left on device<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The root filesystem does not have enough free space for a 2 GB file. Check <code>df -h \/<\/code>, free disk space safely, or choose a smaller swap size such as 1 GB and repeat the creation step with matching <code>dd<\/code> block counts if needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>swapon: ... Operation not permitted<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Some container-based VPS environments do not allow the guest to manage swap. You cannot fix that with a Linux command inside the VPS; ask the hosting provider to enable host-level swap or move the workload to a virtualization plan that permits guest swap files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>swapon: \/swapfile: swapon failed: Device or resource busy<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The path is already active or another process is using it. Run <code>swapon --show<\/code> and <code>ls -l \/swapfile<\/code>; if it is already listed, remove any duplicate <code>fstab<\/code> entry rather than creating another swap area.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How large should swap be on AlmaLinux 10?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There is no single size that fits every server. A 2 GB file is a practical starting point for a small VPS, but memory-heavy services may need more disk-backed headroom; measure RAM pressure and keep enough free disk for the operating system and applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does swap make a VPS faster?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Disk-based swap is much slower than RAM, so heavy swap activity usually indicates that the VPS needs more memory or a workload adjustment. Swap is best treated as an emergency buffer, not a performance upgrade.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to reboot after adding the swap file?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>swapon \/swapfile<\/code> enables it immediately, and the <code>fstab<\/code> entry makes it available on future boots. The <code>systemctl daemon-reload<\/code> command is enough to make systemd recognize the updated configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I remove the swap file later?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>sudo swapoff \/swapfile<\/code>, remove only its line from <code>\/etc\/fstab<\/code>, run <code>sudo systemctl daemon-reload<\/code>, and then delete the file with <code>sudo rm \/swapfile<\/code>. Check <code>swapon --show<\/code> first and do not remove a file that is still active.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"How large should swap be on AlmaLinux 10?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"There is no single size that fits every server. A 2 GB file is a practical starting point for a small VPS, but memory-heavy services may need more disk-backed headroom; measure RAM pressure and keep enough free disk for the operating system and applications.\"}}, {\"@type\": \"Question\", \"name\": \"Does swap make a VPS faster?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Disk-based swap is much slower than RAM, so heavy swap activity usually indicates that the VPS needs more memory or a workload adjustment. Swap is best treated as an emergency buffer, not a performance upgrade.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need to reboot after adding the swap file?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `swapon \/swapfile` enables it immediately, and the `fstab` entry makes it available on future boots. The `systemctl daemon-reload` command is enough to make systemd recognize the updated configuration.\"}}, {\"@type\": \"Question\", \"name\": \"How do I remove the swap file later?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Run `sudo swapoff \/swapfile`, remove only its line from `\/etc\/fstab`, run `sudo systemctl daemon-reload`, and then delete the file with `sudo rm \/swapfile`. Check `swapon --show` first and do not remove a file that is still active.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Learn how to add swap space on AlmaLinux 10 with a secure 2 GB swap file, persistent boot setup, tuning, and verification checks for your VPS.","protected":false},"author":1,"featured_media":882,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[5,9],"tags":[91,93,92],"class_list":["post-881","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-almalinux-10","tag-linux-vps","tag-swap","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":3655,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions\/3655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/882"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}