RPi stripped

These are some options for using a stripped-down RPi when you need the best performance by tailoring what you need to the bare minimum.

Why stripped down? If you want it fast. Fast boot, fast processing, low latency. The RPi is in the order of 100 times faster than 8-bit PIC microcontrollers that I’m used to using, yet most Linux distributions adds a lot of bloat for these kinds of use-cases.

In order from high to low level:

Raspbian: It’s well supported; regular updates and plethora of available packages. Also, packages can quickly be removed as per this previous post, and boot time and other run-time resource hogs can be eliminated as per this previous post.

Why not Arch linux? It’s an option. However, I spent a day just trying to get it to boot, with no luck. It is no longer an option in the NOOBS installer, and having no previous experience with it, and little experience with the RPi, I’d lost before I started.

Start with Raspbian-Ua-NetInst and build it up: If the experience with Arch was too ambitious, then this probably is too. While it is dead easy to install, I wouldn’t want to spend months and months learning with no guarantee of success; I’d want to start with something that just works – even if mediocre – and take it from there. It doesn’t even come with a package manager, and a quick Google search shows that the lack of tutorials for building on it might be a deal-breaker.

Why not MiniBian? ‘Cos I just found out about it.

PiLFS: Probably the lowest level besides bare-metal, but still pretty bulky. It’s not all that clear how much space it would take on the SD card; somewhere between 8MB and 1GB as a minimum??

Why not bare-metal? Are you kidding me? I don’t want to write a Web server, or networking capability from scratch. The reason I’ve decided to use a RPi is to give powerful high-level programming capability to really get stuff done. However, a great tutorial is here: http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/. It is a massive 5-part tutorial which gets you a long way, relatively speaking; great if you just want a quick way of hammering hardware.



Raspbian – resources for reducing boot time

This post will be a work-in-progress. How to reduce boot time of your Raspberry Pi running Raspbian?


First you need to know how long it actually takes to boot up so you can assess your progress.

It has the added benefit of telling you what is happening in that time. Run that command and it will give an output like this:

The number in square brackets on the left is the time since it started up, and whatever is on the right is what is being loaded at that point. I’m not sure what the very last line is about, but the line before that indicates that boot-up time (including ethernet setup in this case) was 22.1 seconds.

Stop stuff being done at boot up

This topic on the Raspberry Pi Forums gives a few ideas for how to speed boot-up time. There are an awful lot of good responses there. Things I’ve tried / will try:

  1. Install rcconf; the Debian Runlevel Configuration tool
  2. Edit /boot/cmdline.txt , add kernel option quiet so boot up log is not printed
  3. In that same file, choose fastboot option which bypasses filesystem check. Supposedly a bad idea though.

Another link: http://rpitc.blogspot.co.uk/p/docs.html

Random hint: some things are never documented. Except in the source code itself. For example, if you have to edit /boot/cmdline.txt , then the only help you will get is by looking at the source.

There are different ways of changing what services are started up during boot-up. I’m not clear what’s supposed to be used when; the complication arises because the way boot-up services are run has changed over the course of Raspbian’s existance. Earlier versions used /etc/inittab but newer versions use systemd . I think this change is why rcconf and sysv-rc-conf don’t work properly; they seem to lose settings on reboot, which makes them useless.

The most successful way I’ve had of reducing boot times is by using  systemd-analyze blame  to show what is taking longest to load. It outputs something like this:

To find out what the services you’re disabling actually do, run this:

And you’ll get an output like this: (Scroll to the right to see the description).

Then disable the individual services as you desire by doing this:

Strip down Raspbian – a collection of what I’ve found

If you want to strip down Raspbian rather than start from the ground up with something like Raspbian-UA-NetInst which really has close to nothing on it, try the below.

It’s unfortunate that developers that offer “server” versions of Raspbian tend to disappear off the face of the planet leaving little more than a husk of a webpage showing that it once existed. So I thought I’d compile a list of reductions that can be run. Mainly for myself, but if it helps you too, then, bonus.

There is probably overlap and so on but I’m sure you’ll figure it out. Many will only help with freeing space on the SD card, rather than help with boot-up time, CPU usage and RAM. But read this post of mine on improving boot time.

PS. If you are the owner of one of the below pages and are unhappy with my inclusion of your commands, please let me know and I will remove them.

Option 1: Remove Packages

And finally, my own little addition, since I discovered that node.js now automatically comes with Raspbian:

Option 2: Raspbian Server Image / Scripts

While the guy who compiled the server edition image has disappeared along with the image, the scripts he used to make it are (at the time of writing), here: https://docs.google.com/file/d/0B1RhPrxJp7gySGljY1c2cFZaMk0/edit.

I have taken the liberty of mirroring it on this blog; click here to download the sirlagz Raspbian Server Edition scripts.tar.gz. Or my .zip version, here: sirlagz Raspbian Server Edition scripts .zip

Other alternatives

From http://raspberrypi.stackexchange.com/questions/14763/how-to-improve-boot-time-for-raspberry-pi, my two favourite answers:

  1. Speed up the boot process using eINIT: https://sourceforge.net/projects/einit/
  2. Read this article at samplerbox.org/article/fastbootrpi which claims to be able to get boot time down to about 8 seconds!
  3. Raspbian-UA-NetInst – a server version of Raspbian
  4. RaspberryPi-UA-NetInst – another server version of Raspbian


How to get a dictator to visit your website

If you’re feeling brave, there are a few easy ways you can get traffic to your website. Just don’t get your hopes up for getting money from it.

Upload a page where you say you have secrets. For example, you could say:

Click here to see what North Korea doesn’t want the world to know.

That’ll get some attention! Or better yet:

Log in here to see secrets of North Korea.

Then watch your hits soar as they try to hack your site.

On the other hand, if your site has water-tight security, you may even be able to get some money out of it…

Click here to buy secrets of North Korea for just $99.

You’ll probably just get one purchase, but every little bit helps towards your funeral costs.

On receipt of payment, you could even have the landing page say something like this:

Dear North Korea,

Congratulations ! Your payment has enabled this website to  upload a Trojan to your computer. As you read this, it is spreading across your computer network, covertly sending anything it finds to ME. Now I actually have something to sell 😉

See you in Den Haag!

Actually, there is one other approach. We all know the Internet boom was funded by porn. And we all know how these dictators plaster images of themselves everywhere, because they think it’s what their people want to see. The truth is they’re just narcissists. So the best way to get one to buy from you might be this:

Click here  to buy a video of Kim Jong-Un masturbating in front of a mirror.

There will only ever be one person clicking on that link, I guarantee it.

I knew it would work! Hiiiii!

It has been a week since I wrote this post. As I write this update, my blog is experiencing a distributed brute-force attack. Starting this morning, I have had over 5000 attempts from nearly 2000 IP addresses to crack my site’s security. Thankfully whoever is orchestrating this will take about a billion, billion, billion, billion, billion, billion years to succeed. I would sooo love it to be the North Koreans! Hellooooooo!

Feeling old? Hit 30 without being depressed

In their 20’s, many people start getting the sense that they’re old. Your best years are nearly over. People younger than you are starting to overtake you – your skills, your wealth, your health. With CEOs as young as 22, Olympic athletes younger than you, fresh-faced hyper-car owners overtaking you, what’s left to be optimistic about?

The solution is simple: remember that it happens to everyone. Everyone sees youth overtaking them, sooner or later. The only people it doesn’t happen to is people who die young. You can be grateful you’re not one of them!

To feel good about yourself and your ageing body and mind, you need to get over the ideals you had when you were younger; the belief that you could take over the world. That you could become better than anyone before you.

That was harsh, it had to be said. But now it’s been said, we can focus on the positives.

Firstly, you have plenty more time to achieve your desires. True; you might not have become CEO at 21, but there’s plenty of time yet.

Second: would you really want to give up the life you have now, for the unknown life had you been an early success? It has been proven that success in itself does not make you happy.

Third: What does make a person happy? If a 90-year-old with a small pension, ailing health and many lost friends and family can be happy, then surely you don’t need to feel bad about not being a spring chicken anymore. The question is how do they do it!

The answer: be at peace with yourself. This is not some new-age spiritual concept. Well, actually it sort of is. But it does not involve meditation (although it can), and it does not involve religion (although it can), and it does not involve happy pills (although it can).

Be proud of who you are

Be proud of what you’ve done. What you’ve overcome.

Remember that you can still make a difference. To yourself and to others.

Remember that everyone’s life eventually comes to an end, but it is not the end. You will have spent your whole life changing the world. Maybe a little bit, maybe more, but you’ve had an impact. You have moved the human race forward, contributed to the well-being of all the people present and future, and every other creature on this planet. There’s still more you can do, today. Seize the day, do something fun. So something amazing. Or just do something.


Why Stack Exchange promotes aggression and hostility

There’s something about stack exchange sites. And it seems to be worst on the larger more established ones like Stack Overflow.

As if the rules weren’t already strict enough, many people try to push it far further. Down votes and close votes on perfectly good questions as defined by rules set out in the help centre.   Snide comments. Nit picking. Some will flatly deny this ever happens, which almost proves the point.

Why does this happen? What about the system encourages this behaviour?  Why were those design decisions taken? What could be done about it? Well, I have some theories. It has been my bugbear for a LONG time. It’s about time I talk about it, so I will outline them in posts to come.

But I believe at it’s core, the issue is this: for a company to be successful, it has to focus on the bottom line; money. And SE’s monly comes from advertising. Which comes from page views. Which comes from high page rank in search engines, which comes from “good content”.

On the one hand, an example of “good content” is well written reference material for common problems. Which SE excels at. But it seems the SE system is designed to completely block any other kind of content, no matter how valuable it may be, either to individuals, people in a field, or Stack Exchange itself.

But because stack exchange has done such a good job of cornering the market as a help site, it has hammered alternatives that would be more flexible than a pure, strict Q&A site.

No discussions. No allowance for questions that need a helping hand when the question itself is hard to formulate into something that can be answered without clarification. (Yes yes… in response to the predictable SE  hardcore criticisms, that’s what comments are for. But that won’t stop you getting down votes and close votes).

What a monstrous creation.

Lol @ String

A piece of string walks into a bar.

Barman: “Are you going to be a problem?”

String: “I’m not a thread”

When to use Front Controller pattern in PHP?

Using the Front Controller pattern in PHP always seemed fairly pointless to me.

I believe that using PHP’s native features with care usually leads to the best code; simple, re-usable components. For example, passing in an object of class ‘MyLogger’ to every object in the system not only ties all the components to using MyLogger, making their use in a system without MyLogger awkward, but the reverse too: any imported code would need to some how be converted to use MyLogger. It’s better to just properly use PHP’s native methods.

The same goes for MVC patterns and so on. Specifically, the front-controller pattern. The paths-to-controller mapping is very effectively done by having one publicly accessible php file for each page, meaning no logic necessary for mapping.

But there was one issue with this that always bugged me. The code in those publicly visible php files, as simple as they may be, (requiring a core bootstrap file and instantiating a couple of objects that do the heavy lifting), were a pain to write automated tests for. Every page would need a test, to check that the cut-and-paste between them had not been broken. Every new page introduced a new weak spot.

But with the Front Controller, all that was reduced to a single page. So there’s the biggest advantage for a front-controller, in my opinion.

Saying that, I don’t think that Front Controller is always the best idea. It can still involve very complex code, or complex debugging. Most who’ve used Apache’s mod_rewrite would agree, I’m sure.

In Martin Fowler’s book, “Patterns of Enterprise Application Architecture”, he points out that it is fine to have a system that uses both Front Controller(s) and Page controllers. There’s a trade-off, and like I’ve heard a thousand times in programming, it ‘depends’. On the requirements, the developers, the technology, and so on. But at least I have now consolidated what to me is the most significant reason for considering the Front Controller, yet why I am unlikely to use it exclusively.


How much will one minute of exercise save the NHS?

Now IMO there’s a good question.

How hard is one minute of exercise? It won’t exactly take you long. About 60 seconds. Go up and down two flights of stairs perhaps.

Now say everyone in the UK did 1 minute more exercise per day than they already do.

I reckon for each minute of exercise that everyone added to their daily routine, the NHS would save in the order of 1 billion pounds every year. I’ve pulled that figure totally off the top of my head, but whether it’s 10 million, 100 million or whatever, doesn’t that make it worth doing?

I don’t vote, because I don’t think one vote can really make a difference. But one minute of exercise might. Maybe I can’t make other people exercise, but I can make a difference to my own health. And if other people read this, who knows, maybe our beloved NHS might stand a chance of surviving. Do we really want to go back to having to pay £15k for a one night stay in hospital? I don’t fancy my chances of staying eligible for affordable healthcare insurance when I reach retirement. I’m only 35, but it’s the one thing that really scares me about the future.

Now we shouldn’t expect everyone to exercise 1 minute more a day – some people cannot. Not just the wheelchair bound; I’m going to stick up for sufferers of mental health problems, to make a point: if one were planing on taking their life, exercise would seem pretty pointless.

But if there is a 10:1 ratio of well to unwell, then just an extra 6 seconds will make up for those who are unable. So, is 66 seconds so much to ask, to look after yourself, the NHS, and the unwell? I think not.

So: Go and do some exercise NOW! Just go up and down those stairs twice. Or 30 pushups, build up those abs and look sexy. Or dig out that awful bush in your garden that you hate. That’s 20 minutes of intense exercise right there! You’ll get a real buzz out of that, I guarantee you. Or do 45 star jumps. Just one minute. For Britain!