debootstrap 制作根文件系统
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<h1><a id="_2"></a>效果图</h1>
制作根文件系统,在PC上最全面的莫过于LFS(linux form scratch),而嵌入式中 busybox 是不二之选。不过,我们这次使用debootstrap来构建文件系统。debootstrap是debian/ubuntu下的一个工具,用来构建一套基本的根文件系统,其生成的目录符合Linux文件系统标准(FHS),即包含了/boot、/etc、/bin、/usr等等目录,但它比发行版本的Linux体积小很多,当然功能也没那么强大,因此,只能说是“基本的系统”。
准备环境
安装所需依赖,使用debootstrap命令创建文件系统。
sudo apt-get install debian-archive-keyring
sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
使用也十分简单,命令格式为:
sudo debootstrap --arch [平台] [发行版本代号] [构建目录] [镜像地址]
当前debootstrap支持的发行版本可以在
/usr/share/debootstrap/scripts
查看,而各发行版代号可以到http://en.wikipedia.org/wiki/List_of_Ubuntu_releases
查看。
创建版本
cd && mkdir build && cd build
这里以bionic版本为例
Armhf
sudo debootstrap --arch=armhf bionic linux-rootfs http://mirrors.ustc.edu.cn/ubuntu-ports/
sudo cp -a /usr/bin/qemu-arm-static ~/build/linux-rootfs/usr/bin/qemu-arm-static
arm64
sudo debootstrap --arch=arm64 bionic linux-rootfs http://mirrors.ustc.edu.cn/ubuntu-ports/
sudo cp -a /usr/bin/qemu-aarch64-static ~/build/linux-rootfs/usr/bin/qemu-aarch64-static
其他镜像:
- https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/
wget https://raw.githubusercontent.com/ywhs/linux-software/master/ch-mount.sh
chmod 777 ch-mount.sh
./ch-mount.sh -m linux-rootfs/
# 执行脚本后,没有报错会进入文件系统,显示 I have no name ,这是因为还没有初始化。
debootstrap/debootstrap --second-stage
exit
./ch-mount.sh -u linux-rootfs/
./ch-mount.sh -m linux-rootfs/
# sudo chroot linux-rootfs
配置系统字符集(根据提示进行)
export LC_ALL=en_US.UTF-8
apt-get install locales
dpkg-reconfigure locales
配置时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
换源
apt-get install nano
cp /etc/apt/sources.list /etc/apt/sources.list.bak
nano /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
apt-get update
apt-get upgrade
配置root用户密码
# 先设置root用户的密码
passwd
创建一个普通用户
# 这两个环境变量可以自行修改
USER=pi
HOST=robot
useradd -G adm tty disk dialout sudo audio video plugdev games users systemd-journal input netdev ssh bluetooth -m -s /bin/bash $USER
passwd $USER
# cat /etc/group
# 查看当前系统用户组
设置主机名称:
echo $HOST>/etc/hostname
设置本机入口ip:
cat <<EOF > /etc/hosts 127.0.0.1 localhost 127.0.1.1 $HOST
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
配置Wi-Fi
nano/etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -Dwext -i wlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B
nano etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="WIFI-Name"
psk="Password"
key_mgmt=WPA-PSK
priority=1
}
允许自动更新dns:
dpkg-reconfigureresolvconf
安装依赖
apt-get install -y sudo ssh net-tools ethtool wireless-tools network-manager iputils-ping rsyslog alsa-utils bash-completion gnupg busybox kmod --no-install-recommends
# 安装音频管理
apt-get install alsa-utils libasound2-dev wget git curl git# add-apt-repository命令
apt-get install software-properties-common#apt update
#apt install sudo language-pack-en-base ssh net-tools ethtool ifupdown iputils-ping htop vim kmod network-manager xorg qt5-default openbox make
#apt upgrade
#apt install gcc g++
Neofetch
Ubuntu 17.04 and up
apt update
apt install neofetch
Ubuntu 16.10 and below
add-apt-repository ppa:dawidd0811/neofetch
apt update && apt install neofetch
挂载
nano /etc/fstab
#<file system> <mount point> <type> <options> <dump> <pass>
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
sudo权限问题
https://blog.csdn.net/zhouguangfei0717/article/details/82768474
cd /home && ls -la
drwxr-xr-x 3 root root 4096 May 26 2020 .
drwx------ 21 pi pi 4096 May 26 2020 ..
drwxr-xr-x 3 pi pi 4096 Feb 11 16:28 pi
chmod 755 ".."
visudo
chmod 4755 /usr/bin/sudo
SSH 问题
https://hant.kutu66.com/ubuntu/article_176553
chown root: /
raspi-config
apt install whiptail parted lua5.1 alsa-utils psmisc
wget http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20200504_all.deb
dpkg -i raspi-config_20200504_all.deb
apt-get -f -y install
安装Ubuntu mate桌面
https://www.htcp.net/880.html
清理系统
rm -Rf /tmp/* && apt clean && apt autoclean
卸载
./ch-mount.sh -u linux-rootfs/
其他
在构建根文件系统过程中可能还存在其他纰漏,欢迎指正。