Monday, 11 August 2014

Banana Pi: Boot your rootfs from SATA

Because the Banana Pi comes with a SATA connector it gives you the possibility to hook up an SSD or other hard drive. Besides it even provides a 5V power connector allowing you to power an SDD right from the board. Just be cautious with the power connector’s polarity, I had to switch the wires of my SATA power cable to get things right!

Move the rootfs to a SATA Drive

Currently it’s impossible to boot from a SATA drive without a SD card. You will still need a small SD card for the bootloader. However, it is possible to adjust the bootscript (which is similar to a bootloader) on the SD card so that it points directly to your SATA drive. This way your system will boot the OS right from the SATA drive.

Here’s what you have to do:

Note: all this commands require root privileges.
  1. Connect your SSD (of course :-) )
  2. run fdisk -l and identify your SATA drive. In this example /dev/sda represents the SSD disk.
  3. Prepare your disk
    > fdisk /dev/sda
    Delete all partitions using the “d” option
    Create a new primary partition using the “n” option (you can accept all the defaults)
    Use the “w” option the apply the changes.
    Format the partition for rootfs with EXT4 filesystem
    > mkfs.ext4 /dev/sda1

Copying Rootfs

I still assume that /dev/sda represent the SATA drive
> mkdir /tmp/1 /tmp/target
> mount /dev/mmcblk0p2 /tmp/1
> mount /dev/sda1 /tmp/target
> (cd /tmp/1; tar --backup -c *) |tar -C /tmp/target -xv
Change the kernel parameters in order to boot from the SSD drive
> mkdir /tmp/boot
> mount /dev/mmcblk0p1 /tmp/boot
> vim /tmp/boot/uEnv.txt
Change the last line to:
.. root=/dev/sda1 ...
Sync to disk and reboot to your hard drive
> sync
> reboot 
You can test the result with: df -h