Table of Contents
- Hi3798MV200 Entu N2 NS-1 (1): Device introduction and flashing instructions
- Hi3798MV200 Entu N2 NS-1 (2): HiNAS use and modification
- Hi3798MV200 Entu N2 NS-1 (3): Make Ubuntu rootfs
- Hi3798MV200 Entu N2 NS-1 (4): Make Debian rootfs
About Debian rootfs
Debian does not provide a packaged rootfs like Ubuntu provides Ubuntu-Base, but Debian provides a tool for making rootfs debootstrap. The following describes the process of using debootstrap to make Debian rootfs.
Debootstrap initialization phase one
install debootstrap
sudo apt install debootstrap
Prepare a working directory, such as workroot, for initialization. Be sure to add mirror, otherwise it will be very slow
sudo debootstrap --arch=arm64 --foreign buster workroot/ http://mirrors.ustc.edu.cn/debian/
Copy qemu-aarch64-static to the target system, if not, install it first sudo apt install qemu-user-static
sudo cp /usr/bin/qemu-aarch64-static workroot /usr/bin/
Check if it works normally
sudo chroot workroot/ /usr/bin/qemu-aarch64-static /bin/ls
prepare resolv.conf
echo "nameserver 127.0.0.53" | sudo tee workroot /etc/resolv.conf
debootstrap initialization phase two
chroot into the target system
sudo chroot workroot/
Initialization of the second stage
/debootstrap/debootstrap --second-stage http://mirrors.ustc.edu.cn/debian/
If the initialization is successful, you can see I: Base system installed successfully
Installation settings
Install basic software
add Debian apt source
cat <<EOT> /etc/apt/sources.list # Enter the following in turn deb http://mirrors.ustc.edu.cn/debian buster main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian buster main contrib non-free deb http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free deb http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free deb-src http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free EOT
check is correct
cat /etc/apt/sources.list
Finally execute apt update
update, apt upgrade
upgrade
Install some basic software, after this step the system size is 434M
apt install locales dialog
Configure locales, choose en_US.UTF-8 UTF-8, en_US.UTF-8
dpkg-reconfigure locales
Go ahead and install some software
apt install vim-tiny openssh-server sudo ifupdown net-tools udev iputils-ping sysstat smartmontools
Add driver file
Rootfs can be started only by using the built-in driver of the kernel, but some onboard peripherals, such as SATA hard disk and USB, will not be recognized because there is no driver. These drivers need to be manually put into rootfs.
Through uname -r
, you can see that the architecture of the target system is 4.4.35-hi3798mv2x
, so you can determine the path of the driver as
/lib/modules/4.4.35-hi3798mv2x/
Extract this part of the files in the system and put them in the corresponding directory of rootfs, the structure is similar to
modules └── 4.4.35-hi3798mv2x ├── kernel │ ├── crypto │ ├── drivers │ ├── fs │ ├── lib │ └── net ├── modules.alias ├── modules.alias.bin ├── modules. builtin ├── modules.builtin.alias.bin ├── modules.builtin.bin ├── modules.dep ├── modules.dep.bin ├── modules.devname ├── modules. order ├── modules.softdep ├── modules.symbols └── modules.symbols.bin
Basic settings
set hostname
echo n2ns1 > /etc/hostname
set network
cat << EOT > /etc/network/interfaces.d/10-eth0 # Enter in sequence auto eth0 iface eth0 inet dhcp EOT
setup vim
nano /etc/vim/vimrc.tiny # Modify compatible to nocompatible set nocompatible # Add this line to fix the backspace key set backspace=2
Important Set a password for the root user, otherwise you will not be able to log in after flashing
passwd
Open root user ssh access, edit /etc/ssh/sshd_config, find
#PermitRootLogin prohibit-password
replace with
PermitRootLogin yes
Configure the serial port for login, modify the file /etc/systemd/system/getty.target.wants/[email protected]
vi /etc/systemd/system/getty.target.wants/getty\@tty1.service
Will
ConditionPathExists=/dev/tty0
change to actual name
ConditionPathExists=/dev/ttyAMA0
Add a welcome interface, create a new /etc/update-motd.d/60-welcome, the content is as follows, and the property is set to executable
#!/bin/sh # IP=$(ifconfig eth0 | grep '\<inet\>'| grep -v '127.0.0.1' | awk '{print $2}' | awk 'NR==1') DEVICE=$(dmesg 2> /dev/null | grep "CPU: hi3798" | awk -F ':[ ]' '/CPU/{printf ($2)}') [ ! "$DEVICE" ] & amp; & amp; DEVICE=$(head -n 1 /etc/regname 2> /null) echo " Board : ${DEVICE} Module : $(egrep -oa "hi3798. + reg" /dev/mmcblk0p1| cut -d '_' -f1 | sort | uniq | tr "\\ " ",") CPU : $(cat -v /proc/device-tree/compatible |sed 's/\^@//g') @ $(cat /proc/cpuinfo | grep "processor" | sort | uniq | wc -l) cores Version : $(awk -F '[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release) | $(uname -r)-$(getconf LONG_BIT)bit Storage : $(df -m / | grep -v File | awk '{a=$4*100.0/$2;b=$4;c=$2} {printf("%.1f%% free, %.1fMiB of %. 1fMiB\ ",a,b,c)}') Memory : $(free -m | grep Mem | awk '{a=$7*100.0/$2;b=$2} {printf("%.1f%% free, %.1fMiB total\ ",a,b)} ') | Swap: $(free -m | grep Swap | awk '{a=$4*100/$2;b=$4} {printf("%.1f%% %.1fMiB\ ",a,b)} ') Up Time : $(awk '{a=$1/86400;b=($1?400)/3600;c=($1600)/60;d=($1`)} {printf("%d days d: d: d\ ",a,b,c,d)}' /proc/uptime) IP Addr: $IP Temp : $(grep Tsensor /proc/msp/pm_cpu | awk '{print $4}')°C MAC : $(ifconfig eth0 |grep "ether"| awk '{print $2}') "
File cleanup
After the installation is complete, clean up apt
apt autoremove apt autoclean apt clean
Finally exit
to exit
Make rootfs image file
# Generate an empty image of appropriate size, this size refers to du -h workroot/ -d1 dd if=/dev/zero of=rootfs.img bs=1M count=1024 # format mkfs.ext4 rootfs.img # or mkfs -t ext4 rootfs.img # Mount an empty image mkdir rootfs sudo mount rootfs.img rootfs/ # write to file, preserve permissions sudo cp -rfp workroot/* rootfs/ # unmount sudo umount rootfs/ # Check the file system and automatically repair it e2fsck -p -f rootfs.img # make the image compact resize2fs -M rootfs.img
Reference
- Detailed process https://akhileshmoghe.github.io/_post/linux/debian_minimal_rootfs