Moving Bananian to SATA HDD

WD Scorpio Black 250GBSo, there are two big drawbacks when using SBC like Raspberry Pi and Banana Pi. The speed of the SD cards, as well as the lifespan of them in case you write data to them often(like in our case we will keep our database there). Thankfully Banana has a great feature; a SATA controller! And while you can move almost everything to your SATA drive, you still need the SD card as the boot partition has to be there. The read/write speed gain is also quite impressive when Bananian(or whatever other linux distro you have). In my case, and since I had a spare 32GB Apacer SSD and a spare 250GB WD Scorpio Black 2.5″ HDD, I moved my OS on both just in case, but I plan to use the HDD mostly because it doesn’t need TRIM(I’ll show you how to add TRIM for your SSD though in the end of this post). Also, to keep the cost to a minimum, I cut down the end of a SATA power cable from an old PSU, as well as the 2 pin power from a useless fan I got together with my RasPi(that I never used since it was too loud and I didn’t need it anyway) and connected them together. Add a spare SATA data cable and there is my setup, with no extra cost.

EDIT: Just as a note, you will need much more power for Banana Pi to power up the SATA drive. It turns out a chinese 2A charger that I had for my tablet isn’t powerful enough for the HDD, but it can power just fine the SSD(it should be giving way less actually). So I’ll stick with the SSD for now. A genuine Iphone 5 1A charger isn’t giving enough juice to boot even with the SSD(all the above with just the ethernet and the SATA drive connected, no WiFi dongle, no HDMI, nothing).

Prepare the partitions

So, first thing first, power down your Banana Pi and connect the cables. If you make a custom power cable like me, be careful of the polarity. The pin next to the micro USB that powers the Banana is the +5V while the other one on the edge is the ground. Power up the Banana again, SSH into it and…

That should give you a list of the disks connected to your Banana. You will most probably see a disk /dev/sda, and that is what you want. From here on you will need to delete all partitions from your hard drive, so don’t continue unless you backup any data you might have in there. Once you are ready to proceed…

There are several options there. You will need to delete all partitions and then make a new one. So the options you should select are:

If there are multiple partitions, first delete partition 1(type 1 and enter). Repeat the process until all partitions are gone. Then to write the partition table changes:

Let’s enter the partition manager again:

Create a new partition:

and make it a primary one:

Enter 1 as the partition number and select the default values of start and end sector(simply press enter), and at the end write the changes to the partition table:

Now to format our new partition to ext4 and mount it as /dev/sda1:

Copy the OS to the SATA drive

Now to copy everything to our hard drive. First, we need a temporary mount point where we will mount our SATA drive:

and let’s copy everything. That should take a few minutes, depending on your SD card, your SATA drive and how much data there is to copy:

Prepare the Boot partition

Once the copy is over, let’s prepare the boot partition so that the Banana will use the SATA drive.

First of all, mount the boot partition

Now, inside /boot you will notice a file named uEnv.txt which is the file we need to change. In order to have easy access to our SD card in case something goes wrong, let’s first of all make a copy of this file and then change its contents.

See the part of the file that reads root=/dev/mmcblk0p2 and change it to root=/dev/sda1 and then save the file and exit the editor.

And let’s make a new copy with the settings for the SATA drive so we can easily swap between these files anytime we want.

Synchronize the drives using

and reboot. Voila, when the Banana Pi boots again you will see that you are using your SATA drive instead of the SD card. To check it, you can try to run this command:

Notice how my rootfs is 230GB.

Now, in case anything goes wrong, you can go back to the OS on the SD card by simply placing your SD in a card reader and overwriting uEnv.txt with a copy of the And you can do the same with the uEnv.txt.sata in case you want to use your SATA drive again.

Before I close this post, I’ll add some information on how to use TRIM if you are to use an SSD.

Use TRIM with your SSD as a cron job every day

First of all, check if you have fstrim in your system(which you should).

This should return an output of <random number> bytes were trimmed. Then let’s add a script to run daily as a cron job:

and inside put paste the following script:

and make that script executable:

And that’s it! You should see a log of the script running anytime using this command:




Basic Banana Pi setup – Bananian, Nginx, MySQL, PHP, Node.js, Node Red

So, let’s start from the basics. A basic setup of Bananian Linux, along with the stuff we will probably need to have installed so we can play with them(Nginx, MySQL, PHP, node.js, node red).

Bananian Linux

This is my favourite Linux distribution, since it has just the basics for a headless setup. It has a special feature that while it is considered bad, it is good as it saves you some headaches if you don’t know much about linux. The default user is root, so you have complete access at everything and no need for sudo. Just be careful to have a good strong password and don’t experiment with anything stupid.

Go and download the latest version from the official site

Burn the image file to your SD card following the instruction on that website, that has to be at least 2GB. I used an old 2GB SD card since I will soon move my installation to a 2.5″ HDD. 2GB might not seem much, but after installing everything mentioned above I still get 300+ MB free.

Place the SD card in the Banana, connect a keyboard and a monitor, and wait for the first boot. Login with root/pi and run bananian-config for some basic changes. CHANGE THE PASSWORD, set your correct timezone and locale, change if you want the hostname, leave video acceleration disabled and ideally expand the filesystem.

Now, there is one more thing we need to do. Set a static IP for your local network. For that, do:

comment the lines about DHCP, uncomment and set a static IP address and it should look something like this:

where address is the static IP you want your Banana to have, gateway is your router’s IP address and netmask should probably be anyway.

Once you have done all these, remove the keyboard, remove the monitor, just leave the power and ethernet cables on and reboot your Banana. From now on you can access it through SSH so download PuTTY or whatever and let the fun begin. So login through SSH to your Banana and let’s…

Install Nginx

Nginx(pronounced engine-x) is an open source lightweight web server. While Apache2 seems more popular, now that resources are limited we will need to have as many of them as possible available for our use.

Before we install anything, let’s do a

and then

We can start the server with

and to test that it works, open a browser, enter the IP address of the Banana and you should see a welcome message.

Install MySQL

While for our purposes a NoSQL database might work better, MySQL is so widely used it will be useful at some point. To install it:

During the installation script, you will be asked for a password for MySQL’s root user. Do that! Then, for some advanced MySQL security:

Read carefully all the questions and answer them promptly.

Install PHP

For PHP to run under Nginx, you will need PHP-FPM.

Also, for PHP to work with MySQL you will need

You can speed up PHP by setting up a cache that stores the already compiled PHP pages.

Configure Nginx

To get PHP working properly under Nginx, we will need to make a few changes to the configuration file.

You should uncomment some lines and the result has to be like this:

Show more...


Finally, one change must be done to the php.ini file.

and set the “cgi.fix_pathinfo” parameter to 0.

Now restart your Nginx with

and test if all is done correctly by making a test.php file

where you put the following code

Save the file with the name test.php and if you open in your browser the <Banana-pi-IP-address>/test.php you should see something like this:


Install Node.js

Node.js is required from Node Red, so we have to install it first. For ARMv7 processors this is what we have to do:

Install Node Red

Before installing Node Red if you had an earlier Node.js installation it is a good idea to…

Now it’s time to install Node Red.

You will see tons of warning and gyp errors that you should ignore. You will probably also see an error about the Bananian OS, that you should ignore also. After about 5 minutes, you will have Node Red installed on your Banana.

To start Node Red you can run the following command(and change the size of RAM in MB that Node Red will use from 128 if you want):

You can open your browser, go to <Banana-pi-IP-address>:1880 and you should see Node Red running.


To have Node Red start on boot, you can install PM2, a process manager for Node.js.

You can have Node Red autostart by placing the following commands:


Welcome – Planning the setup

postSo this is my new blog, where I hope to put in detail what I am about to do about this new obsession of me. Home automation, and the Internet of Things in general, seems to be the future and eventually we will have cheap web-connected stuff all over our houses. But until then, and for the fun of DYI, I will try to make a decent home automation system, and if you are interested you can find details on how to go on yourselves.

At the first steps I thought I’d go for a Raspberry Pi as a server and several Arduinos scattered around the house. The ideal system would be first of all cheap(and then wireless), and the cost of wireless Arduinos is pretty high. Until ESP8266 came out and it was revolutionary! For a couple of bucks you could get an arduino on steroids with Wi-Fi connectivity! I quickly ordered a few of them(still waiting for them to arrive), and I was about to make my RasPi B+ something more than a Kodi/torrentbox machine, when I saw the limitations. mainly in the RAM and CPU departments.

About that time RasPi 2 came out and seemed like a good option. I was about to order it when I searched a bit and I found something cheaper, and while slightly less powerful in terms of CPU power, it had several other features that seemed to be useful. The Banana Pi!

Now, there are a few models of that Banana out there, but even the first one seems more than capable for what I want it to do. It has a dual core ARMv7 CPU, 1GB RAM, SATA port and Gigabit ethernet! Basically it’s way better in all aspects than all Raspberry Pis apart from model 2, but two. One is that the support community is really small(nowhere near the RasPi community) and that the GPU is bad. Not bad really, but with bad drivers and so, for example, it performs worse than a RasPi B+ as a media center. But I don’t care at all for the GPU for what I want to do with it. As a matter of fact, there is an OS image(Bananian OS) that has just the basic that you need for a working system and you can start building on that with just the essentials. After installation it takes just 25MB of RAM, leaving everything else available for whatever you want to do with it.

So, enough chit chat, in the next posts you will find details on my progress, and since tutorials for the Banana Pi are rare, I’ll provide some information on how I setup the Bananian as well.