{"id":6730,"date":"2024-07-31T02:02:00","date_gmt":"2024-07-31T06:02:00","guid":{"rendered":"https:\/\/www.both.org\/?p=6730"},"modified":"2024-07-28T17:41:23","modified_gmt":"2024-07-28T21:41:23","slug":"how-to-remove-existing-traditional-swap-partitions","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=6730","title":{"rendered":"How to remove existing traditional swap partitions"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"6730\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>Swap space is a common and important aspect of computing today regardless of operating system. Linux uses swap space to substitute for RAM when it becomes too full to effectively support additional programs or data. It is a way to temporarily enable the system to keep running albeit at the cost of reduced performance. However the use of zram for swap space has provided an interesting, if counter-intuitive, method for providing a reasonable amount of swap space while significantly improving swap performance.<\/p>\n\n\n\n<p>In a previous article I wrote about <a href=\"https:\/\/www.both.org\/?p=2909\" data-type=\"link\" data-id=\"https:\/\/www.both.org\/?p=2909\" target=\"_blank\" rel=\"noreferrer noopener\">using zram for Linux swap space<\/a> and showed how to configure and activate it. That article covers zram sizing as well as the advantages of using zram for swap instead of traditional hard disk drives (HDD) or solid state devices (SSD). In another article, <a href=\"https:\/\/www.both.org\/?p=2976\" data-type=\"link\" data-id=\"https:\/\/www.both.org\/?p=2976\" target=\"_blank\" rel=\"noreferrer noopener\">How I troubleshoot swappiness and startup time on Linux<\/a>, I wrote about tuning zram swap space using the vm.swappiness kernel parameter.<\/p>\n\n\n\n<p>What I haven&#8217;t previously discussed is how to disable and remove those traditional swap files and partitions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Removing Traditional Swap<\/h2>\n\n\n\n<p>This process is not as straightforward as it should be. It is not hard but it took me some research to figure it out because there is a lot of old and incorrect information out there on the Internet. This procedure works for me on Fedora 36 and later.<\/p>\n\n\n\n<p>First turn off swap for the existing swap partitions and files. This can be done using <strong>swapoff \/dev\/nameofswapdevice<\/strong> but it might be easiest to just turn off all swap with the <strong>swapoff -a<\/strong> command. This command also turns off any existing Zram swap.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># swapoff -a<\/code><\/pre>\n\n\n\n<p>Remove the entries for all traditional swap partitions or files in the \/etc\/fstab file. I originally commented these out in case of unexpected problems so that it would be easy to reactivate them. I deleted those entries after a few days of running with only zram swap. Zram swap does not require an entry in the \/etc\/fstab file.<\/p>\n\n\n\n<p>You\u2019d think \u2013 at least I did at first \u2013 that this would be all that is needed and you could remove the swap partitions or the logical volumes designated as swap. But&#8211;no. I did remove the logical volume I had designated as swap space and rebooted to test. The reboot failed and hung very early in the boot process.<\/p>\n\n\n\n<p>Fortunately I have configured my kernel so that it displays boot and startup messages rather than the graphical boot designed to hide the \u201cscary stuff\u201d from users. As a result I was able to see the error message indicating that the kernel couldn\u2019t find the swap volume. To recover from this I booted from a Live Fedora USB drive and created a new swap volume. It is not necessary to do anything else. Then I rebooted and removed the swap entries in kernel line of \/etc\/defaults\/grub. The grub boot defaults are set in the \/etc\/default\/grub file. Changes are made to this file and then the grub.cfg file is regenerated.<\/p>\n\n\n\n<p>The default \/etc\/default\/grub configuration file is simple and we only need concern ourselves with one line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR=\"$(sed 's, release .*$,,g' \/etc\/system-release)\"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT=\"console\"\nGRUB_CMDLINE_LINUX=\"resume=\/dev\/mapper\/vg01-swap rd.lvm.lv=vg01\/root rd.lvm.lv=vg01\/swap rd.lvm.lv=vg01\/usr <strong>rhgb quiet<\/strong>\"\nGRUB_DISABLE_RECOVERY=\"true\"\nGRUB_ENABLE_BLSCFG=true<\/code><\/pre>\n\n\n\n<p>Change the <code>GRUB_CMDLINE_LINUX<\/code> line to the following.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRUB_CMDLINE_LINUX=\"rd.lvm.lv=vg01\/root rd.lvm.lv=vg01\/usr\"<\/code><\/pre>\n\n\n\n<p>Removing \u201c<code>rhgb quiet<\/code>\u201d kernel options causes all of the kernel boot messages and systemd startup messages to be displayed. This can make it easier to quickly locate problems during the boot and startup phases. Removing \u201cresume=\/dev\/mapper\/vg01-swap\u201d and \u201crd.lvm.lv=vg01\/swap\u201d prevents the kernel from looking for the swap volume.<\/p>\n\n\n\n<p>To make these changes take effect it is necessary to rebuild \/boot\/grub2\/grub.cfg. Make a backup of the current grub.cfg file and then run the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># grub2-mkconfig &gt; \/boot\/grub2\/grub.cfg<\/code><\/pre>\n\n\n\n<p>After this I deleted the swap partition, ran <strong>swapon -a<\/strong> and verified with <strong>swapon &#8211;show<\/strong> and <strong>lsblk<\/strong>. Rebooting the system gave me a final check to ensure that the system did boot properly and that the only swap is the Zram swap.<\/p>\n\n\n\n<p>Did you notice how easy it is to make changes to the kernel configuration?<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n\n\n\n<p>Turn off swap for partition<br>remove entry for swap in \/etc\/fstab<br>remove swap entries in kernel line of \/etc\/defaults\/grub<br>regen grub<br>Optional &#8211; disable swap service<br>remove swap volume or partition<br>test by rebooting<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap space is a common and important aspect of computing today regardless of operating system. Linux uses swap space to substitute for RAM when it becomes too full to effectively support additional programs or data. It is a way to temporarily enable the system to keep running albeit at the cost of reduced performance. However the use of zram for swap space has provided an interesting, if counter-intuitive, method for providing a reasonable amount of swap space while significantly improving swap performance.<\/p>\n","protected":false},"author":2,"featured_media":3132,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5,509,89,510],"tags":[97,139],"class_list":["post-6730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-swap","category-system-administration","category-zram","tag-sysadmin","tag-zram"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/6730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6730"}],"version-history":[{"count":7,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/6730\/revisions"}],"predecessor-version":[{"id":6737,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/6730\/revisions\/6737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3132"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}