Skip to content

Instantly share code, notes, and snippets.

@larsch
Created October 10, 2020 10:48
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

@jpamills
Copy link

Thanks - it worked for me! I had a bit of trouble working out how to dd the exact sectors, but I got it close enough that I could delete the incomplete partition from the Armbian image and make a new ext4 partition. For now, I think I'll stay on the Armbian kernel and get on with configuring the system.

@ytskuh
Copy link

ytskuh commented Jul 6, 2021

I failed at step 6 in Prepare sd-card/image... The system seems to be booted since the sys and wan lights are on, and my route has shown the device, but it even doesn't open ssh port... I can't figure out what's wrong and what can I do.

@rm1138
Copy link

rm1138 commented Jul 19, 2021

@sddred

I encounter a similar problem when I following this guide to install Archlinuxarm on R4S.
Try to add the following line to /etc/fstab.

UUID=........       /               ext4            rw,relatime,data=ordered,noatime   0 1
tmpfs   /tmp         tmpfs   nodev,nosuid            0  0

On my device, the root fs become read-only and blocking the SSH key generation, which makes the SSH service unresponsive to the external connection.

@ytskuh
Copy link

ytskuh commented Jul 23, 2021

@rm1138 Thanks a lot, it works.

@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

@eehlers
Copy link

eehlers commented Feb 3, 2024

Thank you, that part is now working for me. I am still stuck though. I prepare the micro SD card on my Ubuntu laptop. Then I insert it into the NanoPi R6C. At startup I get some red error messages, they scroll by too fast to see. Then it prompts me for the alarm login. Then it hangs.

Edit: I connected to the serial port to see the error messages which appear at startup, the first one is:

[FAILED] Failed to start Network Time Synchronization.
See 'systemctl status systemd-timesyncd.service' for details.

Below are the steps that I take on the Ubuntu laptop to prepare the micro SD card. If anyone has any insights I would be grateful.

wipe the micro SD card

$ sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M

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).

$ sudo dd if=Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img of=/dev/mmcblk0 skip=31 seek=31 bs=512 count=32736

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

sudo fdisk /dev/mmcblk0
# (create partition)
$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 119.08 GiB, 127865454592 bytes, 249737216 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: dos
Disk identifier: 0x6f0526c2

Device         Boot Start       End   Sectors   Size Id Type
/dev/mmcblk0p1      32768 249737215 249704448 119.1G 83 Linux

Create the ext4 file system

$ sudo mkfs.ext4 /dev/mmcblk0p1

and extract ArchLinuxARM-aarch64-latest.tar.gz to the new partition.

$ sudo mount /dev/mmcblk0p1 mnt_arch
$ sudo bsdtar -vxpf ArchLinuxARM-aarch64-latest.tar.gz -C mnt_arch

Copy the contents of /boot from the armbian image to /boot on the new
patition.

$ 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

# 32768 * 512 = 16777216
$ sudo mount -o loop,offset=16777216 Armbian_23.11.1_Nanopi-r6s_bookworm_legacy_5.10.160.img mnt_armb
# move the old arch /boot directory out of the way
$ sudo mv mnt_arch/boot mnt_arch/boot.arch
# copy the contents of the armbian boot partition into a new arch boot directory
$ sudo cp -r mnt_armb mnt_arch/boot
$ sudo umount mnt_armb

Edit the /boot/armbianEnv.txt to point to the new partition either by UUID or
device name (rootdev=/dev/mmcblk0p1)

$ sudo vi mnt_arch/boot/armbianEnv.txt
$ cat mnt_arch/boot/armbianEnv.txt
verbosity=1
bootlogo=false
overlay_prefix=rockchip-rk3588
fdtfile=rockchip/rk3588s-nanopi-r6s.dtb
rootdev=UUID=7974c564-137e-431d-bcf9-88db1c50824f
rootfstype=ext4
$ sudo umount mnt_arch

Boot and follow ArchLinuxArm standard procedures for installation.

-> NanoPi R6C startup displays errors (which scroll by too fast to see), then it prompts me for the alarm login, then it hangs.

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