官方文档:https://wiki.lineageos.org/devices/mars/
适配设备:小米11Pro(已解BL),代号mars
笔者系统环境:Ubuntu24.04,64G RAM,1T HDD
编译系统版本:LineageOS 23.2
若自行编译,请准备一个满足条件的Linux环境,官方建议lineage-21以上版本的系统,需要64G以上RAM,至少400GB可用空间,此外还要加上ccache等空间,固态硬盘最佳。
一、更新软件源与安装相关依赖
# 更新软件源
sudo apt update -y# 安装相关依赖
sudo apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick protobuf-compiler python3-protobuf lib32readline-dev lib32z1-dev libdw-dev libelf-dev libgnutls28-dev lz4 libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc xxd zip zlib1g-dev -y# 官方: 在Ubuntu23.10以上系统,编译LineageOS 20或以上版本,需要按照以下办法安装libncurses5
wget https://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2_amd64.deb && sudo dpkg -i libtinfo5_6.3-2_amd64.deb && rm -f libtinfo5_6.3-2_amd64.deb
wget https://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libncurses5_6.3-2_amd64.deb && sudo dpkg -i libncurses5_6.3-2_amd64.deb && rm -f libncurses5_6.3-2_amd64.deb# Java
# 不同的 LineageOS 版本需要不同版本的 JDK(Java 开发工具包)
# LineageOS 18.1+: OpenJDK 11 (源码中已包含)# Python
# 不同的LineageOS 版本需要不同的默认Python版本
# LineageOS 17.1+: Python 3 (install python-is-python3)
sudo apt install python-is-python3 -y
二、配置代码仓库工具Repo
repo介绍
ref: https://blog.csdn.net/wjjontheway/article/details/124128462
# 创建工具目录
mkdir -p ~/bin
# 下载Repo工具
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
# 授予可执行权限
chmod a+x ~/bin/repo
# 使用nano编辑~/.profile
nano ~/.profile# 添加以下内容到环境变量中(添加repo工具到环境变量)
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; thenPATH="$HOME/bin:$PATH"
fi# source环境变量使其生效
source ~/.profile
三、配置Git环境
# repo需要进行身份验证,需要配置身份信息
git config --global user.email "you@example.com"
git config --global user.name "Your Name"# 开启lfs(Large File Storage)支持
git lfs install
四、启用缓存功能,加快构建速度
# 可以自行选择添加到环境变量中(~/.bashrc)
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache# 指定ccache使用的磁盘空间上限
ccache -M 50G
五、初始化LineageOS源代码仓库
代理加速相关
# 指定repo工具镜像
export REPO_URL='https://mirrors.ustc.edu.cn/aosp/git-repo'
# 替换AOSP仓库
git config --global url."https://mirrors.ustc.edu.cn/aosp/".insteadOf https://android.googlesource.com/
git config --global url."https://gitclone.com/github.com/LineageOS/".insteadOf https://github.com/LineageOS/
# 配置镜像加速
git config --global url."https://hub.fastgit.xyz/".insteadOf https://github.com/
代码同步
# 创建源码目录并进入
mkdir -p ~/android/lineage
cd ~/android/lineage
# 初始化仓库(使用镜像)
# repo init -u https://github.com/LineageOS/android.git -b lineage-23.2 --git-lfs --no-clone-bundle
repo init -u https://mirrors.cernet.edu.cn/lineageOS/LineageOS/android.git -b lineage-23.2 --git-lfs --no-clone-bundle
# 同步源码(耗时较长)
# 若出现409证明请求限流,可以使用参数-j 3降低并发数
# 使用-c只获取当前分支版本,而不是所有可用分支版本
repo sync
六、编译
准备编译环境
# 进入源代码目录
cd ~/android/lineage
# 设置编译环境
source build/envsetup.sh
# 使用croot可以一键回到根目录(没报错就OK)
croot
提取专有数据块
# 进入以下目录
cd ~/android/lineage/device/xiaomi/mars
# 执行
./extract-files.py [ROM.zip路径]
# 或执行
./extract-files.sh [ROM.zip路径]
获取设备专有配置和内核
# breakfast 代号
breakfast mars
开始编译
make -j
编译结果
# 进入输出目录
cd $OUT
# 内核
boot.img
# ROM包
lineage-23.2-20260727-UNOFFICIAL-mars.zip
七、刷入系统
ref: https://wiki.lineageos.org/devices/mars/install/#flashing-additional-partitions
1、电脑安装adb工具包
此处省略
2、关机进入Fastboot模式
关机情况下,按音量-+电源,直到出现FASTBOOT字样
3、刷入dtbo和vendor_boot包并重启到bootloader
fastboot flash dtbo dtbo.img
fastboot flash vendor_boot vendor_boot.img
fastboot reboot bootloader
4、刷入revocery包并重启到recovery模式下
fastboot flash boot boot.img
fastboot reboot recovery
5、双清
Factory Reset->Format data / factory reset
返回到主菜单
Apply update->Apply from ADB
电脑侧载ROM包
adb -d sideload lineage-23.2-20260727-UNOFFICIAL-mars.zip
如果中途提示签名错误,点击忽略。