How can I extend the life of my SD card?

I run 2 commands in sudo su mode, and restart my pi.

What I run:

# swapoff --all
# apt-get remove dphys-swapfile
# reboot

After that, I notice that I can't access to SSH and anything. So I connect to a monitor, pull out/plug in, and the messages says:

[ok] Setting kernel variables .done.
[.....] Configuring network interfaces...

^ THIS TAKE EXTREMELY LONG TIME. And this won't be finished. Just blinking "_". Nothing happened, and I still can't access to anything.

"Configuring network interfaces" stuck I suspect /etc/network/interfaces. I add a line pre-up bash /pifolder/reloadip.sh (Sorry, I forget what I write. But I'm sure reboot works good untill I try swap issue!) ^ This .sh writes tons of IP ranges to iptables.

So, what should I do? I don't want to lose data/config... How can I stop "Configuring network interfaces", so I can install dphys-swapfile again... ( And what command should I run to return back? apt-get install dphys-swapfile only? )

Type B box of Raspbian.

> How big is your reloadip.sh script?
I'm not sure, because it's blocklist.txt is in the pi, and I don't have a backup.
It contains China,Korea,Taiwan,Russia,and other 3 countries. Full range, CIDR format.
> Have you tried running it manually or in post-up?
Of course. Before I try those "swap-remove" commands,
I can do:
# bash reloadip.sh (complete takes about 40 minutes)
# reboot (with no problem)
And I add it in /etc/network/interfaces, to make pi to run reloadip.sh on startup.
I already test it many times, and several weeks passed.
I'm 100% sure that these SWAP-remove command make this thing worse ;(

2 hours has passed since I put the power on... Still showing config netw interfaces.
  • How big is your reloadip.sh script? Have you tried running it manually or in post-up?
    – foibs
    Jan 17, 2014 at 12:26
  • AFAIK, there is no way to stop the pre-up scripts from running at boot time. You have to us a card reader and edit the configuration file from a PC or Mac.
    – foibs
    Jan 17, 2014 at 13:39

1 Answer 1


You went about this the wrong way. If you had simply disabled the service (update-rc.d -f dphys-swapfile) instead, it would be much easier to fix. You could also have just added:

swapoff --all
dphys-swapfile swapoff

To /etc/rc.local.

Then I want you to read this, and if you then are not convinced that the unfounded and absurd concerns about wearing an SD card out on the pi (still floating around the internet) are the product of possibly well meaning but completely delusional, obsessive compulsive minds then read this.1

That said, here's my suggestion for fixing your system. It requires another linux computer with an SD card slot, or SD -> USB adapter, etc. so you can insert the card there.

Take your original raspbian image, or download a new one (dphys-swapfile appears not to have changed in more than a year, so that should be fine). Create a directory, rpi-root, then:

mount -rv -o offset=62914560 -t ext4 raspbian.img rpi-root

I don't think this offset has ever changed as it works with the most recent image I have here, 2013-13-20-wheezy, and previous images. If it doesn't, leave a comment and I'll explain how to figure it out.

Now we need to know what files are required to replace dphys-swapfile. Fortunately I have a running raspbian with it installed, so this is easy:

> dpkg -L dphys-swapfile 

And easy to see that we don't really need most of those, since they're documentation. So copy:


From the mounted image directory into the same paths on the SD card.

There's a catch, though, because the symlinks into /etc/rc.N aren't there. Presuming your default runlevel is 2 -- you can check this in /etc/inittab, look for:

# The default runlevel.

...near the top. Now, cd into /etc/rc2.d on the SD card (or rc- whatever number your default runlevel is) and:

ln -s ../init.d/dphys-swapfile S03dphys-swapfile

Notice the S03 prefix on the link name, very important. You could also put this in all of rc- 2, 3, 4, 5, but not rc-S, since that happens before the specific runlevel directory and dphys-swapfile requires some stuff in there.

That should do it, at least as far as dphys-swapfile is concerned. Once the pi is booted and online you should apt-get install dphys-swapfile.

1. You are free to believe in whatever you want, of course (ghosts, devils, gods, etc), but beyond dubious online anecdotes and the ravings of madmen, all logic, facts, and evidence point to the fact that wearing out an SD card on the pi would require a prolonged, dedicated effort, and the use of a 64 MB swap file is totally insignificant in this regard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.