Raspberry Pi {Self} Maintenance

After all the work that you have done to bring to life your Raspberry Pi project you don’t want the following things to happen: * Update your system if everything

7 years ago

Latest Post The Great Escape Tunnel by Mario Esposito public

After all the work that you have done to bring to life your Raspberry Pi project you don’t want the following things to happen:

Everything Works

The old say goes “if it works don’t touch it!” - That piece of wisdom is as real as popular. Especially when you have DYI hardware involved in the mix. The open-source community is ultra awesome but also evolves very quickly occasionally/often (your call here) careless about dependencies and reliability on backward compatibility. Therefore, if your project works, and you are happy with the service that it provides to you, refrain from touching it or update anything on the software end or your weekends are going to be booked just to go back to where you were before.

SD Card Failure

Card failure can happen and when it does, it super sux. I recommend two things in this horrific event.

Backup regularly and keep two copies of different time frames as if you create an image of already a compromised system that doesn’t yet show signs of issues you won’t find a good recovery point in time for the restore. Sort of manual time machine backup system of OS X.

The other clone your SD card so when a disaster happens you don’t have downtime while you fix the faulty card. SD cards nowadays are pretty cheap, so this is very doable.

Backup and Cloning

To back up, stick that SD card in your Mac and open Disk Utility then follow those steps.

If you feel that the UI slows you down, you can do that task through the command line, and here you will find there a well-written step by step process for that. Thanks, Johnny!

To clone, after you create your DMG image just deploy it on your second card, and you are good to go.

Keep It Posted

If your RPi is exposed to the Internet, family members rely on your geek project and so on you want to make sure that the system is kept up to date with the latest and greatest. From the security point of view, there’s plenty available already out there, I looked at this, and this and I found them useful.

The following steps are what I do to keep the system up to date; every scenario is a big different but those steps below are common sense for most cases.

One Time Operation

Make sure that timezone and the proper tools are installed to help the process below. Run the following commands:

sudo apt-get install arduino rpi-update ca-certificates ntpdatesudo ntpdate -u

And then launch the update phase with the following commands

sudo apt-get update
sudo apt-get upgrade

Automatic updates

If you want to automate these procedures, it can be done by configuring apt’s Periodic options. The Raspberry Pi comes with apt installed, and as part of that package, an automated script is installed (in /etc/cron.daily/apt) for doing automated updates on a daily basis using the Cron daemon.

These may be controlled by creating (as root) a file /etc/apt/apt.conf.d/10periodic putting the following into it:

APT::Periodic::Update-Package-Lists “1”;
APT::Periodic::Download-Upgradeable-Packages “0”;
APT::Periodic::AutocleanInterval “0”;
APT::Periodic::Unattended-Upgrade “0”;

This configuration will just run update every day for you so when you run

sudo apt-get upgrade

You’ll install the latest packages without having first to run apt-get update.

Automatic upgrades
To configure apt to upgrade automatically packages as well - firstly you’ll need to install a new package to make the unattended-upgrades work:

sudo apt-get install unattended-upgrades

Then you change the following option to “1” in /etc/apt/apt.conf.d/10periodic to enable automated upgrades:

APT::Periodic::Unattended-Upgrade “1”;

For more details see the comments inside the /etc/cron.daily/apt and then put the relevant options into the /etc/apt/apt.conf.d/10periodic file.

Boot Up Right

If you have the self-update trick running explained above along with some other script/programs running when the system boots, to remove your churn of doing it semi/manual you can leverage upstart. To install it use the following:

sudo apt-get install upstart

To get this properly installed as it replaces sysvinit, that can potentially cause the device to stop working if things go wrong. Therefore, as soon as installation finishes:

sudo halt

Wait until it shuts down, remove the power and wait a few seconds before powering up again. Next create the script that starts your things. In my case I have a Redis server (and restarts it on a crash as well):

Clean Up

Occasionally all these updates they pile up temporary files or comforting junk, you can save some disk space running the following command

sudo apt-get autoremove scratch here_name_of_what_to_remove

Or you can use a more generic one to remove everything

sudo apt-get clean

That all I know at the moment and what has been helpful to me with my projects. Good luck!


Mario Esposito

Published 7 years ago