Use debootstrap to build and make aarch64/arm64 Debian rootfs file system


Install debootstrap and qemu-user-static

apt install apt-transport-https qemu qemu-user-static binfmt-support debootstrap

Build the Debian 10 (buster) system, the basic package is minbase, using the source of Tsinghua University:

If you want to use other sources, it is recommended to replace the source of your local system with the corresponding one, and then updatedownload to update the corresponding keyand files

variantillustrate

  • minbase: contains only necessary packages and apt;
  • buildd: Contains the build toolkit
  • fakechroot: Contains packages without root privileges
  • scratchbox: contains scratchbox (cross-compilation toolchain) related packages
qemu-debootstrap --arch arm64 --variant=minbase --include=whiptail,ca-certificates,tzdata buster rootfs http://mirrors.ustc.edu.cn/debian/
  • The same is true if you want to make an Ubuntu system. Look at the supported mirrors in http://mirrors.ustc.edu.cn
qemu-debootstrap --arch arm64 --variant=minbase --include=whiptail,ca-certificates,tzdata bionic rootfs http://mirrors.ustc.edu.cn/ubuntu-ports/

After the execution is complete, there should be a rootfs folder in the current directory

copy qemu

cp  /usr/bin/qemu-aarch64-static  rootfs/usr/bin

change source

sed -i 's#http://deb.debian.org#http://mirrors.ustc.edu.cn#g' rootfs/etc/apt/sources.list
# 原始源
sed -i 's#http://ports.ubuntu.com#http://mirrors.ustc.edu.cn#g' rootfs/etc/apt/sources.list

Configure network information:

$ echo 'nameserver 192.168.2.1' > rootfs/etc/resolv.conf
$ mkdir rootfs/etc/netplan
$ cat > rootfs/etc/netplan/50-cloud-init.yaml <<EOF
network:
    ethernets:
        eth0:
        	dhcp4: no
            addresses: [192.168.168.6/24]
            gateway4: 192.168.168.1
            nameservers:
                addresses: [192.168.168.1]
    version: 2
EOF

Configure system information

echo 'Debian10' > rootfs/etc/hostname
echo "127.0.0.1 localhost" > rootfs/etc/hosts
echo "127.0.0.1 Debian10" >> rootfs/etc/hosts

Mount local device files to rootfs:

mount -t proc /proc  rootfs/proc
mount -t sysfs /sys  rootfs/sys
mount -o bind /dev  rootfs/dev
mount -o bind /dev/pts  rootfs/dev/pts

chroot rootfsInternal configuration:

LANG=zh_CN.UTF-8 chroot rootfs/ /bin/bash

execute in rootfs

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
apt update
apt upgrade
apt install systemd -y
apt install wireless-regdb crda -y
apt install rsyslog udev dbus kmod openssh-server openssh-client netplan.io man vim wget net-tools sysstat tmux less wireless-regdb crda dosfstools parted sudo git iputils-ping -y
#你还可以安装其他的工具

  • Those who need a toolchain can execute the following command
apt install gcc g++ -y (或者选择buildd的包)
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config

final preparations

passwd root
umount /dev/pts/ /dev/ /proc/ /sys
exit
  • If you need to add users, use
useradd -m debian -g sudo -s /bin/bash -d /home/debian

Here you can burn and write to the board
After exiting, pack it
Optionally set the network DHCP

cat > /etc/netplan/50-cloud-init.yaml <<EOF
network:
    ethernets:
        eth0:
        		dhcp4: yes
    version: 2
EOF

Pack

cd rootfs
tar jcvf ../rootfs.tar.bz2 *

Guess you like

Origin blog.csdn.net/qq_37596943/article/details/127343930