NekoMio

NekoMio

telegram
github

Install Debian 11 system on Loongson 3A2000C.

Intro#

I saw someone on Bilibili saying that the motherboard (with CPU) of the Loongson 3A2000C is very cheap. I checked on Xiaohuangyu and it's 36 yuan with free shipping. The motherboard comes with a CPU and a heatsink, and it also has 4 SATA ports. So I directly ordered a motherboard + 4GB RAM kit for 51 yuan with free shipping, thinking of playing around with it.

System Installation#

Since this thing is already very old, there isn't much information online. The main references I found are two webpages: 3a2000 Installation and Usage - LA UOSC and Installing Debian 11 on the Great Wall Loongson 3A2000C Platform.
However, at the time of writing this article (2023-11-27 14:55 UTC+8), the second website seems to be inaccessible.

I heavily referenced the snapshot content of the second article to install Debian 11.

Here, I will also record my own installation process.

1. Prepare a LiveCD for booting#

Download the supported installation image for the system.
The official download link for the Loongson 3A2000C installation image is as follows:

http://ftp.loongnix.cn/os/loongnix/1.0/liveinst/old/loongnix-20190331.iso

2. Create a USB drive for installation#

In a Linux environment, use the following command:

cp loongnix-20190331.iso /dev/sdb   # Assuming sdb is the USB device, do not use the file system sdb1, use the device directly

In Windows, you can use Win32ImageWriter to directly write to the USB drive.

3. Install the initial operating system#

Install the system normally using the official system image. I only used the simplest partition layout:

/boot  ext4 partition, size 500M
swap   swap partition, recommended to be the same size as the memory
/      ext4 partition, remaining space

To be honest, it might be because of the USB drive, but the response speed of this system is really slow.
After the normal installation is completed, unplug the USB drive, restart the system, and confirm that it can be used normally.
The current system is based on Fedora 21, and the kernel version should be 3.10.x. The requirements are not high, but it can still be used normally.
In this article 3a2000 Installation and Usage - LA UOSC, it is mentioned that the Loongnix-20.mips64el.rc2 system can also be used normally, but when I wrote the system to the USB drive, it did not start up properly, and I don't know what the problem is.

4. Install Debian 11 via network#

Boot into the installation environment again using the USB drive, but this time, do not install. Open the terminal.

Create a mount point for the temporary environment

sudo su
mkdir /mnt/deb

Mount the root file system on the target hard drive

mount /dev/sda3 /mnt/deb    # Assuming /dev/sda3 is the root file system

Delete all files on the target file system

rm -rf /mnt/deb/*

Rebuild the file system structure of Debian using debootstrap
Since we want to install Debian 11, we need to use debootstrap for Debian 11.
You can download the debootstrap script adapted for it from here:
http://ftp.cn.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.123+deb11u1_all.deb

Since the official operating system of the current LiveCD is based on Fedora and does not have the dpkg command, we need to manually extract the deb file and place the files in the correct location.

ar -x debootstrap_1.0.123+deb11u1_all.deb
tar xvf data.tar.xz
cp -rv usr /   # After extracting the data package, copy the usr directory to the system

Use debootstrap to rebuild the file system structure of the target system

debootstrap --arch mips64el bullseye /mnt/deb http://mirrors.tuna.tsinghua.edu.cn/debian

Copy the official kernel modules to the target system

cp -r /lib/modules /mnt/deb/lib/

Mount other file systems

mount /dev/sda1 /mnt/deb/boot       # Assuming sda1 is the boot partition
mount --bind /sys /mnt/deb/sys
mount --bind /proc /mnt/deb/proc
mount --bind /dev /mnt/deb/dev

Chroot into the target environment

LANG=C.UTF-8 chroot /mnt/deb /bin/bash

Change the root password

passwd root

Modify the installation source

cat >/etc/apt/sources.list <<EOF  
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF

Update the sources and install some basic software

apt-get update
apt-get install wget openssh-server locales network-manager grub-common curl vim

Install the kernel

apt install linux-image-loongson-3 linux-headers-loongson-3 linux-libc-dev

Install the drivers

apt-get install firmware-linux-free firmware-linux-nonfree

Modify the configuration of the target system
Change the hostname

echo 'myhostname' > /etc/hostname
vim /etc/hosts           # Add myhostname after 127.0.0.1 localhost

Configure fstab
Use blkid to get the UUID of the file systems
Running the command will give output similar to the following:

/dev/sda1: UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="198e62aa-01"
/dev/sda2: UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" TYPE="swap" PARTUUID="198e62aa-02"
/dev/sda3: UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="198e62aa-03"

Modify /etc/fstab

Refer to the following configuration to modify fstab

# UNCONFIGURED FSTAB FOR BASE SYSTEM
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX       /       ext4    defaults,noatime        0       1
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX       /boot   ext4    defaults,noatime        0       2
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX       none    swap    defaults                0       0

Localization configuration
Configure locales

dpkg-reconfigure locales

It is recommended to install the following locales

en_US.UTF-8
zh_CN.UTF-8

Select en_US.UTF-8 as the default locale

Configure the time zone

dpkg-reconfigure tzdata

Select Asia and Shanghai in order

Create a new user
Create a user

useradd -m -s /bin/bash myuser
passwd myuser

Install sudo and add the user to the sudo group

apt-get install sudo
usermod -a -G sudo myuser

Rebuild the initramfs
Modify the initramfs-tools configuration to load only the necessary modules

vim /etc/initramfs-tools/initramfs.conf

Find the line MODULES=most and change it to MODULES=dep

Recreate the initramfs

update-initramfs -k 5.10.0-26-loongson-3 -u -v # Note the version here

Modify the grub configuration /boot/grub.cfg

This configuration file originally had two boot configurations for the 3.10 kernel, configured as options.

But in my test, the countdown auto-start of grub doesn't seem to work properly, so I commented out the original two boot options and made grub directly boot using the kernel I configured below.

    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msd$
    else
      search --no-floppy --fs-uuid --set=root XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    fi
    echo    'Loading Linux 5.10.0-26-loongson-3 ...'
    linux   /vmlinuz-5.10.0-26-loongson-3 root=/dev/sda2 ro rhgb quiet loglevel=0 LANG=en_US.UTF-8
    initrd /initrd.img-5.10.0-26-loongson-3
    boot

It's difficult to explain this part, so I suggest studying the grub configuration file yourself.

Replace XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX with the UUID of your root directory.

Restart and test
Exit the temporary environment and restart

exit
shutdown -r now

After the system starts, check the kernel and operating system version information

uname -a
cat /etc/debian_version

Post-Installation Configuration#

I plan to use this machine as a NAS, and the specific configuration process can be found in the next article

Loongson 3A2000C NAS Configuration

Special thanks to
Installing Debian 11 on the Great Wall Loongson 3A2000C Platform http://geek-logic.com/debian-11-on-loongson/

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.