使用Debootstrap制作Debian文件系统(STM32MP157)

使用Debootstrap制作Debian文件系统(STM32MP157)

发现最近随便转载的很多啊,未经授权禁止转载!抄袭!!否则转载者死全家!!另外这是我的笔记,不是教程,难免会有错误,不具有很高的参考性,望周知。

Debootstrap第一阶段

这个阶段会下载一些基本的包。

  1. 在Ubuntu主机安装Debootstrap软件及依赖:
1
sudo apt-get install debootstrap qemu-user-static
  1. 新建文件夹,用来存放根文件系统:
1
mkdir rootfs
  1. 制作Debian根文件系统:
1
sudo debootstrap --foreign --arch armhf buster rootfs http://mirrors.tuna.tsinghua.edu.cn/debian/

如果没有报错就说明完成了,时间大概几分钟。

Debootstrap第二阶段

这个阶段会安装包。

  1. 复制qemu-arm-static文件:
1
sudo cp /usr/bin/qemu-arm-static rootfs/usr/bin
  1. 执行第二阶段:
1
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot rootfs debootstrap/debootstrap --second-stage

其中:

命令 作用
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true 设置为命令行形式交互
LC_ALL=C LANGUAGE=C LANG=C 设置语言
  1. 在Unpacking the base system…过程会卡很长一段时间,我的是机械硬盘,需要十几分钟,需要耐心等待。出现下面的提示就说明成功了:
1
I: Base system installed successfully.

第三阶段(根据需要选择执行)

此阶段进行一些基础配置,否则连系统都登录不进去。

添加新用户,更改密码

使用chroot切换目录:

1
sudo chroot rootfs/

修改root用户密码:

1
passwd

添加新用户(用户名:debian):

1
useradd -m -s /bin/bash -d /home/debian -G sudo debian

修改debian用户密码:

1
passwd debian

安装基础包

修改软件源:

1
nano /etc/apt/source.list

修改内容:

1
2
3
4
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free

更新包缓存:

1
apt update

安装基本软件包:

1
apt install sudo busybox lsof

安装基本网络包:

1
apt install netbase net-tools ethtool udev iproute2 iputils-ping ifupdown isc-dhcp-client ssh ifupdown

安装实用程序包:

1
apt install locales vim adduser less wget dialog usbutils

安装蓝牙配置工具:

1
apt install bluez

安装无线配置工具:

1
apt install firmware-iwlwifi wireless-tools

安装其他包:

1
apt install rsyslog htop iputils-ping nfs-common python3

待补充。。。

添加debian用户到sudo列表

给/etc/sudoers文件添加可写权限:

1
chmod u+w /etc/sudoers

添加debian用户到sudo列表:

1
nano /etc/sudoers

在root ALL=(ALL:ALL) ALL下面添加:

1
debian ALL=(ALL:ALL) ALL

去掉可写权限:

1
chmod u-w /etc/sudoers

设置DNS服务器

设置DNS服务器地址:

1
nano /etc/resolv.conf

修改内容:

1
nameserver 8.8.8.8

设置语言变量

修改文件:

1
sudo vim /root/.bashrc

添加下面的变量:

1
2
3
export LANGUAGE="en_US.UTF-8"
export LANG=en_US:zh_CN.UTF-8
export LC_ALL=C

设置locales包:

1
dpkg-reconfigure locales

更改Hostname

1
nano /etc/hostname

修改为:

1
FS-MP1A

第四阶段

  1. 退出chroot:
1
exit
  1. 打包rootfs:
1
sudo tar -zcvf debian.tar.gz rootfs
  1. 放入nfs目录,测试
1
2
cd rootfs
sudo mv * ~/nfs_rootfs

坚持原创技术分享,您的支持是我前进的动力!