Skip to content

Instantly share code, notes, and snippets.

@larsch
Created October 10, 2020 10:48
Show Gist options
  • Save larsch/a8f13faa2163984bb945d02efb897e6d to your computer and use it in GitHub Desktop.
Save larsch/a8f13faa2163984bb945d02efb897e6d to your computer and use it in GitHub Desktop.
Installing Arch Linux AArch64 on the NanoPi R2S

Installing Arch Linux AArch64 on the NanoPi R2S

There is current no support for the NanoPi R2S in ArchLinuxArm, but it's possible to run it using the generic aarch64 installation.

Prepare sd-card/image

  1. Copy bootloader and uBoot from an armbian image using for the NanoPi R2S using dd (sectors 32 to 32767) everything before the partition, except the partition table).
  2. Create an ext4 partition on /dev/mmcblk0p1 at offset of 32768 sectors (16384 KiB):
Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1      32768 15523839 15491072  7.4G 83 Linux
  1. Create the ext4 file system and extract ArchLinuxARM-aarch64-latest.tar.gz to the new partition.
  2. Copy the contents of /boot from the armbian image to /boot on the new patition.
  3. Edit the /boot/armbianEnv.txt to point to the new partition either by UUID or device name (rootdev=/dev/mmcblk0p1)
  4. Boot and follow ArchLinuxArm standard procedures for installation.

Kernel

You can boot with the armbian kernel (currently 5.7.15), or chose to install the arch linux stock aarch64 kernel (linux-aarch64). If you install the stock kernel, a new DTB is needed or USB 3.0 and the secondary ethernet won't work. It works with the rock64 DTB since it has the same Ethernet controller:

ln -sf /boot/dtbs /boot/dtb

Change /boot/armbianEnv.txt to have fdtfile=rockchip/rk3328-rock64.dtb.

Create an uBoot image of the initramfs:

pacman -S uboot-tools
mkimage -A arm64 -T ramdisk -n uInitrd -d /boot/initramfs-linux.img /boot/uInitrd-initramfs-linux.img
ln -sf /boot/uInitrd-initramfs-linux.img /boot/uInitrd

And install a pacman hook to ensure that this is done every time the kernel is upgraded:

mkdir -p /etc/pacman.d/hooks

/etc/pacman.d/hooks/initramfs.hook

[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux-aarch64

[Action]
Description = Generate uInitrd
Exec = /usr/bin/mkimage -A arm64 -T ramdisk -n uInitrd -d /boot/initramfs-linux.img /boot/uInitrd-initramfs-linux.img 
When = PostTransaction
Depends = uboot-tools

Serial Gadget

systemctl enable serial-getty@ttyGS0
echo g_serial > /etc/modules-load.d/g_serial.conf

SD-Card layout

Sector Purpose
0 MSDOS partition table
64 Loader
16384 uBoot
32768 ext4 partition

References

https://wiki.friendlyarm.com/wiki/index.php/NanoPi_R2S

https://wiki.archlinux.org/index.php/NanoPi_NEO_Plus2

@eehlers
Copy link

eehlers commented Feb 1, 2024

I am having trouble following this howto and I would be grateful for some help. I am trying to install to the R6C. The first step is:

Copy bootloader and uBoot from an armbian image using for the NanoPi R2S using dd (sectors 32 to 32767) everything before the partition, except the partition table).

What is that telling me to do, exactly? Copy what to what? I downloaded the armbian image for the R6C/R6S, this is what I see:

$ fdisk -l Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img
Disk Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img: 2.41 GiB, 2583691264 bytes, 5046272 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 48FD0898-A4A4-8043-BB0A-F366B8DB80C9

Device                                                    Start     End Sectors  Size Type
Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img1  32768  557055  524288  256M Linux extended boot
Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img2 557056 5046238 4489183  2.1G Linux filesystem

What am I supposed to do?

@ytskuh
Copy link

ytskuh commented Feb 2, 2024

@eehlers Copy the data on the block device, before the partition. You may achieve this using dd like

# dd if=Path_to_your_img of=/dev/sdX skip=31 seek=31 bs=512 count=32736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment