{"id":893,"date":"2026-10-21T18:00:00","date_gmt":"2026-10-21T18:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=893"},"modified":"2026-10-21T18:00:00","modified_gmt":"2026-10-21T18:00:00","slug":"add-swap-space-rocky-linux-10","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/21\/add-swap-space-rocky-linux-10\/","title":{"rendered":"How to Add Swap Space on Rocky Linux 10"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Add swap space on Rocky Linux 10 by creating a protected 2 GiB swap file and enabling it now and at every future boot. The setup usually takes five to ten minutes and gives a small VPS temporary disk-backed headroom 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>Rocky Linux 10, with at least 2.5 GiB free on the filesystem mounted at <code>\/<\/code> for this example.<\/li>\n\n\n<li>SSH access as <code>root<\/code>, or an administrative user that can run commands with <code>sudo<\/code>.<\/li>\n\n\n<li>A shell prompt and permission to create <code>\/swapfile<\/code>; do not use that path if it already belongs to a file or active swap area.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a Rocky Linux server for this procedure.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is slower than RAM, so treat it as a buffer for short memory spikes rather than a substitute for choosing enough memory. The commands below use 2 GiB; use a smaller file if your disk has less free space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Inspect Rocky Linux 10 and the current swap state<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the release, root filesystem, free capacity, and existing swap before writing anything so you do not overwrite a useful configuration or fill the system disk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID)=' \/etc\/os-release\nfindmnt -no FSTYPE \/\ndf -h \/\nfree -h\nswapon --show\nif [ -e \/swapfile ]; then ls -lh \/swapfile; else echo \"\/swapfile is available\"; fi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On an unused Rocky Linux 10 VPS, the release starts with version 10, the root filesystem is commonly <code>xfs<\/code> or <code>ext4<\/code>, <code>Swap<\/code> is <code>0B<\/code>, and the last line confirms that the target path is free:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Rocky Linux 10.x (Red Quartz)\"\nVERSION_ID=\"10.x\"\nxfs\nFilesystem      Size  Used Avail Use% Mounted on\n\/dev\/vda1        40G  6.8G   33G  18% \/\n               total        used        free      shared  buff\/cache   available\nMem:            2.0Gi       520Mi       760Mi        18Mi       720Mi       1.3Gi\nSwap:              0B          0B          0B\n\/swapfile is available<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The minor release, device name, memory totals, and filesystem type can differ. Rocky Linux 10 uses DNF 5, but no package installation is required for this procedure. If <code>swapon --show<\/code> lists swap already, keep it unless you have a specific reason to add another area. If <code>\/swapfile<\/code> exists, stop here and choose another unused filename.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create and protect the swap file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Allocate the file, lock it to root, and add the swap signature; the permission step prevents local users from reading memory pages that the kernel writes into the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the normal XFS or ext4 root filesystem, create a 2 GiB file with <code>fallocate<\/code>, which the RHEL 10 storage documentation recommends for modern filesystems:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fallocate -l 2G \/swapfile\nsudo chown root:root \/swapfile\nsudo chmod 0600 \/swapfile\nsudo mkswap \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>mkswap<\/code> should report a swap area close to 2 GiB and print a generated UUID. The UUID is informational here because the persistent configuration will use the stable <code>\/swapfile<\/code> path.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Setting up swapspace version 1, size = 2 GiB\nno label, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the file format and Rocky Linux 10\u2019s Red Hat-compatible storage workflow, see the official <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\">RHEL 10 swap documentation<\/a>. Do not repeat this step if <code>\/swapfile<\/code> is already active.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Activate swap for the running system<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Formatting the file only prepares it; <code>swapon<\/code> makes the kernel use it immediately without requiring a reboot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon \/swapfile\nsudo swapon --show<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output should include <code>\/swapfile<\/code> with a capacity close to 2 GiB:<\/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 priority can be different when another swap device is already enabled. The important checks are that the file is listed and its size is correct.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Persist swap across reboots<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add one guarded <code>\/etc\/fstab<\/code> entry so Rocky Linux enables the same file during boot, while avoiding duplicate lines if the command is run again.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if ! sudo grep -qE '^[[:space:]]*\/swapfile[[:space:]]' \/etc\/fstab; then\n  echo '\/swapfile none swap defaults 0 0' | sudo tee -a \/etc\/fstab\nfi\nsudo systemctl daemon-reload\nsudo grep -nE '^[[:space:]]*\/swapfile[[:space:]]' \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final command should show one active configuration line:<\/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\"><code>systemctl daemon-reload<\/code> refreshes systemd\u2019s generated view of the changed file. Swap is already active from Step 3; the <code>fstab<\/code> record is what restores it after the next restart.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Review swappiness before changing it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>vm.swappiness<\/code> value influences how readily Linux moves inactive memory pages to disk, so inspect it before choosing a workload-specific setting.<\/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\">If the server should prefer RAM and use swap mostly during pressure, you can test 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 monitoring shows that value suits the workload, save it in a separate file so package updates do not overwrite the setting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' 'vm.swappiness = 10' | sudo tee \/etc\/sysctl.d\/60-swap.conf\nsudo sysctl --load=\/etc\/sysctl.d\/60-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\">Do not set swappiness to zero simply to eliminate disk activity. Continuous swapping usually means the VPS needs more RAM or the application needs tighter memory limits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the persistent Rocky Linux 10 swap setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these checks together to prove that the kernel sees the file, the file is protected, and the boot configuration contains exactly one matching entry.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon --show\ncat \/proc\/swaps\nfree -h\nsudo stat -c '%A %U:%G %n' \/swapfile\nsudo grep -E '^[[:space:]]*\/swapfile[[:space:]]' \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Successful output contains a 2 GiB active file, a nonzero swap total, root-only permissions, and one <code>fstab<\/code> entry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME      TYPE  SIZE USED PRIO\n\/swapfile file    2G   0B   -2\nSwap:          2.0Gi          0B     2.0Gi\n-rw------- root:root \/swapfile\n\/swapfile none swap defaults 0 0<\/code><\/pre>\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 a Rocky Linux VPS with room for applications and a protected 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>fallocate: fallocate failed: No space left on device<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The root filesystem cannot provide the requested 2 GiB. Confirm the available capacity with <code>df -h \/<\/code>, clean up files you recognize, or recreate the inactive file at a smaller size such as 1 GiB. Never remove the file until <code>sudo swapon --show<\/code> confirms that <code>\/swapfile<\/code> is not active.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo swapon --show\nsudo rm \/swapfile\nsudo fallocate -l 1G \/swapfile\nsudo chown root:root \/swapfile\nsudo chmod 0600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>\/etc\/fstab<\/code> path does not include the size, so the existing entry can remain unchanged.<\/p>\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, incomplete, or on a filesystem with swap-file restrictions. Check <code>findmnt -no FSTYPE \/<\/code> and confirm that <code>mkswap \/swapfile<\/code> completed; on XFS or ext4, recreate the inactive file with <code>fallocate<\/code>, then run <code>mkswap<\/code> and <code>swapon<\/code> again. If the kernel log identifies a filesystem or virtualization restriction, use a swap partition or ask the host to provide swap instead.<\/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 has it open. Run <code>sudo swapon --show<\/code> and <code>ls -l \/swapfile<\/code>; if it is already listed, keep that file and remove only duplicate <code>\/swapfile<\/code> lines from <code>\/etc\/fstab<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>swapon: \/swapfile: swapon failed: Operation not permitted<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Some container-based VPS plans do not allow a guest to manage its own swap. This is a host policy, not a missing Rocky Linux package, so request host-managed swap or move the workload to a virtualization plan that permits guest swap files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How much swap should Rocky Linux 10 use?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There is no fixed RAM-to-swap formula. Two GiB is a practical starting point for a small VPS when disk space is available, but size the file around short memory spikes and keep enough storage for updates, logs, and application data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does swap add physical RAM?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Swap uses disk storage as slower virtual memory. It can delay an out-of-memory failure during a brief spike, but it cannot provide the performance of additional RAM.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to reboot after enabling swap?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>swapon \/swapfile<\/code> activates the file immediately, and the <code>\/etc\/fstab<\/code> entry handles later boots. A reboot is only needed if you want to test the complete boot path during a maintenance window.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I remove the swap file later?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm its exact path with <code>sudo swapon --show<\/code>, run <code>sudo swapoff \/swapfile<\/code>, and remove only its line from <code>\/etc\/fstab<\/code>. After checking that it is inactive, delete the file with <code>sudo rm \/swapfile<\/code>; never remove active swap first.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"How much swap should Rocky Linux 10 use?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"There is no fixed RAM-to-swap formula. Two GiB is a practical starting point for a small VPS when disk space is available, but size the file around short memory spikes and keep enough storage for updates, logs, and application data.\"}}, {\"@type\": \"Question\", \"name\": \"Does swap add physical RAM?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Swap uses disk storage as slower virtual memory. It can delay an out-of-memory failure during a brief spike, but it cannot provide the performance of additional RAM.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need to reboot after enabling swap?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `swapon \/swapfile` activates the file immediately, and the `\/etc\/fstab` entry handles later boots. A reboot is only needed if you want to test the complete boot path during a maintenance window.\"}}, {\"@type\": \"Question\", \"name\": \"Can I remove the swap file later?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Confirm its exact path with `sudo swapon --show`, run `sudo swapoff \/swapfile`, and remove only its line from `\/etc\/fstab`. After checking that it is inactive, delete the file with `sudo rm \/swapfile`; never remove active swap first.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Add swap space on Rocky Linux 10 with a secure 2 GiB file, persistent boot setup, safe tuning, verification, and common fixes.","protected":false},"author":1,"featured_media":894,"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":[93,99,92],"class_list":["post-893","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-linux-vps","tag-rocky-linux-10","tag-swap","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/893","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=893"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/893\/revisions"}],"predecessor-version":[{"id":3676,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/893\/revisions\/3676"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/894"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}