[Tutorial] Full Debian install on eMMC

Personally, i quit using the R4 as a wifi AP, but that doesn’t mean it can’t used for other stuff. Like a NAS, afterall it can support 4 nvme drives or even more SATA drives. Adapters are needed to be able to use the nvme drives on the mpcie or M.2 key-b (4/5G modem) slots.

For the 4/5G modem slot, with a 2280 drive, the heatsink needs to be cut in order to fit the adapter and disk. The adapter will probably be touching the RAM chip. I haven’t tried this tough. For a 2242 disk, only the adapter needs to be cut.

I use these ones:

4/5G slot to nvme: https://aliexpress.com/item/1005005218158216.html

mpcie to nvme: https://aliexpress.com/item/1005005225490121.html

There are 2 kinds of scripts:

  • Custom kernel build
  • Kernel downloaded from Frank-w’s repo. (shorter)

The scripts can be copy and pasted. Variables can be changed. The final image will be installed via ssh. No need for a pen drive.

Custom kernel build
##############   Variables to be set   #################
# Kernel repo in https://github.com/frank-w/BPI-Router-Linux/ (default is 6.12-main)
export BRANCH=6.16-rsslro
# kernel modules to be compiled
export KMODULES="WIREGUARD"
# kernel options to be enabled
export KENABLE="WIREGUARD_DEBUG"
# Extra packages to be installed in the final image
#  bridge-utils  is needed for using bridge  configurations in /etc/network/interfaces, default networking confs are in /etc/systemd/network tough.
export PACKAGES="vim bash-completion bridge-utils hdparm git htop lm-sensors iperf3 chrony"


########   necessary packages for compilation and building    ########
sudo apt install -y git make gcc-aarch64-linux-gnu ccache gcc flex bison u-boot-tools bc libc6-dev libncurses-dev libssl-dev python3 python3-requests parted qemu-user-static debootstrap binfmt-support

#####################   KERNEL   #################
git clone --depth 1  -b  $BRANCH https://github.com/frank-w/BPI-Router-Linux.git
cd BPI-Router-Linux
git config --global --add safe.directory $PWD

###   For the  R4 (just f or confirmation)
echo "board=bpi-r4" >>  build.conf

###   build conf
rm -f ../build/.config
./build.sh importconfig

### Enable extra modules and activate kernel options
for M in $KMODULES ; do ./scripts/config  --file ../build/.config -m   $M ; done
for E in $KENABLE ; do ./scripts/config  --file ../build/.config -e   $E ; done

###   Kernel build with option set to PACK (1), so it's ready for the full image build.
###   Option 1 - Pack
###   Option 2 - Install to SDCARD
###   Option 3 - Create .deb package 
###   Option 4 - Upload

echo 1 | ./build.sh


##########################   Full  Debian image build   #################
cd ..
git clone --depth 1 https://github.com/frank-w/BPI-Router-Images
cd BPI-Router-Images/

###   this is needed otherwise, throws an "file not found error"
wget https://github.com/frank-w/u-boot/releases/download/CI-BUILD-2025-07-bpi-2025.07-2025-07-22_1719/bpi-r4_emmc.img.gz

###   Some settings and kernel package location
cat <<EOF > sourcefiles_bpi-r4.conf
skipubootdownload=1
skipkerneldownload=1
imgfile=bpi-r4_emmc.img.gz
kernelfile=$(ls -t ../SD/bpi-r4*.tar.gz   |  head -1)
userpackages="$PACKAGES"
EOF

###   Build the image (normal if the image is named sdmmc)
sudo ./buildimg.sh bpi-r4 bookworm
Kernel downloaded from Frank-w's repo. (shorter)
################   Variables to be set   ###################
export KERNELVERSION=6.12

###   Extra packages to be installed in the final image
###   bridge-utils  is needed for using bridge  configurations in /etc/network/interfaces, default networking confs are in /etc/systemd/network tough.
export PACKAGES="vim bash-completion bridge-utils hdparm git htop lm-sensors iperf3 chrony"

######################################    Variables END #########################

###  necessary packages for building
sudo apt install -y git python3 python3-requests parted qemu-user-static debootstrap binfmt-support

git clone --depth 1 https://github.com/frank-w/BPI-Router-Images
cd BPI-Router-Images/

###   this is needed otherwise, throws an "file not found error"
wget https://github.com/frank-w/u-boot/releases/download/CI-BUILD-2025-07-bpi-2025.07-2025-07-22_1719/bpi-r4_emmc.img.gz


###   Some settings and kernel package location
cat <<EOF > sourcefiles_bpi-r4.conf
imgfile=bpi-r4_emmc.img.gz
userpackages="$PACKAGES"
EOF

### Full image build with downloaded kernel, syntax is ./buildimg.sh   BOARD   DISTRO   KERNEL-VERSION    STORAGE-DEVICE
sudo ./buildimg.sh bpi-r4 bookworm $KERNELVERSION emmc

It is only possible to install the image on eMMC, from NAND. So boot to NAND, but if no system is installed, Openwrt can be used. Some jumping needed. MicroSD > NAND > eMMC tough.

So first lets boot from microsd with Openwrt

Download Openwrt image and install it on microsd card. Check the device for the microsd card, here it is /dev/sdb. Or just use rufus on windows or other app in mac.

wget https://downloads.openwrt.org/releases/24.10.2/targets/mediatek/filogic/openwrt-24.10.2-mediatek-filogic-bananapi_bpi-r4-sdcard.img.gz

gunzip -c openwrt-24.10.2-mediatek-filogic-bananapi_bpi-r4-sdcard.img.gz | sudo dd of=/dev/sdb status=progress

  • The serial cable should be connected to the R4, the bootswitch set to SD. Terminal software like minicom or putty on windows can be used to see the console.
  • Turn it on so it boots from the microsd.
  • On the boot menu, choose 7. Install booloader, recovery and production to NAND.
  • After it finishes, turn it off and set the bootswitch to boot from NAND, turn it on and let it boot till the end.
  • Configure networking so the R4 is accessible from the compilation machine. For example: ip address replace 192.168.0.60/24 dev br-lan

On compilation machine install debian system image via ssh. The uncompressed image is 7+ GBs, so normal to take around 10 minutes to install to eMMC.

gunzip -c bpi-r4_bookworm_*img.gz | ssh root@R4’S-IP-HERE dd bs=512 conv=notrunc,fsync of=/dev/mmcblk0

Boot to eMMC

  • Power it off (reboot not enough for the bootswitch change). Change bootswitch to eMMC and finally boot Debian 12. Login: root:bananapi

Done. Configure it as you wish. Networking confs are in /etc/systemd/network/ but /etc/network/interfaces can also be used.

Please do comment about possible corrections or additions.