This is content I have found from a few sources - I can’t remember who were the authors - so all credit to them. The instructions below have worked for me and I have rebuilt this 5 times now and each time it has worked as expected.
BOOT from HDD/SDD
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:
sudo mke2fs -t ext4 -L rootfs /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:
mount /dev/sda1 /tmp/sata
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:
rsync -arx --progress / /tmp/sata
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
mkdir /tmp/boot mount /dev/mmcblk0p1 /tmp/boot
Now, inside /tmp/boot you will notice a file named boot.cmd 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.
cp /tmp/boot/boot.cmd /tmp/boot/boot.cmd.sd nano /tmp/boot/boot.cmd
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.
cp /tmp/boot.cmd /tmp/boot/boot.cmd.sata
We need to install some tools to manage the boot script (.scr) creation
$ apt-get install u-boot-tools
…and now make copies of the various boot scripts so you can switch between them easily if needed.
- $ cd /tmp/boot
- cp boot.scr boot.scr.sd
- $ rm boot.scr
- $ mkimage -C none -A arm -T script -d boot.cmd boot.scr
- cp boot.scr boot.scr.sata
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:
[email protected] ~ # df -h
Filesystem Size Used Avail Use% Mounted on rootfs 230G 1.6G 217G 1% / /dev/root 230G 1.6G 217G 1% / devtmpfs 486M 0 486M 0% /dev tmpfs 98M 224K 97M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 195M 0 195M 0% /run/shm
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 boot.scr with a copy of the boot.cmd.sd. And you can do the same with the boot.scr.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).
fstrim -v /
This should return an output of bytes were trimmed. Then let’s add a script to run daily as a cron job:
and inside put paste the following script:
#!/bin/sh LOG=/var/log/trim.log echo “*** $(date -R) ***” >> $LOG fstrim -v / >> $LOG
and make that script executable:
chmod +x /etc/cron.daily/trim
And that’s it! You should see a log of the script running anytime using this command: