RV64 board replacement rootfs guide

XieJiSS, revision 3

This article may not be updated in time, please refer to the RV64 board replacement rootfs guide – archriscv-packages Wiki

0x00 warning

Make sure you or your partner have physical (via serial) access to the board. Otherwise, your board will lose connection at step 6 at 0x02 reboot.

0x01 Preparations

  1. First, go back to the root directory as root:

     1
    2
     sudo su
    cd /
  2. Download the rootfs tarball (make sure wget is installed):

     1
    2
    3
    4
     mkdir new && cd new
    wget curl -O https://archriscv.felixc.at/images/archriscv-20220727.tar.zst
    tar -xf archriscv-20220727.tar.zst
    cd..
  3. Create the old folder in the root directory:

     1
     mkdir old
  4. Take a look at fstab :

     1
     cat /etc/fstab

    It is best to take pictures or screenshots for future reference.

  5. Get the current Linux kernel version:

    First, initialize the script used to extract the kernel version from vmlinuz . vmlinuz is generally located in the /boot directory and requires root privileges to access it.

     1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     kver_generic() {
    # For unknown architectures, we can try to grep the uncompressed or gzipped
    # image for the boot banner.
    # This should work at least for ARM when run on /boot/Image, or RISC-V on
    # gzipped /boot/vmlinuz-linuz. On other architectures it may be worth trying
    # rather than bailing, and inform the user if none was found.

    # Loosely grep for `linux_banner`:
    # https://elixir.bootlin.com/linux/v5.7.2/source/init/version.c#L46
    local kver= reader=cat

    [[ $(file -b --mime-type "$1") == 'application/gzip' ]] && reader=zcat

    read _ _ kver _ < <($reader "$1" | grep -m1 -aoE 'Linux version .(\.[-[:alnum:]]+)+')

    printf '%s' "$kver"
    }

    Execute kver_generic /boot/vmlinuz , remember the Linux kernel version. You can assign it to a temporary shell variable, or you can continue to take pictures and record:

     1
     linux_kver=$(kver_generic /boot/vmlinuz)

    Note that if your current system does not have kernel compression turned on, you may need to change vmlinuz to vmlinux .

  6. Take a look at the addresses of ip addr and router:

     1
    2
    3
     # Here eth0 may need to be modified according to the actual situation, ip addr show can view all devices
    # Generally, the second device of ip addr show is the device we need (the first is the lo local loopback)
    ip addr show dev eth0

    Record the IP of the inet line, which is your current IP address. It will be used later, it is recommended to take pictures or screenshots to keep. (Including the /24 after the IP, if it is not displayed as /24 , then it should be modified to the suffix displayed at this time in the following steps)

    In fact, this step is not needed in theory, just use dhcp. But it seems that the port forwarding of PLCT Nanjing intranet is essentially based on static IP, which relies on the feature that the server will give priority to the released IP after the dhcp client is restarted, which is not stable. It is recommended to configure a static IP in the seventh step of 0x02.

     1
     ip route show dev eth0

    Record the IP address behind the default via , which is the router address of the LAN where your board is located. It is recommended to take photos or screenshots.

    If the target board is not in the PLCT Nanjing intranet, and you do not understand the purpose of the above commands: it is recommended to stop here and discuss the network topology with the mentor before continuing.

0x02 Start to replace rootfs

  1. Record a few key paths (don’t really remember, anyway):

     1
    2
     /new/lib/ # Will be set to LD_LIBRARY_PATH in later steps
    /new/lib/ld-linux-riscv64-lp64d.so.1

    It may be necessary to replace /lib with /usr/lib when the new rootfs is not Arch Linux. See why: The /lib directory becomes a symlink – Arch Linux News

  2. move folder

     1
    2
     mv etc home media mnt opt ​​root srv var old/ # keep /boot here
    mv new/etc new/home new/mnt new/opt new/root new/srv new/var ./
  3. Continue moving folders

     1
    2
    3
    4
     LD_LIBRARY_PATH=/new/lib/ /new/lib/ld-linux-riscv64-lp64d.so.1 /new/bin/mv bin sbin usr lib old/
    LD_LIBRARY_PATH=/new/lib/ /new/lib/ld-linux-riscv64-lp64d.so.1 /new/bin/mv new/bin new/sbin new/usr new/lib ./

    mv old/lib/firmware ./lib/

    /lib/firmware is the firmware path of Ubuntu on Unmatched, which may need to be modified according to the actual situation.

  4. move the kernel modules back

     1
     mv old/usr/lib/modules/$linux_kver ./lib/modules/

    The $linux_kver here is set in the previous step “Get the current Linux kernel version”.

    dtbs, vmlinuz, etc. are all located under /boot , and /boot boot has not been overwritten before, so don’t worry about them at this step. Remarks: Generally speaking, the tar file of the new rootfs does not contain files such as dtbs and vmlinuz. They usually appear in .img or .iso , which is beyond the scope of rootfs, so this article does not explain in detail.

  5. Modify fstab

     1
    2
     echo "LABEL=cloudimg-rootfs / ext4 discard,errors=remount-ro 0 1" >> /etc/fstab
    echo "LABEL=timesyncd-clock /var/lib/systemd/timesync/tmpfs size=1K,rw,nodev,nosuid,noexec,noatime 0 1" >> /etc/fstab

    Note that it may be necessary to modify the first line according to the content of the fstab seen before. For example, if the disk was originally a vfat , you definitely do not want it to be set to read in ext4 format.

    The tmpfs on the second line is because we’re going to enable systemd-timesyncd later, but we don’t want it to affect the life of the hard drive too much. If you don’t care, you can drop this line.

  6. Reboot the machine.

  7. After the reboot it was already Arch Linux. Start configuring network and fstab :

     1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     echo test > test.txt # test / is mounted as rw
    # mount -o remount,rw / # If the previous line reports an error, execute this line, then stop and contact your mentor
    rm test.txt

    Intranet IPv4 address/24 dev eth0 recorded before ip addr add
    ip link set eth0 up
    ip route add default via router address dev eth0 recorded before

    # 114.114.114.114 is a commonly used dns recursive server in China
    echo 'nameserver 114.114.114.114' > /etc/resolv.conf

    systemctl start systemd-timesyncd

    pacman -Syu --noconfirm
    pacman -Syy vim openssh dhcpcd
    systemctl start sshd.service
    systemctl enable sshd.service
    touch .ssh/authorized_keys # Trusted ssh public key, editable with vim

    vim /etc/dhcpcd.conf # Configuration example is as follows. This is limited by the Nanjing intranet topology, and the configuration scheme of static IP is provided.
     1
    2
    3
    4
    5
    6
     # /etc/dhcpcd.conf

    interface eth0
    static ip_address=previously recorded intranet IPv4 address/24
    static routers=router address recorded before
    static domain_name_servers=114.114.114.114
  8. Update the pacman repositories and reboot again.

     1
    2
     pacman -Syu --noconfirm
    # reboot -f, you may also need to press the reset button for Unmatched boards

    If you don’t restart Syu after running, you may encounter many problems caused by “half the upgrade”, such as the kernel module cannot be found, various symbols cannot be found, and so on.

Source: https://blog.jiejiss.com/

This article is reprinted from https://blog.jiejiss.com/RV64-%E6%9D%BF%E5%AD%90%E6%9B%B4%E6%8D%A2-rootfs-%E6%8C%87%E5% 8D%97/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment