surenyi
3 months ago
3 changed files with 439 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,438 @@ |
|||
\chapter{制作欧拉文件系统} |
|||
本章节介绍如何构建适用于 aarch64 的 openEuler 文件系统镜像。 |
|||
|
|||
\section{准备安装环境} |
|||
\begin{enumerate}[(1)] |
|||
\item 下载 openEuler 的 rpi 的镜像文件 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
curl -O http://repo.openeuler.org/openEuler-24.03-LTS/raspi_img/\ |
|||
openEuler-24.03-LTS-raspi-aarch64.img.xz |
|||
xz -d openEuler-24.03-LTS-raspi-aarch64.img.xz |
|||
\end{minted} |
|||
\item 准备 aarch64 的系统: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
sudo losetup -P /dev/loop0 openEuler-24.03-LTS-raspi-aarch64.img |
|||
sudo mount /dev/loop0p3 /media |
|||
mkdir rpi |
|||
sudo rsync -avzP /media/ rpi/ |
|||
sudo umount /media |
|||
sudo losetup -d /dev/loop0 |
|||
sudo cp /usr/bin/qemu-aarch64-static rpi/usr/bin |
|||
\end{minted} |
|||
\item 切换到安装环境 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
sudo mount --bind /dev rpi/dev |
|||
sudo mount --bind /dev/pts rpi/dev/pts |
|||
sudo mount -t proc proc rpi/proc |
|||
sudo mount -t sysfs sys rpi/sys |
|||
sudo chroot rpi /usr/bin/qemu-aarch64-static /bin/bash -i |
|||
\end{minted} |
|||
\item 编辑 /etc/resolv.conf |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
nameserver 8.8.8.8 |
|||
nameserver 114.114.114.114 |
|||
\end{minted} |
|||
\item 安装依赖包 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dnf makecache |
|||
dnf install git wget make gcc bison dtc m4 flex bc openssl-devel \ |
|||
tar dosfstools rsync parted dnf-plugins-core tar |
|||
\end{minted} |
|||
\item 创建工作目录 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
export WORKDIR=/root/build |
|||
mkdir -p $WORKDIR |
|||
cd $WORKDIR |
|||
\end{minted} |
|||
\end{enumerate} |
|||
|
|||
\section{构建 rootfs 镜像} |
|||
|
|||
\subsection{创建 RPM 数据库} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
cd $WORKDIR |
|||
mkdir -p rootfs/var/lib/rpm |
|||
rpm --root $WORKDIR/rootfs/ --initdb |
|||
\end{minted} |
|||
|
|||
\subsection{下载安装 openEuler 发布包} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
rpm -ivh --nodeps --root $WORKDIR/rootfs/ \ |
|||
http://repo.openeuler.org/openEuler-24.03-LTS/everything/\ |
|||
aarch64/Packages/openEuler-release-24.03LTS-55.oe2403.aarch64.rpm |
|||
\end{minted} |
|||
如出现错误:\\ |
|||
``error: failed to exec scriptlet interpreter /bin/sh: No such file or directory''\\ |
|||
可暂时忽略。 |
|||
|
|||
\subsection{添加 yum 源} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
mkdir -p $WORKDIR/rootfs/etc/yum.repos.d |
|||
curl -o $WORKDIR/rootfs/etc/yum.repos.d/openEuler-24.03-LTS.repo \ |
|||
https://gitee.com/src-openeuler/openEuler-repos/raw/\ |
|||
openEuler-24.03-LTS/generic.repo |
|||
\end{minted} |
|||
|
|||
\subsection{安装 dnf} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dnf --installroot=$WORKDIR/rootfs/ install dnf --nogpgcheck -y |
|||
\end{minted} |
|||
|
|||
\subsection{安装必要软件} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dnf --installroot=$WORKDIR/rootfs/ makecache |
|||
dnf --installroot=$WORKDIR/rootfs/ install -y git wget bison dtc flex \ |
|||
m4 dnf alsa-utils v4l-utils wpa_supplicant vim net-tools iproute \ |
|||
iputils NetworkManager openssh-server passwd hostname lrzsz minicom \ |
|||
tcpdump ethtool openssl-devel tar dosfstools gdisk parted bc socat \ |
|||
unzip gstreamer1 gstreamer1-plugins-base gstreamer1-plugins-good \ |
|||
gstreamer1-plugins-bad-free gcc g++ gdb make cmake irqbalance sudo \ |
|||
ntfs-3g rsync dnf-plugins-core |
|||
\end{minted} |
|||
|
|||
\subsection{添加配置文件} |
|||
\subsubsection{设置 DNS} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
cp /etc/resolv.conf ${WORKDIR}/rootfs/etc/resolv.conf |
|||
\end{minted} |
|||
其内容为: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
nameserver 8.8.8.8 |
|||
nameserver 114.114.114.114 |
|||
\end{minted} |
|||
|
|||
\subsubsection{设置 fstab} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
vim ${WORKDIR}/rootfs/etc/fstab |
|||
\end{minted} |
|||
添加内容: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
# <file system> <mount pt> <type> <options> <dump> <pass> |
|||
/dev/root / auto rw,noauto 0 1 |
|||
tmpfs /tmp tmpfs mode=1777 0 0 |
|||
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0 |
|||
PARTLABEL=oem /oem ext2 defaults 0 2 |
|||
PARTLABEL=userdata /userdata ext4 defaults 0 0 |
|||
proc /proc proc defaults 0 0 |
|||
devtmpfs /dev devtmpfs defaults 0 0 |
|||
devpts dev/pts devpts mode=0620,ptmxmode=0666,gid=5 0 0 |
|||
tmpfs /dev/shm tmpfs nosuid,nodev,noexec 0 0 |
|||
sysfs /sys sysfs defaults 0 0 |
|||
debugfs /sys/kernel/debug debugfs defaults 0 0 |
|||
pstore /sys/fs/pstore pstore defaults 0 0 |
|||
\end{minted} |
|||
|
|||
\subsubsection{设置 IP 地址} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
mkdir $WORKDIR/rootfs/etc/sysconfig/network-scripts |
|||
vim $WORKDIR/rootfs/etc/sysconfig/network-scripts/ifcfg-eth0 |
|||
\end{minted} |
|||
内容如下: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
NAME=eth0 |
|||
DEVICE=eth0 |
|||
ONBOOT=yes |
|||
BOOTPROTO=none |
|||
TYPE=Ethernet |
|||
IPADDR=192.168.1.80 |
|||
NETMASK=255.255.255.0 |
|||
GATEWAY=192.168.1.1 |
|||
\end{minted} |
|||
|
|||
\subsubsection{禁用网卡名修改} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
vim $WORKDIR/rootfs/etc/udev/rules.d/80-net-setup-link.rules |
|||
\end{minted} |
|||
内容如下: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
# do not edit this file, it will be overwritten on update |
|||
SUBSYSTEM!="net", GOTO="net_setup_link_end" |
|||
IMPORT{builtin}="path_id" |
|||
ACTION=="remove", GOTO="net_setup_link_end" |
|||
IMPORT{builtin}="net_setup_link" |
|||
NAME=="", ENV{ID_NET_NAME}!="", NAME="$env{ID_NET_SLOT}" |
|||
LABEL="net_setup_link_end" |
|||
\end{minted} |
|||
|
|||
\subsubsection{添加第一次开机脚本} |
|||
在 \verb+$WORKDIR/rootfs/etc/rc.d/init.d/first-run.sh+ 写入以下内容: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
#!/bin/bash |
|||
# chkconfig: - 99 10 |
|||
# description: expand rootfs |
|||
|
|||
ROOT_PART="$(findmnt / -o source -n)" # /dev/mmcblk0p7 |
|||
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")" # /dev/mmcblk0 |
|||
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")" # 7 |
|||
|
|||
USER_PART="$(findmnt /userdata -o source -n)" # /dev/mmcblk0p9 |
|||
USER_NUM="$(echo "$USER_PART" | grep -o "[[:digit:]]*$")" # 9 |
|||
|
|||
cat << EOF | gdisk $ROOT_DEV |
|||
p |
|||
w |
|||
Y |
|||
Y |
|||
EOF |
|||
|
|||
parted -s $ROOT_DEV -- resizepart $PART_NUM 100% |
|||
resize2fs $ROOT_PART |
|||
|
|||
parted -s $ROOT_DEV -- resizepart $USER_NUM 100% |
|||
resize2fs $USER_PART |
|||
|
|||
depmod -a |
|||
|
|||
if [ -f /etc/rc.d/init.d/first-run.sh ]; |
|||
then rm /etc/rc.d/init.d/first-run.sh; |
|||
fi |
|||
\end{minted} |
|||
|
|||
设置可执行权限: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
chmod +x $WORKDIR/rootfs/etc/rc.d/init.d/first-run.sh |
|||
\end{minted} |
|||
|
|||
\subsubsection{启用 rc.local 脚本} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
chmod +x $WORKDIR/rootfs/etc/rc.d/rc.local |
|||
\end{minted} |
|||
|
|||
\subsubsection{安装 firmware 和 modules} |
|||
从原文件系统中复制 firmware 和 modules: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
cp -R /path/to/lib/firmware $WORKDIR/rootfs/usr/lib/ |
|||
cp -R /path/to/lib/modules/5.10.110 $WORKDIR/rootfs/usr/lib/modules/ |
|||
cp -R /path/to/usr/src/linux-5.10.110 $WORKDIR/rootfs/usr/src |
|||
\end{minted} |
|||
|
|||
\subsubsection{串口自动登录} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
vim $WORKDIR/rootfs/usr/lib/systemd/system/serial-getty@.service |
|||
\end{minted} |
|||
修改其中的 \texttt{ExecStart}: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
[Service] |
|||
# The '-o' option value tells agetty to replace 'login' arguments with an |
|||
# option to preserve environment (-p), followed by '--' for safety, and then |
|||
# the entered username. |
|||
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM |
|||
#ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,57600,38400,9600 - $TERM |
|||
Type=idle |
|||
\end{minted} |
|||
|
|||
\section{rootfs 设置} |
|||
|
|||
\subsection{挂载必要的路径} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
mount --bind /dev $WORKDIR/rootfs/dev |
|||
mount --bind /dev/pts $WORKDIR/rootfs/dev/pts |
|||
mount -t proc proc $WORKDIR/rootfs/proc |
|||
mount -t sysfs sys $WORKDIR/rootfs/sys |
|||
\end{minted} |
|||
|
|||
\subsection{chroot 到 root} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
chroot $WORKDIR/rootfs /bin/bash |
|||
\end{minted} |
|||
|
|||
\subsection{设置 root 密码} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
passwd |
|||
\end{minted} |
|||
|
|||
\subsection{添加一个新用户} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
adduser euler |
|||
passwd euler |
|||
\end{minted} |
|||
|
|||
\subsection{设置主机名} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
echo openEuler > /etc/hostname |
|||
echo "127.0.0.1 openEuler" >> /etc/hosts |
|||
\end{minted} |
|||
|
|||
\subsection{设置默认时区为东八区} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
|||
\end{minted} |
|||
|
|||
\subsection{安装 xfce4 桌面系统 (可选)} |
|||
\begin{enumerate}[(1)] |
|||
\item 安装软件 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dnf install -y dejavu-fonts liberation-fonts gnu-*-fonts wqy-zenhei-fonts |
|||
dnf install -y xorg-* |
|||
dnf install -y xfwm4 xfdesktop xfce4-* xfce4-*-plugin |
|||
dnf install -y lightdm lightdm-gtk |
|||
\end{minted} |
|||
\item 设置默认桌面为XFCE 启动 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
echo 'user-session=xfce' >> /etc/lightdm/lightdm.conf.d/\ |
|||
60-lightdm-gtk-greeter.conf |
|||
echo 'autologin-user=euler' >> /etc/lightdm/lightdm.conf.d/\ |
|||
60-lightdm-gtk-greeter.conf |
|||
\end{minted} |
|||
\item 设置开机自启动图形界面 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
systemctl enable lightdm |
|||
systemctl set-default graphical.target |
|||
\end{minted} |
|||
\item 添加 /etc/X11/xorg.conf.d/20-modesetting.conf 文件,内容如下: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
Section "Device" |
|||
Identifier "Rockchip Graphics" |
|||
Driver "modesetting" |
|||
|
|||
### Use Rockchip RGA 2D HW accel |
|||
# Option "AccelMethod" "exa" |
|||
|
|||
### Use GPU HW accel |
|||
Option "AccelMethod" "glamor" |
|||
Option "DRI" "2" |
|||
|
|||
### Set to "always" to avoid tearing, could lead to up 50% performance loss |
|||
Option "FlipFB" "always" |
|||
|
|||
### Limit flip rate and drop frames for "FlipFB" to reduce performance lost |
|||
# Option "MaxFlipRate" "60" |
|||
Option "NoEDID" "true" |
|||
Option "UseGammaLUT" "true" |
|||
|
|||
### Set virtual screen size (scaled by VOP hardware) |
|||
# Option "VirtualSize" "DSI-1:600x1080" |
|||
|
|||
### Set physical display paddings <top,bottom,left,right> |
|||
# Option "Padding" "DSI-1:180,300,300,540" |
|||
EndSection |
|||
|
|||
Section "Screen" |
|||
Identifier "Default Screen" |
|||
Device "Rockchip Graphics" |
|||
Monitor "Default Monitor" |
|||
EndSection |
|||
|
|||
### Valid values for rotation are "normal", "left", "right" |
|||
Section "Monitor" |
|||
Identifier "Default Monitor" |
|||
Option "Rotate" "normal" |
|||
EndSection |
|||
\end{minted} |
|||
|
|||
\end{enumerate} |
|||
|
|||
\subsection{安装 ukui 桌面系统 (可选)} |
|||
ukui 是麒麟软件团队历经多年打造的一款Linux 桌面,主要基于 GTK 和 QT开发。与其他UI界面相比,ukui更加注重易用性和敏捷度,各元件相依性小,可以不依赖其他套件而独自运行,给用户带来亲切和高效的使用体验。 |
|||
|
|||
\begin{enumerate}[(1)] |
|||
\item 安装 ukui |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dnf install -y dejavu-fonts liberation-fonts gnu-*-fonts wqy-zenhei-fonts |
|||
dnf install ukui |
|||
\end{minted} |
|||
\item 配置允许root登陆 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
echo "greeter-show-manual-login=true" >> /usr/share/lightdm/lightdm.conf.d/\ |
|||
95-ukui-greeter.conf |
|||
echo "all-guest=false" >> /usr/share/lightdm/lightdm.conf.d/\ |
|||
95-ukui-greeter.conf |
|||
\end{minted} |
|||
\item 配置 euler 用户自动登陆 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
echo "autologin-user=euler" >> /usr/share/lightdm/lightdm.conf.d/\ |
|||
95-ukui-greeter.conf |
|||
\end{minted} |
|||
\item 添加 /etc/X11/xorg.conf.d/20-modesetting.conf 文件,内容如下: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
Section "Device" |
|||
Identifier "Rockchip Graphics" |
|||
Driver "modesetting" |
|||
|
|||
### Use Rockchip RGA 2D HW accel |
|||
# Option "AccelMethod" "exa" |
|||
|
|||
### Use GPU HW accel |
|||
Option "AccelMethod" "glamor" |
|||
Option "DRI" "2" |
|||
|
|||
### Set to "always" to avoid tearing, could lead to up 50% performance loss |
|||
Option "FlipFB" "always" |
|||
|
|||
### Limit flip rate and drop frames for "FlipFB" to reduce performance lost |
|||
# Option "MaxFlipRate" "60" |
|||
Option "NoEDID" "true" |
|||
Option "UseGammaLUT" "true" |
|||
|
|||
### Set virtual screen size (scaled by VOP hardware) |
|||
# Option "VirtualSize" "DSI-1:600x1080" |
|||
|
|||
### Set physical display paddings <top,bottom,left,right> |
|||
# Option "Padding" "DSI-1:180,300,300,540" |
|||
EndSection |
|||
|
|||
Section "Screen" |
|||
Identifier "Default Screen" |
|||
Device "Rockchip Graphics" |
|||
Monitor "Default Monitor" |
|||
EndSection |
|||
|
|||
### Valid values for rotation are "normal", "left", "right" |
|||
Section "Monitor" |
|||
Identifier "Default Monitor" |
|||
Option "Rotate" "normal" |
|||
EndSection |
|||
\end{minted} |
|||
\item 切换用户界面(GUI)模式 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
systemctl set-default graphical.target |
|||
\end{minted} |
|||
还原到文本模式,用下面命令: |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
systemctl set-default multi-user.target |
|||
\end{minted} |
|||
\end{enumerate} |
|||
|
|||
\subsection{设置第一次开机脚本,然后退出} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
chkconfig --add first-run.sh |
|||
chkconfig first-run.sh on |
|||
dnf clean all |
|||
exit |
|||
\end{minted} |
|||
|
|||
\subsection{取消临时挂载的目录} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
umount -l $WORKDIR/rootfs/dev/pts |
|||
umount -l $WORKDIR/rootfs/dev |
|||
umount -l $WORKDIR/rootfs/proc |
|||
umount -l $WORKDIR/rootfs/sys |
|||
\end{minted} |
|||
|
|||
\section{制作镜像} |
|||
\begin{enumerate}[(1)] |
|||
\item 计算镜像容量 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
IMAGE_SIZE_MB=$(( $(sudo du -sh -m $WORKDIR/rootfs | cut -f1) + 300 )) |
|||
\end{minted} |
|||
|
|||
\item 创建镜像文件 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
dd if=/dev/zero of=rootfs.img bs=1M count=0 seek=${IMAGE_SIZE_MB} |
|||
\end{minted} |
|||
|
|||
\item 格式化镜像 |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
mkfs.ext4 -d $WORKDIR/rootfs rootfs.img |
|||
\end{minted} |
|||
\end{enumerate} |
|||
rootfs.img 就是最后可以用 rockchip 的工具烧写到 MMC 上的欧拉系统。 |
|||
|
|||
\section{退出并清理} |
|||
\begin{minted}[bgcolor=lightgray!30,fontsize=\scriptsize]{bash} |
|||
exit |
|||
sudo umount -l rpi/dev/pts |
|||
sudo umount -l rpi/dev |
|||
sudo umount -l rpi/proc |
|||
sudo umount -l rpi/sys |
|||
\end{minted} |
Loading…
Reference in new issue