如何在小米 MIX 3 上安装 Arch Linux(基于 ED

2022-08-19  本文已影响0人  安安_660c

本教程将帮助您在小米 MIX 3 上安装 Arch LInux。您可以按照以下所有步骤从头开始构建所有内容,或者如果您想节省一些时间并想使用现成的内核和 rootfs,请跳过到第 3 步观看。

1.编译内核

1.1 安装依赖项

sudo apt install build-essential openssl pkg-config libssl-dev libncurses5-dev pkg-config minizip libelf-dev flex bison  libc6-dev libidn11-dev rsync bc liblz4-tool gcc-aarch64-linux-gnu dpkg-dev dpkg git

1.2 克隆内核源

mkdir ~/workspace
cd ~/workspace
git clone --depth 1 https://github.com/edk2-porting/linux-snapdragon.git -b linux-rolling-stable --single-branch linux

1.3 编译

cd ~/workspace/linux
make ARCH=arm64 defconfig sdm845_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc)
cp arch/arm64/boot/dts/qcom/sdm845-xiaomi-perseus.dtb ..

2.构建rootfs

2.1 下载 ArchLinux rootfs

cd ~/workspace
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz

2.2 自定义 rootfs

设置 chroot 环境:

sudo apt install qemu-user-static
dd if=/dev/zero of=archlinux.img bs=1G count=6
mkfs.ext4 archlinux.img
mkdir arch
sudo mount archlinux.img arch
cd arch
sudo tar -xpvf ../ArchLinuxARM-aarch64-latest.tar.gz
sudo mv etc/resolv.conf etc/resolv.conf.bak
sudo cp /etc/resolv.conf etc/
cd ..
sudo mount --bind /dev arch/dev
sudo mount -t devpts devpts arch/dev/pts -o gid=5,mode=620
sudo mount -t proc proc arch/proc
sudo mount -t sysfs sysfs arch/sys
sudo mount -t tmpfs tmpfs arch/run
sudo chroot arch

初始化 pacman:

pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syyu
exit

安装新内核和固件:

cd ~/workspace/linux
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=~/workspace/arch modules_install
sudo make ARCH=arm64 INSTALL_PATH=~/workspace/arch/boot install

devicetree从内核目录复制linux到引导:

cd ~/workspace
sudo cp linux/arch/arm64/boot/dts/qcom/sdm845-xiaomi-perseus.dtb arch/boot/

从这里下载 MIX 3 的固件,解压缩并将“固件”文件夹移动到“工作区”文件夹。

cd ~/workspace
sudo cp -r firmware ~/workspace/arch/root
sudo chroot arch
cd ~
cp -r ~/firmware/* /usr/lib/firmware/
rm -r ~/firmware
ldconfig
ls /usr/lib/modules //get kernel version
mkinitcpio --generate /boot/initrd.img-5.17.8-sdm845+ --kernel 5.17.8-sdm845+ //replace 5.17.8-sdm845+ with your kernel version got from above command
exit

设置时区:

cd ~/workspace
sudo chroot arch
ln -sf /usr/share/zoneinfo/Asia/Phnom_Penh /etc/localtime
nano /etc/locale.gen //uncomment en_US.UTF-8 UTF-8
locale-gen
nano /etc/locale.conf //change `LANG=C` to `LANG=en_US.UTF-8`

更改主机名:

echo 'MIX3' > /etc/hostname

设置用户:

passwd alarm //change its password. Default is "alarm"
usermod -aG wheel alarm
pacman -S sudo
EDITOR=nano visudo //uncomment by delete '#' from this line '#%wheel ALL=(ALL:ALL) ALL'

安装一些必备软件:

pacman -S base base-devel dhcpcd iwd grub efibootmgr networkmanager modemmanager bluez bluez-utils pulseaudio-bluetooth qrtr rmtfs git wget ntfs-3g usbutils
systemctl enable NetworkManager bluetooth qrtr-ns rmtfs

为 LTE 配置调制解调器管理器:

su alarm
mkdir ~/modemmanager
cd ~/modemmanager
nano PKGBUILD

复制PKGBUILD的内容并进行以下更改:

更改arch=(x86_64)arch=(x86_64 aarch64)

删除-D plugin_qcom_soc=disabled

makepkg -rsi
cd ..
sudo rm -rf ~/modemmanager
sudo systemctl enable ModemManager
exit

编译并pd-mapper安装tqftpserv

su alarm
cd ~
git clone https://aur.archlinux.org/pd-mapper-git.git ~/pd-mapper-git
cd pd-mapper-git
nano PKGBUILD //on the `source=` line, replace `git:` with `git+http:`
makepkg -si
cd ..
git clone https://aur.archlinux.org/tqftpserv-git.git ~/tqftpserv-git
cd tqftpserv-git
nano PKGBUILD //on the `source=` line, replace `git:` with `git+http:`
makepkg -si
cd ..
sudo rm -rf *
sudo systemctl enable tqftpserv pd-mapper
exit

修复音频:

su alarm
cd ~
git clone https://github.com/xperseus-dev/alsa-ucm-perseus.git
cd alsa-ucm-perseus
makepkg -si
exit

添加桌面环境:

pacman -S gnome
systemctl enable gdm

清理:

pacman -Scc
su alarm
cat /dev/null > ~/.bash_history && history -c && exit
cat /dev/null > ~/.bash_history && history -c && exit

卸载 rootfs:

cd ~/workspace
sudo umount ~/workspace/arch/run
sudo umount ~/workspace/arch/sys
sudo umount ~/workspace/arch/proc
sudo umount ~/workspace/arch/dev/pts
sudo umount ~/workspace/arch/dev

使用 tar 打包 rootfs:

cd ~/workspace/arch
sudo tar -czvf ~/workspace/arch.tar.gz *

3.安装到手机

如果还没有,请确保解锁引导加载程序并安装 TWRP。

修改分区

重启手机到TWRP并连接PC,进入ADB shell:

adb shell

parted复制到内部存储,并在您的PC上输入以下命令:

cp /sdcard/parted /sbin/ && chmod 755 /sbin/parted
umount /data && umount /sdcard
parted /dev/block/sda

在parted中,执行以下操作:

p
resizepart 22
64GB //total storage for MIX 3 is 123GB, resize userdata to 64GB, you have around 59GB for esp and linux
mkpart esp fat32 64GB 65GB
mkpart linux ext4 65GB 123GB
set 23 esp on
q

重启 TWRP 并再次进入 ADB shell:

adb shell
mke2fs -t ext4 /dev/block/by-name/userdata
mkfs.fat -F32 -s1 /dev/block/by-name/esp
mke2fs -t ext4 /dev/block/by-name/linux

再次重新启动 TWRP 并获取 UUID,记下用于 grub 配置的 UUID:

blkid /dev/block/by-name/linux

准备rootfs:

从上面的第 2 步,将你的 'archh.tar.gz' 复制到内部存储,如果你使用我现成的rootfs,默认用户是 'alarm' 和密码是 '123456',然后在 ADB shell 中输入以下命令:

mkdir /linux
mount /dev/block/by-name/linux /linux
cd /linux
tar -xpvf /sdcard/arch.tar.gz

准备 GRUB:

下载grub.zip并复制到内部存储,解压缩并将文件复制到每个分区:

在 adb 外壳中:

cd /sdcard
unzip grub.zip
mkdir /esp
mount /dev/block/by-name/esp /esp
cp -r /sdcard/esp/* /esp/

grub.cfg在 adb shell 中修改 UUID :

nano /esp/EFI/arch/grub.cfg
//replace every UUID `4a857297-e07c-45b2-a277-3fc6f9ba1f7f` to your UUID
//replace kernel version from `5.17.8-sdm845+` to your kernel version

重新启动到引导加载程序,并刷新 Mix 3 的 UEFI 映像,在此处下载:

fastboot flash boot boot-perseus.img
fastboot reboot

在启动时选择 Arch Linux。完毕!恭喜!

链接:https://xperseus.dev/how-to-install-arch-linux-on-xiaomi-mi-mix-3-based-on-edk2

上一篇下一篇

猜你喜欢

热点阅读