5. Ubuntu 根文件系统定制
引用---->
https://wiki.t-firefly.com/zh_CN/Firefly-Linux-Guide/custom_ubuntu_rootfs.html
5. Ubuntu 根文件系统定制
以下基于 Ubuntu 18.04 64bit 根文件系统定制为例。
5.1. 准备工作
5.1.1. 安装 qemu
在 Linux PC 主机上安装模拟器:
sudo apt-get install qemu-user-static
5.1.2. 下载和解压 ubuntu-core
用户可以到 ubuntu cdimg 下载,选择下载 ubuntu-base-18.04.5-base-arm64.tar.gz。
下载完之后,创建临时文件夹并解压根文件系统:
mkdir temp
sudo tar -xpf ubuntu-base-18.04.5-base-arm64.tar.gz -C temp
5.2. 修改根文件系统
5.2.1. 准备工作
准备网络:
sudo cp -b /etc/resolv.conf temp/etc/resolv.conf
准备 qemu:
sudo cp /usr/bin/qemu-aarch64-static temp/usr/bin/
5.2.1. 准备工作
准备网络:
sudo cp -b /etc/resolv.conf temp/etc/resolv.conf
准备 qemu:
sudo cp /usr/bin/qemu-aarch64-static temp/usr/bin/
创建一个挂载脚本,命名为 mount.sh,脚本内容如下:
#!/bin/bash
mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
sudo mount -o bind /dev/pts ${2}dev/pts
}
umnt() {
echo "UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
sudo umount ${2}dev/pts
sudo umount ${2}dev
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
fi
添加执行权限并使用脚本进行挂载:
注意:稍后定制完成一定要记得取消挂载!!!
chmod +x mount.sh
./mount.sh -m temp/
进入根文件系统进行操作:
sudo chroot temp
5.2.2. 更新及安装
更新:
apt update
apt upgrade
安装自己需要的功能
apt install vim git ....(根据自己需求添加)
安装 xubuntu:
apt-get install xubuntu-desktop
可能出现错误:
E: Unable to locate package xxxx
安装包的源没有添加到 /etc/apt/source.list 中,导致无法识别安装包,可以自行添加源,也可以使用下面给出的 source.list 覆盖原来的 /etc/apt/source.list 文件:
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main
