{"id":5993,"date":"2016-07-11T09:10:45","date_gmt":"2016-07-11T01:10:45","guid":{"rendered":"http:\/\/rmohan.com\/?p=5993"},"modified":"2016-07-11T09:10:45","modified_gmt":"2016-07-11T01:10:45","slug":"swapon-swapfile-swapon-failed-invalid-argument","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5993","title":{"rendered":"swapon: swapfile: swapon failed: Invalid argument"},"content":{"rendered":"<p> fallocate -l 4G \/swapfile<br \/>\nchmod 600 \/swapfile<br \/>\n mkswap \/swapfile<\/p>\n<p>swapon \/swapfile<br \/>\n<strong> swapon: \/swapfile: swapon failed: Invalid argument<\/strong><\/p>\n<p>echo &#8220;\/swapfile swap swap sw 0 0&#8221; >> \/etc\/fstab<br \/>\necho &#8220;vm.swappiness = 10&#8221; >>\/etc\/sysctl.conf<br \/>\necho &#8220;vm.vfs_cache_pressure = 50&#8221; >> \/etc\/sysctl.conf<\/p>\n<p>The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space but swapon(2) syscall requires a real space. Reference : https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=1129205<\/p>\n<p>I had faced this issue earlier with my box too. So instead of using fallocate, I had used dd as per the link suggests<br \/>\nsudo dd if=\/dev\/zero of=\/swapfile count=4096 bs=1MiB<\/p>\n","protected":false},"excerpt":{"rendered":"<p> fallocate -l 4G \/swapfile chmod 600 \/swapfile mkswap \/swapfile<\/p>\n<p>swapon \/swapfile swapon: \/swapfile: swapon failed: Invalid argument<\/p>\n<p>echo &#8220;\/swapfile swap swap sw 0 0&#8221; >> \/etc\/fstab echo &#8220;vm.swappiness = 10&#8221; >>\/etc\/sysctl.conf echo &#8220;vm.vfs_cache_pressure = 50&#8221; >> \/etc\/sysctl.conf<\/p>\n<p>The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5993"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5993"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5993\/revisions"}],"predecessor-version":[{"id":5994,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5993\/revisions\/5994"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}