How to Install Arch Linux on Xiaomi Mi MIX 3 (based on EDK2)

How to Install Arch Linux on Xiaomi Mi MIX 3 (based on EDK2)


5 min read

This tutorial will help you to install Arch LInux on Xiaomi Mi MIX 3. You can follow all the steps below to build everything from scratch, or if you would like to save some time and want to use the ready built kernel and rootfs, please skip to Step 3, all the files you need for Step 3 are here.

1. Compiling kernel

1.1. Install dependencies

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. Clone kernel source

mkdir ~/workspace
cd ~/workspace
git clone --depth 1 -b linux-rolling-stable --single-branch linux

1.3. Compile

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. Build rootfs

2.1. Download ArchLinux rootfs

cd ~/workspace

2.2. Customize rootfs

Setup chroot environment:

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

Initialize pacman:

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

Install new kernel and firmware:

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

Copy devicetree from kernel directory linux to boot:

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

Download firmware for MIX 3 from here, unzip and move 'firmware' folder to 'workspace' folder.

cd ~/workspace
sudo cp -r firmware ~/workspace/arch/root
sudo chroot arch
cd ~
cp -r ~/firmware/* /usr/lib/firmware/
rm -r ~/firmware
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

Set time zone:

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
nano /etc/locale.conf //change `LANG=C` to `LANG=en_US.UTF-8`

Change hostname:

echo 'MIX3' > /etc/hostname

Setup user:

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'

Install some essentials software:

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

Configure modem manager for LTE:

su alarm
mkdir ~/modemmanager
cd ~/modemmanager

Copy contents of PKGBUILD and make below changes:

Change arch=(x86_64) to arch=(x86_64 aarch64)

Delete -D plugin_qcom_soc=disabled

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

Compile and install pd-mapper and tqftpserv:

su alarm
cd ~
git clone ~/pd-mapper-git
cd pd-mapper-git
nano PKGBUILD //on the `source=` line, replace `git:` with `git+http:`
makepkg -si
cd ..
git clone ~/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

Fix audio:

su alarm
cd ~
git clone
cd alsa-ucm-perseus
makepkg -si

Add desktop environment:

pacman -S gnome
systemctl enable gdm

Cleaning up:

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

Unmount 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

Package rootfs using tar:

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

3. Install to phone

Make sure to unlock bootloader and install TWRP, if you haven't.

3.1. Modify partition

Reboot your phone to TWRP and connect to PC, and enter ADB shell:

adb shell

Copy parted to internal storage, and enter below command on your PC:

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

In parted, do below:

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

Reboot TWRP and enter ADB shell again:

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

Reboot TWRP again and get UUID, note down the UUID for grub configuration:

blkid /dev/block/by-name/linux

Prepare rootfs:

From Step 2 above, copy your 'archh.tar.gz' to internal storage, if you use my ready-built rootfs, the default user is 'alarm' and password is '123456', then input below command in ADB shell:

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

Prepare GRUB:

Download and copy to internal storage, unzip and copy files to each partition:

In adb shell:

cd /sdcard
mkdir /esp
mount /dev/block/by-name/esp /esp
cp -r /sdcard/esp/* /esp/

Modify UUID in grub.cfg in adb shell:

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

Reboot to bootloader, and flash UEFI image for Mix 3, download here:

fastboot flash boot boot-perseus.img
fastboot reboot

Select Arch Linux on boot. Done! Congratulations!

Adapted from original tutorial for Oneplus6T: Source

Did you find this article valuable?

Support Perseus X by becoming a sponsor. Any amount is appreciated!