提交 af739a7a 编写于 作者: Y yafen

交叉编译 分区扩容

上级 8b39ebc7
......@@ -14,11 +14,11 @@ This repository provides scripts for building openEuler image for Raspberry Pi a
##### Prepare the environment
To build openEuler ARM64 image for Raspberry Pi, the requirements of runing scripts of this repository are as follows:
To build openEuler AArch64 image for Raspberry Pi, the requirements of runing scripts of this repository are as follows:
- OS: openEuler or Centos 7/8
- Architecture: ARM
- Architecture: AArch64
For example, you can use [QEMU](https://www.qemu.org/) to build ARM system emulation or directly use an ARM hardware such as Raspberry Pi.
For example, you can use [QEMU](https://www.qemu.org/) to build AArch64 system emulation or directly use an AArch64 hardware such as Raspberry Pi.
##### Run the scripts to build image
......@@ -44,7 +44,7 @@ The meaning of each parameter:
- KERNEL_BRANCH:The branch name of kernel source's repository,which defaults to `openEuler-1.0-LTS-raspi`.
- KERNEL_DEFCONFIG:The filename of configuration for compiling kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in the config directory or in arch/arm64/configs of the kernel source. If this configuration file does not exist, the script uses the next parameter: DEFAULT_DEFCONFIG.
- DEFAULT_DEFCONFIG:The filename of configuration for kernel, which defaults to `openeuler-raspi_defconfig`. The configuration file should be in arch/arm64/configs of the kernel source. If both KERNEL_DEFCONFIG and this file do not exist, the process of building image will exit.
- REPO_FILE:The URL or name of openEuler's file, which defaults to `openEuler-1.0-LTS.repo`. Caution, if REPO_FILE is a file name, please make sure this file in the config directory. Otherwise, if REPO_FILE is a URL, please make sure you can get a correct repo file from this URL.
- REPO_FILE:The URL or name of openEuler's file, which defaults to `openEuler-20.03-LTS.repo`. Caution, if REPO_FILE is a file name, please make sure this file in the config directory. Otherwise, if REPO_FILE is a URL, please make sure you can get a correct repo file from this URL.
- --cores:Followed by parameter MAKE_CORES
- MAKE_CORES:The number of parallel compilations, according to the actual number of CPU of the server running the script. The default is 18.
......
......@@ -13,13 +13,13 @@
##### 准备环境
用于生成 openEuler ARM64 的树莓派镜像。
用于生成 openEuler AArch64 的树莓派镜像。
本仓库的脚本运行环境要求:
- 操作系统:openEuler 或 Centos 7/8
- 架构:ARM
- 架构:AArch64
可以使用 [QEMU](https://www.qemu.org/) 模拟器搭建 ARM 运行环境或者直接使用 ARM 架构的主机(例如,树莓派)。
可以使用 [QEMU](https://www.qemu.org/) 模拟器搭建 AArch64 运行环境或者直接使用 AArch64 架构的主机(例如,树莓派)。
##### 构建镜像
......@@ -45,7 +45,7 @@
- KERNEL_BRANCH:内核源码的对应分支,默认为`openEuler-1.0-LTS-raspi`
- KERNEL_DEFCONFIG:内核编译使用的配置文件名称,默认为`openeuler-raspi_defconfig`,在本目录的 config 目录下或内核源码的目录 arch/arm64/configs 下。如果该文件不存在则使用配置文件 DEFAULT_DEFCONFIG。
- DEFAULT_DEFCONFIG:内核默认配置文件名称,默认为`openeuler-raspi_defconfig`,在内核源码的目录 arch/arm64/configs 下。如果 KERNEL_DEFCONFIG 和该文件均不存在则退出镜像构建过程。
- REPO_FILE:openEuler 开发源的 repo 文件的 URL 或者文件名称, 默认为`openEuler-1.0-LTS.repo`。注意,如果 REPO_FILE 为文件名称,需要保证该文件在脚本 build_img.sh 所在目录的 config 文件夹下。
- REPO_FILE:openEuler 开发源的 repo 文件的 URL 或者文件名称, 默认为`openEuler-20.03-LTS.repo`。注意,如果 REPO_FILE 为文件名称,需要保证该文件在脚本 build_img.sh 所在目录的 config 文件夹下。
- --cores:其后跟参数 MAKE_CORES。
- MAKE_CORES:并行编译的数量,根据运行脚本的服务器CPU实际数目设定,默认为18。
......
......@@ -11,7 +11,7 @@ kernel_url="git@gitee.com:openeuler/raspberrypi-kernel.git"
kernel_branch="openEuler-1.0-LTS-rasp"
kernel_defconfig="openeuler-raspi_defconfig"
default_defconfig="openeuler-raspi_defconfig"
repo_file=openEuler-1.0-LTS.repo
repo_file=openEuler-20.03-LTS.repo
date_str=$(date "+%Y%m%d")
output_dir=${run_dir}/output
......@@ -56,6 +56,9 @@ LOG(){
}
prepare(){
if [ ! -d ${cur_dir}/log ]; then
mkdir ${cur_dir}/log
fi
LOG "prepare begin..."
rmp_names=("bison" "flex" "parted" "wget" "multipath-tools")
rmp_install_names=("bison" "flex" "parted" "wget" "kpartx")
......@@ -67,9 +70,6 @@ prepare(){
[ $? -ne 0 ] && echo "yum install ${rmp_install_names[i]} failed." && ERROR "yum install ${rmp_install_names[i]} failed." && yum_right=3
done
[ $yum_right ] && exit 3
if [ ! -d ${cur_dir}/log ]; then
mkdir ${cur_dir}/log
fi
if [ ! -d ${run_dir}/img ]; then
mkdir ${run_dir}/img
fi
......@@ -357,6 +357,8 @@ make_rootfs(){
mkdir -p ${rootfs_dir}/lib/firmware
cp bluez-firmware/broadcom/* ${rootfs_dir}/lib/firmware/
cp -r firmware-nonfree/brcm/ ${rootfs_dir}/lib/firmware/
mv ${rootfs_dir}/lib/firmware/BCM43430A1.hcd ${rootfs_dir}/lib/firmware/brcm/
mv ${rootfs_dir}/lib/firmware/BCM4345C0.hcd ${rootfs_dir}/lib/firmware/brcm/
cp -r ${output_dir}/lib/modules ${rootfs_dir}/lib/
rm ${rootfs_dir}/chroot.sh
LOG "make rootfs for ${repo_file} end."
......@@ -433,6 +435,17 @@ make_img(){
tar cpf ${run_dir}/rootfs.tar .
cd ${root_mnt}
tar xpf ${run_dir}/rootfs.tar -C .
for tmpdir in `ls ${output_dir}/lib/modules`
do
if [ -d ./lib/modules/${tmpdir} ]; then
if [ -L ./lib/modules/${tmpdir}/build ]; then
rm -rf ./lib/modules/${tmpdir}/build
fi
if [ -L ./lib/modules/${tmpdir}/source ]; then
rm -rf ./lib/modules/${tmpdir}/source
fi
fi
done
cd "${run_dir}"
sync
sleep 10
......
# 环境需求
- 操作系统:openEuler 或 Centos 7/8;
- 架构:ARM
- 架构:AArch64
- 硬盘存储不低于50G;
- 内存不低于2G;
- 可访问外网。
可以通过以下方式获取 ARM 架构的运行环境:
可以通过以下方式获取 AArch64 架构的运行环境:
- 使用 ARM 架构的主机,例如树莓派
- 使用 [QEMU](https://www.qemu.org/) 模拟器搭建 ARM 运行环境
- 使用 AArch64 架构的主机,例如树莓派
- 使用 [QEMU](https://www.qemu.org/) 模拟器搭建 AArch64 运行环境
# 树莓派相关
......@@ -20,9 +20,9 @@
### 准备环境
- 操作系统:openEuler 或 Centos 7/8
- 架构:ARM
- 架构:AArch64
除了使用 ARM 架构的运行环境,也可以采用交叉编译的方式编译内核。这里,我们在 ARM 架构的服务器上编译内核。
除了使用 AArch64 架构的运行环境,也可以采用交叉编译的方式编译内核,文档详见 [交叉编译内核](./交叉编译内核.md)。这里,我们在 AArch64 架构的服务器上编译内核。
### 下载源码
......@@ -139,7 +139,7 @@
## 下载安装openEuler发布包
`rpm -ivh --nodeps --root /${WORKDIR}/rootfs/ http://repo.openeuler.org/openEuler-20.03-LTS/everything/aarch64/Packages/openEuler-release-20.03LTS-33.oe1.aarch64.rpm`
`rpm -ivh --nodeps --root ${WORKDIR}/rootfs/ http://repo.openeuler.org/openEuler-20.03-LTS/everything/aarch64/Packages/openEuler-release-20.03LTS-33.oe1.aarch64.rpm`
会在 ${WORKDIR}/rootfs 下生成三个文件夹:
......@@ -151,7 +151,7 @@ etc/ usr/ var/
`mkdir ${WORKDIR}/rootfs/etc/yum.repos.d`
`vim ${WORKDIR}/rootfs/etc/yum.repos.d/openEuler-20.03LTS.repo`
`vim ${WORKDIR}/rootfs/etc/yum.repos.d/openEuler-20.03-LTS.repo`
添加内容:
......@@ -175,13 +175,13 @@ enabled=1
### 安装dnf
`dnf --installroot=${rootfs_dir}/ install dnf --nogpgcheck -y`
`dnf --installroot=${WORKDIR}/rootfs/ install dnf --nogpgcheck -y`
### 安装必要软件
`dnf --installroot=${rootfs_dir}/ makecache`
`dnf --installroot=${WORKDIR}/rootfs/ makecache`
`dnf --installroot=${rootfs_dir}/ install -y wpa_supplicant vim net-tools iproute iputils NetworkManager openssh-server passwd hostname ntp`
`dnf --installroot=${WORKDIR}/rootfs/ install -y wpa_supplicant vim net-tools iproute iputils NetworkManager openssh-server passwd hostname ntp`
## 添加配置文件
......@@ -254,7 +254,7 @@ DEVICE=eth0
`passwd root`
输入要设置的root密码
输入要设置的root密码
5. 设置主机名
......@@ -278,32 +278,40 @@ DEVICE=eth0
### 将固件放进rootfs
`mkdir -p /${WORKDIR}/rootfs/lib/firmware`
`mkdir -p ${WORKDIR}/rootfs/lib/firmware`
`cp /${WORKDIR}/bluez-firmware/broadcom/* /${WORKDIR}/rootfs/lib/firmware/`
`cp ${WORKDIR}/bluez-firmware/broadcom/* ${WORKDIR}/rootfs/lib/firmware/`
`cp -r /${WORKDIR}/firmware-nonfree/brcm/ ${WORKDIR}/rootfs/lib/firmware/`
`cp -r ${WORKDIR}/firmware-nonfree/brcm/ ${WORKDIR}/rootfs/lib/firmware/`
蓝牙相关固件放到 ${WORKDIR}/rootfs/lib/firmware/brcm/ 下:
`mv ${WORKDIR}/rootfs/lib/firmware/BCM43430A1.hcd ${WORKDIR}/rootfs/lib/firmware/brcm/`
`mv ${WORKDIR}/rootfs/lib/firmware/BCM4345C0.hcd ${WORKDIR}/rootfs/lib/firmware/brcm/`
### 将内核模块放进rootfs
`cp -r /${WORKDIR}/output/lib/modules /${WORKDIR}/rootfs/lib/`
`cp -r ${WORKDIR}/output/lib/modules ${WORKDIR}/rootfs/lib/`
## boot内容完善
### 将内核放进引导
`cp /${WORKDIR}/output/Image /${WORKDIR}/firmware/boot/kernel8.img`
`cp ${WORKDIR}/output/Image ${WORKDIR}/firmware/boot/kernel8.img`
### 将设备树文件放进引导
### 将dtb放进引导
`cp ${WORKDIR}/output/*.dtb ${WORKDIR}/firmware/boot/`
`cp /${WORKDIR}/output/*.dtb /${WORKDIR}/firmware/boot/`
`cp ${WORKDIR}/output/overlays/* ${WORKDIR}/firmware/boot/overlays/`
## 生成镜像并分区挂载
### 计算镜像大小
`du -sh --block-size=1MiB /${WORKDIR}/rootfs`
`du -sh --block-size=1MiB /${WORKDIR}/firmware/boot`
`du -sh --block-size=1MiB ${WORKDIR}/rootfs`
`du -sh --block-size=1MiB ${WORKDIR}/firmware/boot`
得到总大小略加1100MiB即可,将该大小记为 SIZE。
......
# 介绍
目前 openEuler 树莓派版本只支持 AArch64 架构。
编译内核时,除了使用 AArch64 架构的运行环境,也可以采用交叉编译的方式。这里,我们以 ubuntu16.04 x86_64 的服务器上编译内核为例,介绍交叉编译的过程。
# 实验环境
- 操作系统:ubuntu16.04
- 架构:x86_64
# 安装依赖软件
`apt-get install build-essential gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu bc libssl-dev -y`
# 编译
操作目录:${WORKDIR}
## 下载内核源码
`git clone git@gitee.com:openeuler/raspberrypi-kernel.git`
得到文件${WORKDIR}/raspberrypi-kernel。
## 进入内核源码
`cd ${WORKDIR}/raspberrypi-kernel`
## 切换分支
这里适用于树莓派的 openEuler-1.0-LTS 内核源码的分支为 openEuler-1.0-LTS-raspi,
`git checkout -b openEuler-1.0-LTS-raspi origin/openEuler-1.0-LTS-raspi`
## 设置环境变量
`export ARCH=arm64`
`export CROSS_COMPILE=aarch64-linux-gnu-`
## 载入默认配置
`make openeuler-raspi_defconfig`
其中 openeuler-raspi_defconfig 在 ../linux/arch/arm64/configs 下。
## 编译内核
`make -j9`
## 创建编译内核模块目录
`mkdir ${WORKDIR}/ouput`
## 编译内核模块
`make INSTALL_MOD_PATH=${WORKDIR}/output/ modules_install`
在 ${WORKDIR}/output 文件夹下会生成 lib 文件夹。
## 收集编译结果
### 内核
`cp ${WORKDIR}/raspberrypi-kernel/arch/arm64/boot/Image ${WORKDIR}/output/`
### 设备树文件等
`cp ${WORKDIR}/raspberrypi-kernel/arch/arm64/boot/dts/broadcom/*.dtb ${WORKDIR}/output/`
`mkdir ${WORKDIR}/output/overlays`
`cp ${WORKDIR}/raspberrypi-kernel/arch/arm64/boot/dts/overlays/*.dtb* ${WORKDIR}/output/overlays/`
至此,所有内核及内核模块相关内容都在 ${WORKDIR}/output 下了。
## 验证内核可用性
使用一个之前刷好 openEuler 树莓派镜像的 SD 卡,直接插到 Linux 主机上,SD 会默认挂载其 boot 分区和 根目录分区。这里其挂载路径分别表示为 ${boot} 和 ${rootfs},将上面编译好的内核放置到SD卡对应分区。
### 将内核模块放进rootfs
`cp -r ${WORKDIR}/output/lib/modules ${rootfs}/lib/`
### 将内核放进引导
`cp ${WORKDIR}/output/Image ${boot}/kernel8.img`
### 将设备树文件放进引导
`cp ${WORKDIR}/output/*.dtb ${boot}/`
`cp ${WORKDIR}/output/overlays/* ${boot}/overlays/`
之后,参考 [树莓派使用](./树莓派使用.md) 使用该 SD 卡启用树莓派,验证功能:
![](images/验证内核.jpg)
......@@ -2,6 +2,8 @@
版本要求:树莓派 3B/3B+/4B。
默认用户名:root,密码:openeuler。
将刷好的 SD 卡插入树莓派,通电启用。树莓派正常启动,还需连接网线至局域网。
由于使用树莓派时,大多都使用 ssh 远程连接;在树莓派启动联网时,无法得知其 IP 地址。
......@@ -16,4 +18,90 @@
连接显示器后,直接用户名/密码登陆,登陆成功后,树莓派即显示本机相关信息,包括本机 IP。如下图(ssh登陆也显示这些信息):
![](images/登录树莓派.jpg)
\ No newline at end of file
![](images/登录树莓派.jpg)
# 根目录分区扩展
默认根目录分区空间比较小,在使用之前,需要对分区进行扩容。
## 查看磁盘分区信息
`fdisk -l`
获取 SD 卡磁盘信息,例如 SD 卡对应磁盘为 /dev/mmcblk0。openEuler 镜像包括3个分区,分别为
- 引导分区 /dev/mmcblk0p1
- 交换分区 /dev/mmcblk0p2
- 根目录分区 /dev/mmcblk0p3
这里我们需要将根目录分区进行扩容。
## 分区扩容
### 操作磁盘 /dev/mmcblk0
`fdisk /dev/mmcblk0`
### 查看当前分区情况
`p`
记录下分区 /dev/mmcblk0p3 的起始扇区号,这里记为 `xxx`
### 删除分区 /dev/mmcblk0p3
`d`
### 选择要删除的分区序号
回车(默认为3)或 输入`3`
### 创建新的分区
`n`
### 选择创建分区类型
回车(默认为 p)或 输入`p`
### 选择要创建的分区序号
回车(默认为3)或 输入`3`
### 输入新分区的起始扇区号
`xxx`
这是输入删除分区 /dev/mmcblk0p3 之前查看到的的起始扇区号。
### 输入新分区的终止扇区号
回车
取默认的最后一个扇区号。
### 是否修改扇区标记
`N`
不修改。
### 保存并退出
`wq`
该操作结束后,使用 `fdisk -l` 命令可以看到 /dev/mmcblk0p3大小已经扩展。但是通过 `df -lh`可以看到根目录大小没有变化。
### 增大未加载的文件系统大小
`resize2fs /dev/mmcblk0p3`
如果该命令失败,可通过命令 `reboot`重启树莓派之后再执行`resize2fs /dev/mmcblk0p3`
该操作结束后,通过 `df -lh`可以看到根目录大小已经扩展。
至此,根目录分区扩容结束。扩容过程见下图:
![](images/分区扩容.jpg)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册