I can't enable Swap space on CentOS 7












44















So I'm following a tutorial to install OTRS which is Open source Ticket Request System. So in order to install, it requires: 4GB of Swap space. Here's the command I used:



[root@ip-10-0-7-41 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 50G 14G 37G 27% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 484M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1000
[root@ip-10-0-7-41 ~]# fallocate -l 4G /myswap
[root@ip-10-0-7-41 ~]# ls -lh /myswap
-rw-r--r--. 1 root root 4.0G Jul 8 08:44 /myswap
[root@ip-10-0-7-41 ~]# chmod 600 /myswap
[root@ip-10-0-7-41 ~]# mkswap /myswap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=3656082a-148d-4604-96fb-5b4604fa5b2e
[root@ip-10-0-7-41 ~]# swapon /myswap
swapon: /myswap: swapon failed: Invalid argument


You can see : Invalid argument error here. I tried many time in vain to enable it.Someone please tell me how to fix this error.
(I'm running this CentOS 7 on AWS Instance EC2)



[root@ip-10-0-7-41 ~]# df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/xvda1 xfs /









share|improve this question

























  • What filesystem is this happening on? btrfs by any chance?

    – schaiba
    Jul 8 '16 at 8:54











  • @schaiba Hello, i edited my question. I think filesystem is xfs.

    – The One
    Jul 8 '16 at 8:56






  • 2





    On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

    – schaiba
    Jul 8 '16 at 9:01











  • @schaiba I didn't know very well about type of filesystem. Thanks so much.

    – The One
    Jul 8 '16 at 9:04
















44















So I'm following a tutorial to install OTRS which is Open source Ticket Request System. So in order to install, it requires: 4GB of Swap space. Here's the command I used:



[root@ip-10-0-7-41 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 50G 14G 37G 27% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 484M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1000
[root@ip-10-0-7-41 ~]# fallocate -l 4G /myswap
[root@ip-10-0-7-41 ~]# ls -lh /myswap
-rw-r--r--. 1 root root 4.0G Jul 8 08:44 /myswap
[root@ip-10-0-7-41 ~]# chmod 600 /myswap
[root@ip-10-0-7-41 ~]# mkswap /myswap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=3656082a-148d-4604-96fb-5b4604fa5b2e
[root@ip-10-0-7-41 ~]# swapon /myswap
swapon: /myswap: swapon failed: Invalid argument


You can see : Invalid argument error here. I tried many time in vain to enable it.Someone please tell me how to fix this error.
(I'm running this CentOS 7 on AWS Instance EC2)



[root@ip-10-0-7-41 ~]# df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/xvda1 xfs /









share|improve this question

























  • What filesystem is this happening on? btrfs by any chance?

    – schaiba
    Jul 8 '16 at 8:54











  • @schaiba Hello, i edited my question. I think filesystem is xfs.

    – The One
    Jul 8 '16 at 8:56






  • 2





    On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

    – schaiba
    Jul 8 '16 at 9:01











  • @schaiba I didn't know very well about type of filesystem. Thanks so much.

    – The One
    Jul 8 '16 at 9:04














44












44








44


14






So I'm following a tutorial to install OTRS which is Open source Ticket Request System. So in order to install, it requires: 4GB of Swap space. Here's the command I used:



[root@ip-10-0-7-41 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 50G 14G 37G 27% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 484M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1000
[root@ip-10-0-7-41 ~]# fallocate -l 4G /myswap
[root@ip-10-0-7-41 ~]# ls -lh /myswap
-rw-r--r--. 1 root root 4.0G Jul 8 08:44 /myswap
[root@ip-10-0-7-41 ~]# chmod 600 /myswap
[root@ip-10-0-7-41 ~]# mkswap /myswap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=3656082a-148d-4604-96fb-5b4604fa5b2e
[root@ip-10-0-7-41 ~]# swapon /myswap
swapon: /myswap: swapon failed: Invalid argument


You can see : Invalid argument error here. I tried many time in vain to enable it.Someone please tell me how to fix this error.
(I'm running this CentOS 7 on AWS Instance EC2)



[root@ip-10-0-7-41 ~]# df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/xvda1 xfs /









share|improve this question
















So I'm following a tutorial to install OTRS which is Open source Ticket Request System. So in order to install, it requires: 4GB of Swap space. Here's the command I used:



[root@ip-10-0-7-41 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 50G 14G 37G 27% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 484M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1000
[root@ip-10-0-7-41 ~]# fallocate -l 4G /myswap
[root@ip-10-0-7-41 ~]# ls -lh /myswap
-rw-r--r--. 1 root root 4.0G Jul 8 08:44 /myswap
[root@ip-10-0-7-41 ~]# chmod 600 /myswap
[root@ip-10-0-7-41 ~]# mkswap /myswap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=3656082a-148d-4604-96fb-5b4604fa5b2e
[root@ip-10-0-7-41 ~]# swapon /myswap
swapon: /myswap: swapon failed: Invalid argument


You can see : Invalid argument error here. I tried many time in vain to enable it.Someone please tell me how to fix this error.
(I'm running this CentOS 7 on AWS Instance EC2)



[root@ip-10-0-7-41 ~]# df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/xvda1 xfs /






centos swap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 6 '16 at 13:20









Jeff Schaller

39.9k1054126




39.9k1054126










asked Jul 8 '16 at 8:50









The OneThe One

1,20562032




1,20562032













  • What filesystem is this happening on? btrfs by any chance?

    – schaiba
    Jul 8 '16 at 8:54











  • @schaiba Hello, i edited my question. I think filesystem is xfs.

    – The One
    Jul 8 '16 at 8:56






  • 2





    On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

    – schaiba
    Jul 8 '16 at 9:01











  • @schaiba I didn't know very well about type of filesystem. Thanks so much.

    – The One
    Jul 8 '16 at 9:04



















  • What filesystem is this happening on? btrfs by any chance?

    – schaiba
    Jul 8 '16 at 8:54











  • @schaiba Hello, i edited my question. I think filesystem is xfs.

    – The One
    Jul 8 '16 at 8:56






  • 2





    On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

    – schaiba
    Jul 8 '16 at 9:01











  • @schaiba I didn't know very well about type of filesystem. Thanks so much.

    – The One
    Jul 8 '16 at 9:04

















What filesystem is this happening on? btrfs by any chance?

– schaiba
Jul 8 '16 at 8:54





What filesystem is this happening on? btrfs by any chance?

– schaiba
Jul 8 '16 at 8:54













@schaiba Hello, i edited my question. I think filesystem is xfs.

– The One
Jul 8 '16 at 8:56





@schaiba Hello, i edited my question. I think filesystem is xfs.

– The One
Jul 8 '16 at 8:56




2




2





On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

– schaiba
Jul 8 '16 at 9:01





On XFS indeed it's better to use dd. Please bear in mind that not all filesystems support swap or at least not in the same way.

– schaiba
Jul 8 '16 at 9:01













@schaiba I didn't know very well about type of filesystem. Thanks so much.

– The One
Jul 8 '16 at 9:04





@schaiba I didn't know very well about type of filesystem. Thanks so much.

– The One
Jul 8 '16 at 9:04










3 Answers
3






active

oldest

votes


















81














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



I'd faced this issue earlier with my box too. So instead of using fallocate, I used dd as the link suggests



sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB


and proceeding with chmod, mkswap & swapon commands. Bingo ! It worked.






share|improve this answer





















  • 1





    Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

    – Davidian1024
    May 30 '18 at 0:28













  • Solution works on CentOS 7.5

    – NerdOfCode
    Aug 31 '18 at 20:32



















9














Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need



yum install nano -y

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

sudo nano /etc/fstab


add this line:



/swapfile   swap    swap    sw  0   0


run this command



sudo sysctl vm.swappiness=10

sudo nano /etc/sysctl.conf


add this line



vm.swappiness = 10
vm.vfs_cache_pressure = 50


To verify swap's size



swapon --summary
free -h





share|improve this answer































    0














    works perfectly! on centos 7 dd works but fallocate does not






    share|improve this answer








    New contributor




    user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294600%2fi-cant-enable-swap-space-on-centos-7%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      81














      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



      I'd faced this issue earlier with my box too. So instead of using fallocate, I used dd as the link suggests



      sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB


      and proceeding with chmod, mkswap & swapon commands. Bingo ! It worked.






      share|improve this answer





















      • 1





        Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

        – Davidian1024
        May 30 '18 at 0:28













      • Solution works on CentOS 7.5

        – NerdOfCode
        Aug 31 '18 at 20:32
















      81














      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



      I'd faced this issue earlier with my box too. So instead of using fallocate, I used dd as the link suggests



      sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB


      and proceeding with chmod, mkswap & swapon commands. Bingo ! It worked.






      share|improve this answer





















      • 1





        Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

        – Davidian1024
        May 30 '18 at 0:28













      • Solution works on CentOS 7.5

        – NerdOfCode
        Aug 31 '18 at 20:32














      81












      81








      81







      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



      I'd faced this issue earlier with my box too. So instead of using fallocate, I used dd as the link suggests



      sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB


      and proceeding with chmod, mkswap & swapon commands. Bingo ! It worked.






      share|improve this answer















      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



      I'd faced this issue earlier with my box too. So instead of using fallocate, I used dd as the link suggests



      sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB


      and proceeding with chmod, mkswap & swapon commands. Bingo ! It worked.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 25 '17 at 3:13

























      answered Jul 8 '16 at 9:06









      RahulRahul

      9,10412842




      9,10412842








      • 1





        Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

        – Davidian1024
        May 30 '18 at 0:28













      • Solution works on CentOS 7.5

        – NerdOfCode
        Aug 31 '18 at 20:32














      • 1





        Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

        – Davidian1024
        May 30 '18 at 0:28













      • Solution works on CentOS 7.5

        – NerdOfCode
        Aug 31 '18 at 20:32








      1




      1





      Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

      – Davidian1024
      May 30 '18 at 0:28







      Odd, an fallocate'd swap file worked fine for me on Ubuntu 16.04.3 LTS but it fails with "swapon failed: Invalid argument" on Red Hat Enterprise Linux Server release 7.4 (Maipo). The dd command provided above indeed works on RedHat. There must be something different between the two OSes that allows fallocate to work on Ubuntu.

      – Davidian1024
      May 30 '18 at 0:28















      Solution works on CentOS 7.5

      – NerdOfCode
      Aug 31 '18 at 20:32





      Solution works on CentOS 7.5

      – NerdOfCode
      Aug 31 '18 at 20:32













      9














      Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need



      yum install nano -y

      sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
      sudo chmod 600 /swapfile
      sudo mkswap /swapfile
      sudo swapon /swapfile

      sudo nano /etc/fstab


      add this line:



      /swapfile   swap    swap    sw  0   0


      run this command



      sudo sysctl vm.swappiness=10

      sudo nano /etc/sysctl.conf


      add this line



      vm.swappiness = 10
      vm.vfs_cache_pressure = 50


      To verify swap's size



      swapon --summary
      free -h





      share|improve this answer




























        9














        Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need



        yum install nano -y

        sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
        sudo chmod 600 /swapfile
        sudo mkswap /swapfile
        sudo swapon /swapfile

        sudo nano /etc/fstab


        add this line:



        /swapfile   swap    swap    sw  0   0


        run this command



        sudo sysctl vm.swappiness=10

        sudo nano /etc/sysctl.conf


        add this line



        vm.swappiness = 10
        vm.vfs_cache_pressure = 50


        To verify swap's size



        swapon --summary
        free -h





        share|improve this answer


























          9












          9








          9







          Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need



          yum install nano -y

          sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
          sudo chmod 600 /swapfile
          sudo mkswap /swapfile
          sudo swapon /swapfile

          sudo nano /etc/fstab


          add this line:



          /swapfile   swap    swap    sw  0   0


          run this command



          sudo sysctl vm.swappiness=10

          sudo nano /etc/sysctl.conf


          add this line



          vm.swappiness = 10
          vm.vfs_cache_pressure = 50


          To verify swap's size



          swapon --summary
          free -h





          share|improve this answer













          Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need



          yum install nano -y

          sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
          sudo chmod 600 /swapfile
          sudo mkswap /swapfile
          sudo swapon /swapfile

          sudo nano /etc/fstab


          add this line:



          /swapfile   swap    swap    sw  0   0


          run this command



          sudo sysctl vm.swappiness=10

          sudo nano /etc/sysctl.conf


          add this line



          vm.swappiness = 10
          vm.vfs_cache_pressure = 50


          To verify swap's size



          swapon --summary
          free -h






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 21 '18 at 4:47









          Dylan BDylan B

          19112




          19112























              0














              works perfectly! on centos 7 dd works but fallocate does not






              share|improve this answer








              New contributor




              user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                works perfectly! on centos 7 dd works but fallocate does not






                share|improve this answer








                New contributor




                user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  works perfectly! on centos 7 dd works but fallocate does not






                  share|improve this answer








                  New contributor




                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  works perfectly! on centos 7 dd works but fallocate does not







                  share|improve this answer








                  New contributor




                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 17 mins ago









                  user333330user333330

                  1




                  1




                  New contributor




                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  user333330 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294600%2fi-cant-enable-swap-space-on-centos-7%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      サソリ

                      広島県道265号伴広島線

                      Accessing regular linux commands in Huawei's Dopra Linux