Skip to main content

Turning an Old Android Phone into a Server (Redmi 4X [santoni])

Turning an Old Android Phone into a Server (Redmi 4X [santoni])
hahnavi hahnavi

This is my rough-and-ready notes for turning a Redmi 4X (santoni) into a tiny Linux server. Huge credit to the original work here: https://github.com/dreemurrs-embedded/arch-linux-santoni

Quick heads‑up: this will wipe and rework partitions, so don’t do it on a phone you still need as a phone. Backups first.

What I used

  • A Linux host
  • USB cable
  • Some patience

Create a rootfs image

dd if=/dev/zero of=rootfs.img bs=1M count=2560

Format it as ext4

mkfs.ext4 rootfs.img

Mount it

sudo mount rootfs.img /mnt/rootfs

Grab Arch Linux ARM64 rootfs

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

Extract into the image

sudo bsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C /mnt/rootfs

Install qemu-user-static

sudo pacman -S qemu-user-static

Setup DNS inside the rootfs

sudo mv /mnt/rootfs/etc/resolv.conf /mnt/rootfs/etc/resolv.conf.ori
echo "nameserver 8.8.8.8" | sudo tee /mnt/rootfs/etc/resolv.conf

Copy qemu-user-static into the rootfs

sudo cp `which qemu-aarch64-static` /mnt/rootfs/sbin/

Bind mount dev/proc/sys

sudo mount -o bind /dev /mnt/rootfs/dev
sudo mount -t proc proc /mnt/rootfs/proc
sudo mount -t sysfs sysfs /mnt/rootfs/sys
sudo mount -t devpts devpts /mnt/rootfs/dev/pts

Chroot into the rootfs

sudo chroot /mnt/rootfs /sbin/qemu-aarch64-static /bin/bash

Switch pacman mirror to something close to you

vi /etc/pacman.d/mirrorlist
...
# Server = http://mirror.archlinuxarm.org/$arch/$repo
...
...
Server = http://sg.mirror.archlinuxarm.org/$arch/$repo
...

Initialize pacman keys

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

Update packages

pacman -Syu

Install build tools and sudo

pacman -S sudo base-devel git

Note: you shouldn’t run makepkg as root.

Allow wheel group to use sudo

visudo
...
%wheel ALL=(ALL:ALL) NOPASSWD: ALL
...

Switch to the alarm user

su - alarm

Clone the repo

git clone https://github.com/dreemurrs-embedded/arch-linux-santoni.git

Install firmware

cd arch-linux-santoni/Arch_PKGBUILDs/firmware-xiaomi-santoni
makepkg -si

Install firmware loader

cd ../postmarketos-firmware-loader/
makepkg -si

Install USB networking

cd ../postmarketos-usb-networking/
makepkg -si

Install WCNSS WLAN

cd ../postmarketos-wcnss-wlan/
makepkg -si

Set up SSH keys

mkdir ~/.ssh
chmod 700 ~/.ssh
echo "<public key>" | tee ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Exit back to root

exit

Enable USB networking

systemctl enable usb_networking.service

Set up DHCP Edit /etc/dhcpcd.conf and add:

interface rndis0
static ip_address=172.16.42.1/24
static routers=172.16.42.1
static domain_name_servers=8.8.8.8

Enable dhcpcd

systemctl enable dhcpcd.service

Enable WCNSS WLAN

systemctl enable wcnss-wlan.service

Add root partition to /etc/fstab

echo "/dev/mmcblk0p49 / ext4 rw,relatime 0 1" | tee /etc/fstab

Clean pacman cache

pacman -Scc

Restore the original resolv.conf

rm /etc/resolv.conf
mv /etc/resolv.conf.ori /etc/resolv.conf

Exit chroot

exit

Unmount

sudo umount /mnt/rootfs/dev/pts
sudo umount /mnt/rootfs/dev
sudo umount /mnt/rootfs/sys
sudo umount /mnt/rootfs/proc
sudo umount /mnt/rootfs

Flash img

fastboot flash userdata rootfs.img

…to be continued…

Share

comments powered by Disqus