element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi
  • Products
  • More
Raspberry Pi
Forum How do I permanently disable the swap service?
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 162 subscribers
  • Views 4781 views
  • Users 0 members are here
  • raspberry
  • raspberry_pi
  • raspberrypi
  • rpi
  • linux
Related

How do I permanently disable the swap service?

Kuya.Marc
Kuya.Marc over 9 years ago

My Device: Raspberry PiRaspberry Pi

 

Situation: Automatic Force-Restoration of Swap service

For some unknown reason, Raspbian OS permanently reloads the swap service at every reboot. Here are the steps I have to do after every reboot:

  1. sudo sync
  2. sudo swapoff -a
  3. sudo apt-get purge -y dphys-swapfile
  4. sudo rm /var/swap
  5. sudo sync

This stop swap, but it's back on a reboot. Writing this list into a script makes the script vanish upon a reboot with swap service activated.

Here are the other attempts I've tried and tried to kill the swap service:

  • sudo update-rc.d dphys-swapfile disable
  • sudo rm /etc/init.d/dphys-swapfile
  • sudo dphys-swapfile disable
  • sudo dphys-swapfile swapoff
  • sudo dphys-swapfile uninstall
  • sudo echo "CONF_SWAPSIZE=0" > /etc/dphys-swapfile
  • sudo rm /etc/dphys-swapfile
  • sudo chmod -x /etc/init.d/dphys-swapfile

All attempts to kill the swap service failed! Upon a reboot, a 100MB swapfile is restored and activated.

Anyone have a working solution?

  • Reply
  • Cancel
  • Cancel

Top Replies

  • Former Member
    Former Member over 9 years ago +1

    If you take away execute permissions from scripts in /etc/init.d they will not run in any runlevel.  So maybe you did not quite hit the right order of things.

     

    sudo chmod -x /etc/init.d/dphys-swapfile

    sudo…

  • dragonfly.67
    dragonfly.67 over 1 year ago +1

    With the newest Raspbian Version (on a Pi4 Rev. 1.1 / 4GB) I just changed the the Parameter CONF_SWAPSIZE to 0 in the file /etc/dphys-swapfile. After a reboot there was no Swap anymore (check with free…

  • Former Member
    Former Member over 9 years ago

    If you take away execute permissions from scripts in /etc/init.d they will not run in any runlevel.  So maybe you did not quite hit the right order of things.

     

    sudo chmod -x /etc/init.d/dphys-swapfile

    sudo swapoff -a

    sudo rm /var/swap

     

    Then and after reboot free shows 0 swap.

    efflandt@raspberrypi ~ $ ls /var

    backups  cache  lib  local  lock  log  mail  opt  run  spool  tmp

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • Cancel
  • Kuya.Marc
    Kuya.Marc over 9 years ago in reply to Former Member

    Hi David,

     

    Actually, the problem is with the Element14 SDCardElement14 SDCard, itself. It mysteriously becomes read-only after a month of use.

     

    Marcos

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to Kuya.Marc

    I guess one other thing that should be done to avoid an error when symbolic links in runlevels try to run dphys-swapfile when it no longer has execute permission is to remove the symlinks with:

     

    sudo update-rc.d -f dphys-swapfile remove

     

    Can you still flash a new image to an SD card that became read-only?  If not, make sure that the little write protect switch on left side of SD is pushed away from you towards the contacts.  Some people have also had that issue of flash memory becoming read only in Ubuntu PC Linux, but I never have.  I did corrupt an SD card while overclock testing a Pi, but have never had any SD or other flash memory ever fail to the point that it could not be reflashed or formatted.

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to Former Member

    > make sure that the little write protect switch on left side of SD is pushed away from you towards the contacts.

     

    I don't think this would help at all, since the RPi hardware doesn't connect up

    the write-protect switch, as noted here:

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=10775&start=1

     

    One user suggests editing /etc/fstab to make the file system readonly:

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=10775&start=9

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • Cancel
  • dragonfly.67
    dragonfly.67 over 1 year ago

    With the newest Raspbian Version (on a Pi4 Rev. 1.1 / 4GB) I just changed the the Parameter CONF_SWAPSIZE to 0 in the file /etc/dphys-swapfile. After a reboot there was no Swap anymore (check with free - second line)

    1. sudo nano /etc/dphys-swapfile

    2. change CONF_SWAPSIZE=0

    3. Save and Reboot

    Thats it. This way I don't have to disable the swapservice and in case I would like to change the Swap size later it can be done by just repeating the steps above.

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube