0
点赞
收藏
分享

微信扫一扫

使用debootstrap构建制作aarch64/arm64 Debian rootfs文件系统


使用debootstrap构建制作aarch64/arm64 Debian rootfs文件系统

  • ​​安装debootstrap和qemu-user-static​​
  • ​​构建Debian 10(buster)系统,基础包为minbase,使用清华的源:​​
  • ​​拷贝qemu​​
  • ​​换源​​
  • ​​配置网络信息:​​
  • ​​配置系统信息​​
  • ​​挂载本地设备文件到rootfs:​​
  • ​​`chroot rootfs` 内配置:​​
  • ​​在rootfs内执行​​
  • ​​最后的准备​​
  • ​​打包​​

安装debootstrap和qemu-user-static

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

构建Debian 10(buster)系统,基础包为minbase,使用清华的源:

如果想用其他的源,建议将你本机系统的源也换成相应的,然后 ​​update​​​ 下以更新相应的 ​​key​​ 以及文件

​variant​​ 说明

  • minbase: 只包含必要的包和apt;
  • buildd: 包含编译工具包
  • fakechroot: 包含不用root权限的包
  • scratchbox: 包含scratchbox(交叉编译工具链)相关包

qemu-debootstrap --arch arm64 --variant=minbase --include=whiptail,ca-certificates,tzdata buster rootfs http://mirrors.ustc.edu.cn/debian/

  • 如果想制作Ubuntu系统同理。看下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/

执行完成后应该会在当前目录下有rootfs文件夹

拷贝qemu

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

换源

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

配置网络信息:

$ 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

配置系统信息

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

挂载本地设备文件到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 rootfs 内配置:

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

在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
#你还可以安装其他的工具

  • 需要工具链的可以执行以下命令

apt install gcc g++ -y (或者选择buildd的包)
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config

最后的准备

passwd root
umount /dev/pts/ /dev/ /proc/ /sys
exit

  • 如果需要添加用户,使用

useradd -m debian -g sudo -s /bin/bash -d /home/debian

到这里就可以烧写到板子上了
退出后,打包
可选设置网络DHCP

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

打包

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


举报

相关推荐

0 条评论