|
|
@ -1,11 +1,14 @@ |
|
|
|
\chapter{制作 ubuntu 文件系统} |
|
|
|
|
|
|
|
在 主机的 Ubuntu 系统里面,可以制作 aarch64 的文件系统,这里介绍一下步骤。 |
|
|
|
\section{ 安装依赖软件} |
|
|
|
\section{准备安装环境} |
|
|
|
|
|
|
|
\subsection{安装依赖软件} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
sudo apt install qemu-user-static debootstrap |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\section{下载基础系统} |
|
|
|
\subsection{下载基础系统} |
|
|
|
这里以安装 Ubuntu 22.04 为例: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
mkdir ubuntu |
|
|
@ -16,20 +19,20 @@ sudo chroot ubuntu /usr/bin/qemu-aarch64-static /bin/sh \ |
|
|
|
\end{minted} |
|
|
|
Ubuntu 22.04 的代号是 jammy, Ubuntu 20.04 的代号是 focal。如果要做 Ubuntu 20.04 版本的系统,把命令中的 jammy 换成 focal。 |
|
|
|
|
|
|
|
\section{安装必备软件} |
|
|
|
|
|
|
|
\subsection{安装基础软件} |
|
|
|
给目标系统安装常用程序: |
|
|
|
\begin{enumerate}[(1)] |
|
|
|
\item 进入目标系统: |
|
|
|
\subsection{切换到安装环境} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
sudo mount -o bind /sys ubuntu/sys |
|
|
|
sudo mount -o bind /proc ubuntu/proc |
|
|
|
sudo mount -o bind /dev ubuntu/dev |
|
|
|
sudo mount -o bind /dev/pts ubuntu/dev/pts |
|
|
|
sudo chroot ubuntu /usr/bin/qemu-aarch64-static /bin/bash -i |
|
|
|
sudo mount -t sysfs sys /sys ubuntu/sys |
|
|
|
sudo mount -t proc proc /proc ubuntu/proc |
|
|
|
sudo mount -o bind /dev ubuntu/dev |
|
|
|
sudo mount -o bind /dev/pts ubuntu/dev/pts |
|
|
|
sudo chroot ubuntu /usr/bin/qemu-aarch64-static /bin/bash -i |
|
|
|
\end{minted} |
|
|
|
\item 修改 /etc/apt/sources.list 如下: |
|
|
|
|
|
|
|
\section{构建 rootfs} |
|
|
|
|
|
|
|
\subsection{更新 apt 源} |
|
|
|
|
|
|
|
修改 /etc/apt/sources.list 如下: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
deb http://ports.ubuntu.com/ jammy main universe |
|
|
|
deb-src http://ports.ubuntu.com/ jammy main universe |
|
|
@ -38,25 +41,51 @@ deb-src http://ports.ubuntu.com/ jammy-security main universe |
|
|
|
deb http://ports.ubuntu.com/ jammy-updates main universe |
|
|
|
deb-src http://ports.ubuntu.com/ jammy-updates main universe |
|
|
|
\end{minted} |
|
|
|
\item 更新系统: |
|
|
|
|
|
|
|
\subsection{更新系统} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get update |
|
|
|
apt-get dist-upgrade |
|
|
|
\end{minted} |
|
|
|
\item 安装常用软件: |
|
|
|
|
|
|
|
\subsection{安装必要软件} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install -y vim-nox build-essential gdb u-boot-tools rsync \ |
|
|
|
socat jq tcpdump ifupdown minicom i2c-tools lrzsz tftp-hpa \ |
|
|
|
net-tools dosfstools pciutils memtool ethtool unzip python3-pip \ |
|
|
|
parted usbutils command-not-found gdisk |
|
|
|
parted usbutils command-not-found gdisk openssh-server |
|
|
|
apt-get install locales tzdata |
|
|
|
\end{minted} |
|
|
|
\item 安装图形界面 (可选): |
|
|
|
|
|
|
|
\subsection{安装 rockchip 硬解码器} |
|
|
|
添加软件源: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install software-properties-common |
|
|
|
add-apt-repository ppa:george-coolpi/multimedia |
|
|
|
apt update |
|
|
|
\end{minted} |
|
|
|
安装 gstreamer : |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ |
|
|
|
libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base \ |
|
|
|
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad alsa-utils \ |
|
|
|
gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools \ |
|
|
|
gstreamer1.0-alsa gstreamer1.0-pulseaudio ffmpeg v4l-utils |
|
|
|
\end{minted} |
|
|
|
安装插件gstreamer1.0-rockchip |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install gstreamer1.0-rockchip |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\subsection{安装图形界面 (可选)} |
|
|
|
\subsubsection{安装 ubuntu 桌面环境} |
|
|
|
执行如下命令: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install ubuntu-desktop # 其他可选xubuntu-desktop lubuntu-desktop等 |
|
|
|
\end{minted} |
|
|
|
提示选择桌面管理器时,可以选 gdm。 |
|
|
|
\item 安装中英文语言包与输入法(可选): |
|
|
|
提示选择桌面管理器时,可以选 `gdm`。 |
|
|
|
|
|
|
|
\subsubsection{安装中英文语言包与输入法(可选)} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
# 英文环境 |
|
|
|
apt-get install language-pack-en-base |
|
|
@ -69,52 +98,70 @@ apt install language-pack-gnome-zh-hans-base |
|
|
|
# 中文输入法 |
|
|
|
apt-get install ibus-table-wubi ibus-pinyin ibus-sunpinyin |
|
|
|
\end{minted} |
|
|
|
\item 设置开机默认切换到图形界面,执行如下命令(可选): |
|
|
|
|
|
|
|
\subsubsection{设置 gdm 自动登录} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
vim /etc/gdm3/custom.conf |
|
|
|
# 修改下面的内容,ubuntu即账户名 |
|
|
|
[daemon] |
|
|
|
AutomaticLoginEnable=true |
|
|
|
AutomaticLogin=ubuntu |
|
|
|
TimedLoginEnable=true |
|
|
|
TimedLogin=ubuntu |
|
|
|
TimedLoginDelay=10 |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\subsubsection{开机默认进图形界面} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
systemctl set-default graphical.target |
|
|
|
\end{minted} |
|
|
|
\item 设置 root 密码: |
|
|
|
|
|
|
|
\subsection{rootfs 设置} |
|
|
|
|
|
|
|
\subsubsection{设置 root 密码} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
passwd root |
|
|
|
\end{minted} |
|
|
|
\item 添加用户: |
|
|
|
|
|
|
|
\subsubsection{添加用户} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
useradd -s '/bin/bash' -m -G adm,sudo,video,plugdev,dialout ubuntu |
|
|
|
\end{minted} |
|
|
|
\item 设置时区: |
|
|
|
|
|
|
|
\subsubsection{设置时区} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
|
|
|
\end{minted} |
|
|
|
\item 设置 hostname: |
|
|
|
|
|
|
|
\subsubsection{设置 hostname} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
echo sytc > /etc/hostname |
|
|
|
echo "127.0.0.1 sytc" >> /etc/hosts |
|
|
|
\end{minted} |
|
|
|
\item 设置bash为默认shell: |
|
|
|
|
|
|
|
\subsubsection{设置bash为默认shell (可选)} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
dpkg-reconfigure dash |
|
|
|
\end{minted} |
|
|
|
选择 ``NO''。 |
|
|
|
\item 配置 locals: |
|
|
|
|
|
|
|
\subsubsection{配置 locale} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
dpkg-reconfigure locales |
|
|
|
\end{minted} |
|
|
|
至少选择 en\_US.UTF-8 和 zh\_CN.UTF-8。 |
|
|
|
\item 修改开机检测网络时间,避免开机卡住,执行如下命令: |
|
|
|
|
|
|
|
修改下面这个文件 |
|
|
|
\subsubsection{修改开机检测网络时间} |
|
|
|
|
|
|
|
修改开机检测网络时间,避免开机卡住: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
vim /lib/systemd/system/networking.service |
|
|
|
# 将里面的TimeoutStartSec=5min修改为 |
|
|
|
TimeoutStartSec=1sec |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
vim /lib/systemd/system/NetworkManager-wait-online.service |
|
|
|
# 将里面的 timeout=30 修改为 |
|
|
|
ExecStart=/usr/bin/nm-online -s -q --timeout=1 |
|
|
|
\end{minted} |
|
|
|
\item 配置/etc/fstab,例如: |
|
|
|
\subsubsection{ 配置 fstab } |
|
|
|
配置/etc/fstab 内容如下: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
# <file system> <mount pt> <type> <options> <dump> <pass> |
|
|
|
/dev/root / auto rw,noauto 0 1 |
|
|
@ -130,7 +177,10 @@ sysfs /sys sysfs defaults 0 0 |
|
|
|
debugfs /sys/kernel/debug debugfs defaults 0 0 |
|
|
|
pstore /sys/fs/pstore pstore defaults 0 0 |
|
|
|
\end{minted} |
|
|
|
\item 修改 getty 服务,使 root 自动登录。修改文件 /usr/lib/systemd/system/serial-getty@.service 的 ExecStart 对应的值: |
|
|
|
|
|
|
|
\subsubsection{串口自动登录} |
|
|
|
|
|
|
|
修改文件 /usr/lib/systemd/system/serial-getty@.service 的 ExecStart 对应的值: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
[Service] |
|
|
|
# The '-o' option value tells agetty to replace 'login' arguments with an |
|
|
@ -140,22 +190,14 @@ ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM |
|
|
|
#ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,38400,9600 %I $TERM |
|
|
|
Type=idle |
|
|
|
\end{minted} |
|
|
|
使能串口服务: |
|
|
|
|
|
|
|
然后使能调试串口服务: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
systemctl enable serial-getty@ttyFIQ0.service |
|
|
|
\end{minted} |
|
|
|
\item 设置图形界面的自动登录(可选): |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
vim /etc/gdm3/custom.conf |
|
|
|
# 修改下面的内容,ubuntu即账户名 |
|
|
|
[daemon] |
|
|
|
AutomaticLoginEnable=true |
|
|
|
AutomaticLogin=ubuntu |
|
|
|
TimedLoginEnable=true |
|
|
|
TimedLogin=ubuntu |
|
|
|
TimedLoginDelay=10 |
|
|
|
\end{minted} |
|
|
|
\item 设置 pulseaudio 音频服务 (可选): \\ |
|
|
|
|
|
|
|
|
|
|
|
\subsubsection{ 设置 pulseaudio 音频服务 (可选)} |
|
|
|
添加文件 /etc/systemd/system/pulseaudio.service 内容如下: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
[Unit] |
|
|
@ -181,7 +223,9 @@ autospawn = no |
|
|
|
\end{minted} |
|
|
|
将用户添加到 pulse-access组中。 |
|
|
|
|
|
|
|
\item 设置网络参数/etc/network/interfaces.d/eth0 |
|
|
|
\subsubsection{设置网卡IP地址} |
|
|
|
|
|
|
|
设置网络参数/etc/network/interfaces.d/eth0 |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{ini} |
|
|
|
auto eth0 |
|
|
|
iface eth0 inet static |
|
|
@ -194,17 +238,15 @@ auto eth0 |
|
|
|
echo "source-directory /etc/network/interfaces.d" > /etc/network/interfaces |
|
|
|
\end{minted} |
|
|
|
用这里 \ref{sec:fixethx} 的方法将网卡名固定为 ethX 。 |
|
|
|
\item 下载并安装附件的\openfilelink{resize-disk.pdf}{resize-disk} 脚本。 |
|
|
|
|
|
|
|
\subsubsection{首次开机扩容脚本} |
|
|
|
|
|
|
|
下载并安装附件的\openfilelink{resize-disk.pdf}{resize-disk} 脚本。 |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
tar xpvf resize-disk.tar.xz -C / |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\end{enumerate} |
|
|
|
\subsection{安装 ssh server} |
|
|
|
\noindent 安装软件: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install openssh-server |
|
|
|
\end{minted} |
|
|
|
\subsubsection{配置 ssh server} |
|
|
|
配置允许root登陆,将/etc/ssh/sshd\_config中的: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
#PermitRootLogin prohibit-password |
|
|
@ -214,37 +256,22 @@ apt-get install openssh-server |
|
|
|
PermitRootLogin yes |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\subsection{安装 rockchip 硬解码器} |
|
|
|
添加软件源: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install software-properties-common |
|
|
|
add-apt-repository ppa:george-coolpi/multimedia |
|
|
|
apt update |
|
|
|
\end{minted} |
|
|
|
安装 gstreamer : |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ |
|
|
|
libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base \ |
|
|
|
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad alsa-utils \ |
|
|
|
gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools \ |
|
|
|
gstreamer1.0-alsa gstreamer1.0-pulseaudio ffmpeg v4l-utils |
|
|
|
\end{minted} |
|
|
|
安装插件gstreamer1.0-rockchip |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get install gstreamer1.0-rockchip |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\subsection{打包成 ext4 文件系统} |
|
|
|
|
|
|
|
清理并退出 chroot 环境: |
|
|
|
\subsubsection{清理并退出} |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
apt-get clean |
|
|
|
exit |
|
|
|
sudo umount ubuntu/dev/pts |
|
|
|
sudo umount ubuntu/dev |
|
|
|
sudo umount ubuntu/sys |
|
|
|
sudo umount ubuntu/proc |
|
|
|
\end{minted} |
|
|
|
|
|
|
|
\section{打包成 ext4 文件系统} |
|
|
|
|
|
|
|
执行命令,打包成 ext4 的文件系统文件: |
|
|
|
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|
|
|
IMAGE_SIZE_MB=$(( $(sudo du -sh -m ubuntu | cut -f1) + 300 )) |
|
|
|
dd if=/dev/zero of=ubuntu.img bs=1M count=0 seek=${IMAGE_SIZE_MB} |
|
|
|
sudo mkfs.ext4 -d ubuntu ubuntu.img |
|
|
|
\end{minted} |
|
|
|
可以将 ubuntu.img 烧写到 EMMC 的 rootfs 分区上。 |
|
|
|
可以将 ubuntu.img 烧写到 EMMC 的 rootfs 分区上。 |
|
|
|