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 uEnv.txt.sd. 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: