This recipe explains how to copy the root filesystem from the SD card to an external disk and boot from it. This is an advanced recipe. You will still require an SD card as the kernel with the necessary filesystem drivers located at the first partition of the SD card.
You may want to move your root filesystem from the SD card to an external drive for performance and/or space reasons. Also when having a lot of I/O operations on the SD card, the SD card may become unstable. A filesystem on a SATA attached disk is more stable in general.
The following ingredients are needed when using an external disk as the root filesystem:
This recipe is split into two subtopics, the preparing (that is formatting) of the external disk and the copying and configuring of the root filesystem.
We need to prepare the HDD or SSD to have at least one formatted ext4 partition.
$ sudo umount /dev/sda*
fdisk
program with the SATA disk as parameter:$ sudo fdisk /dev/sda
p
, you get a list of all the currently available partitions.d
followed by 1
to delete the first partition.d
operation again, until all partitions are deleted.n
followed by 4x
. Press Enter to create a new partition with the full size of the drive.p
again to check whether the partition table is correct.w
to write the changes to the drive. Otherwise enter q
to quit without changes.The following screenshot shows the previous steps done in fdisk
:
$ sudo mkfs.ext4 /dev/sda1
You have created a fresh ext4 partition successfully.
The second step is to copy the whole root filesystem (rootfs) to the external disk and edit the uEnv.txt
file, which contains essential information for the kernel at boot time:
$ sudo mkdir /mnt/boot $ sudo mkdir /mnt/sata_drive
$ sudo mount /dev/mmcblk0p1 /mnt/boot
$ sudo mount /dev/sda1 /mnt/sata_drive
$ sudo rsync -arxP / /mnt/sata_drive/
uEnv.txt
to change the used root:$ sudo nano /mnt/boot/uEnv.txt
root=/dev/mmcblk0p2
. You might need to scroll to the right-hand side by pressing the right arrow key.root=/dev/sda1
:$ sync
$ sudo shutdown -r now
You successfully booted your Banana Pi from the external disk.
The Linux kernel is located on the first partition of the SD card (filename uImage
). When powering the Banana Pi, the boot loader (called UBoot) tries to load the kernel from the SD card. The kernel itself requires some parameters to boot successfully. These parameters and options are configured in the uEnv.txt
file.
When writing the SD card to prepare a Linux distribution for the Banana Pi, the image contains two partitions. The first partition includes the kernel, the uEnv.txt
and a script.bin
files. The second partition is the actual root filesystem. The rootfs contains all the actual programs, configurations, home directories, and so on of your Linux system.
We are synchronizing the rootfs from the SD card to a partition on the external drive using the synchronization tool rsync. The tool rsync is used to synchronize files over a network or on two directories, as in this case. The parameters -a
mean archive (preserving permissions, symbolic links, and so on), -r
recursive (recursive into directories), and -x
is to prevent crossing filesystem boundaries. The parameter -P
shows the progress of each synchronization.
Then we change the desired root from the rootfs of the SD card (that is the second partition) to the partition of the external drive in the uEnv.txt
.
As the boot loader requires the kernel and further information from the first partition of an SD card, the SD card cannot be omitted when moving the rootfs to an external drive.
To use the SD card again as root, you simply mount the first SD card again and change the root option back to root=/dev/mmcblk0p2
.
3.135.62.42