blog-image

Rock64 - Bootp starting

  • dHENRY
  • 13/09/2018
  • (Reading time : 7 mn)

(**) Translated with www.DeepL.com/Translator

I use Rock64-4Gb (manufactured by PINE64) which are much more powerful than a Raspberry Pi 3, not much more expensive, and have an Ethernet Gigabit connection. Starting a Rock64 unit from the network was not as simple as with a Raspberry PI. Documentation, in English only, is very scattered on the Internet. The sources that made it possible to create this document are impossible to quote in their entirety, so much so have I navigated.
To start, a unit needs a bootloader and a Linux system (kernel, commands, etc…). As part of a network startup, the bootloader will be distributed by a TFTP server and the Linux system by an NFS server.

! boot sequence - (c)Mytinydc.com](/images/blog/image-5-5.png)

Boot sequence - (c)Mytinydc.com

The implementation of a network startup service (BOOTP) is the result of a specific configuration of several services. You will need to have these prerequisites:

  • a functional TFP server (DEBIAN package tftp-hpa)
  • a functional DHCP server (DEBIAN package isc-dhcp-server)
  • a NFS server functional.
  • a Rock64 unit, equipped with an SD card on which is installed the ARMBIAN distribution (seehttps://www.armbian.com), and the nfs-common, rsync. packages

_**PS **: The 3 services mentioned above can, of course, be hosted on a single server.

Preparation of TFTP and NFS servers

We will create our two systems, bootloader and Linux, from a unit already started. These systems will only be a copy of the system installed on the Rock64 unit. Therefore I advise you to do this operation from a freshly installed Rock64, without additional packages.

TFTP server

On DEBIAN, the directory “/srv/tftp” is automatically created when installing the “tftp-hpa” package. We will use it to respect this architecture.
The rest of this procedure involves exporting NFS from this directory.
Connected to the TFTP server: **Connected to the TFTP server: **

vi /etc/exports
#Add the line:
/srv/tftp *(rw,sync,no_subtree_check,no_root_squash)

Save, and run:

exportfs -ra

**This NFS export is temporary, I will disable this resource at the end of the procedure.

NFS Server

After obtaining the bootloader from the TFTP service, the unit, booting over the network (the Rock64 unit without SD card) will also need a complete Linux system (kernel, commands, shells, etc…). These files, according to the “bootp” protocol, are available from an NFS server (For more information about NFS,[see Wikipedia article] (https://fr.wikipedia.org/wiki/Network_File_System). **Connected to the NFS server:

mkdir -p /nfs/boot/rock64
# I add to the file " **/etc/exports** " the line 
* /nfs/boot/rock64 *(rw,sync,no_subtree_check,no_root_squash)

Save and export this configuration with the command :

exportfs -ra

(“r” to re-export the configuration, “a” the entire configuration).

Preparation of Bootloader - Linux systems

The /srv/tftp directories of the TFTP server and /nfs/boot/rock64 directories of the NFS server must now be accessible from the Rock64 unit via an NFS link.

NFS access required](/images/blog/image-3-3.png)

NFS access required

Bootloader

Connect the Rock64 unit to the network, boot and connect to its console (root)

# Create a mount point 
mdkir /tftp
# Install the package required for the operation (NFS)
apt-get -y install nfs-common
# Now mount the NFS remote directory of the TFTP server:
mount -t nfs[TFTP server ip address]://srv/tftp /tftp
cp /boot/initrd.img-4.4.4.152-rockchip64 /tftp
cp /boot/vmlinuz-4.4.152-rockchip64 /tftp
cp -r /boot/dtb /tftp/.
mkdir /tftp/pxelinux.cfg

Create the file /tftp/pxelinux.cfg/default-arm, with this content :

Linux-aarch64 label  
kernel /vmlinuz-4.4.152-rockchip64
initrd /initrd.img-4.4.4.152-rockchip64  
devicetreedir /dtb  
append earlycon=uart8250,mmio32,0xff13000000 printk.devkmsg=on panic=10 coherent_pool=1M ethaddr=${ethaddr} eth1addr=${eth1addr} serial=${serial#} hostname=${board}-${serial#} ip=::::${board}-${serial#}::::: root=/dev/nfs rw nfsroot=${serverip}:/nfs/boot/rock64,rsize=32768,wsize=32768 cloud-init=disabled mtdparts=spi32766.0:32k(system),4064k(loader),3840k(reserved),256k(vendor),4M(uboot),4M(atf)

#The "append" line fits on a single line, no carriage return.

Change the permissions of the /tftp directory

chmod -R 755 /tftp/

Final aroma of /tftp

├─── dtb
│ ├── *.dtb
└── pxelinux.cfg
│ ├── default-arm
├── vmlinuz-4.4.152-rockchip64
├─── initrd.img-4.4.4.152-rockchip64

Linux

Connect to the console of the rock64 unit

# Create a mount point: 
mdkir /fsnfs
# Install the necessary packages for the operation (NFS rsync): 
apt-get -y install nfs-common rsync
# Mount the directory saying NFS of the NFS server, on the mounting point: 
mount -t nfs[NFS server ip address]://nfs/boot/rock64 /fsnfs
# Copy the Linux system excluding the directories provisioned at boot from a server and the custom directories of the unit, to the NFS directory (use the command "**rsync**") : 
rsync -rxa --delete --progress --exclude --fsnfs --exclude=var/www/* --exclude=var/log/* --exclude=dev/* --exclude=dev/* --exclude=proc/* --exclude=tmp/* --exclude=root/.ssh/* / /fsnfs/.

chroot in the new Linux system:

chroot /fsnfs

You will find yourself in a complete Linux environment set up on the NFS server. All subsequent commands will impact this environment and not the unit you are currently connected to.
Change the host name of the system by changing the content of “/etc/hostname” (use the vi command). This host name will be identical to all units that start with the network. If you are looking for an alternative solution, please refer to the documentationhttps://fr.wikipedia.org/wiki/Linux_Terminal_Server_Project

#Change the "root" password: 
passwd
# The password you have just changed will be the password to use to connect to the unit by SSH, once the unit is started by the network.
# Modify the file /etc/fstab as follows 
* tmpfs /tmp tmps tmps defaults, nosuid 0 0
# Exit the chroot environment: 
exit

Disabling the NFS export of the TFTP server

I no longer need this resource, the TFTP service is in charge of distributing the files by its protocol. Connected to the TFTP server:

vi /etc/exports
# delete the line: /srv/tftp *(rw,sync,no_subtree_check,no_root_squash)

Save and execute the order:

exportfs -ra

DHCP server configuration

Connected to the DHCP server, you will need to allow “Bootp” in the DHCP service configuration (isc-dhcp-server). Add these lines to the header of the file “/etc/dhc/dhcp/dhcpd.conf”:

allowbootp;
allow booting;
boot-unknown-clients false;

The last line tells the DHCP service to allow network boot only for known hosts, i.e. declared as a “host” in the DHCP configuration.

Restart the DHCP service:

service isc-dhcp-server restart

Preparation of the Rock64 at startup BOOTP/PXE

The Rock64, factory default, does not have the settings for booting from the network card, as many PCs do, you will have to start it a first time and enable this feature.
Source: https://github.com/ayufan-rock64/linux-build/blob/master/recipes/flash-spi.md

SPI Flash Procedure with U-boot image

  • Retrieve the uboot image: https://github.com/ayufan-rock64/linux-u-boot/releases/latest, choose the image “u-boot-flash-spi-rock64.img.xz”
  • Write this image on an SD card. Be careful, this procedure will destroy all the data available on the SD card. According to your system:
  • Windows: rename the downloaded image using the “gz” extension. You can decompress the image with the 7zip tool. Open the Win32DiskImager tool and load the decompressed image. Insert an SD card and use the “Write” button.
  • Linux : use tool xz : xz -k -d -d -c -c -v -T 3[Image name] | dd of=/dev/[device SD card] bs=1M
  • **You don’t need a screen to do this operation. **

Start rock64 by inserting the SD card that has the downloaded image. After starting, your unit will be “flashed”. Wait about 30 seconds and you will see the “Power” LED light up once a second. Disconnect the Rock64 and remove the SD card.

Starting Rock64 from the network

  • Connect the Rock64 to the network switch
  • Remove the SD card
  • Connected to the DHCP server, open a console (root) and execute the command :
tail -f /var/log/syslog
  • At this point you don’t know the MAC address of the Rock64.
  • Turn on the Rock64 unit and look at the logs that appear on the DHCP server console.
  • You get: several lines looking like this:
Sep 10 15:43:43:59 raspi1 dhcpd[27651]: DHCPDISCOVER from xx:xx:xx:xx:xx:xx:xx:xx via eth0: unknown client

## The most important thing here is: **unknown client**. This indicates that the unit is attempting a bootp boot.
  • Finally, add this unit to your DHCP configuration (next chapter)

Adding a host to the DHCP service

Add a block corresponding to the new network host. This is done in the file “/etc/dhcp/dhcpd.conf”

Adapt this setting to your network configuration:

host rock64-1{  
hardware ethernet a7:37:ac:bc:16:0a;  
host-name option "rock64-1";  
DDNS-hostname "rock64-1";  
fixed-address 172.28.28.0.5;   
tftp-server-name option "172.28.0.1";  
next-server 172.28.28.0.1;  
}

**Explanations:
Hardware ethernet line: Indicate the Mac address that appeared in the syslog traces above.
Line option “tftp-server-name” : IP address of the TFTP server
Next-server line: IP address of the NFS server
Restart the DHCP service:

service isc-dhcp-server restart

Bootp start

After completing all the steps in this procedure, restart the Rock64.

Problems encountered

Sometimes Rock64 does not finalize its start, and stops at the loading of the “rk3328-rock64.dtb” driver. Not knowing how to debug this kind of process, I restart the unit by pressing its “Reset” button.

It may also be that the unit does not even reach the first level, the stage where it asks the network for a Bootp start.
In this case you have two solutions:

Conclusion

Your Rock64 is now started without an SD card. The Raspberry PI and Rock64 have the “hotplug” function for the SD card. **Interesting: this will help us for the next post which will be entitled:"Automated installation of new servers (provision of servers)

Document licence : Creative Commons (CC BY-NC-ND 4.0)

THIS DOCUMENTATION IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND AND DISTRIBUTED FOR EDUCATIONAL PURPOSES ONLY. THE AUTHOR, CONTRIBUTORS TO THIS DOCUMENTATION OR ©MYTINYDC.COM SHALL IN NO EVENT BE LIABLE FOR ANY DIRECT OR INDIRECT DAMAGE THAT MAY RESULT FROM THE APPLICATION OF THE PROCEDURES IMPLEMENTED IN THIS DOCUMENTATION, OR FROM THE INCORRECT INTERPRETATION OF THIS DOCUMENT.

(**) Translated with www.DeepL.com/Translator