postmarketOS

Use Docker on a Xiaomi Redmi 4X

VirgilPosted by

I just got a broken Xiaomi Redmi 4X from a friend, the phone is working well but the buttons at the bottom of the phone are not responding any more. This phone has 3 different versions, it can have 2, 3 or 4GB of memory and that’s enough to use it as a server. Mine has 3GB of memory and 32GB of storage.

Preparation

Required material

  • A computer with GNU/Linux
  • A micro USB Cable
  • A Redmi 4X, also named Santoni with the bootloader unlocked

Software

Install pmbootstrap following the official guide on your GNU/Linux computer. If you don’t have it, install also git. If not specified, the commands will be run from your computer.

Postmarket OS preparation

To use Docker on our device, we will install postmarketOS on it. This system, based on Alpine Linux, is really minimalist.

Lets download the project

pmbootstrap init

For the questions

Enter to use the default Work path
Channel: edge
Vendor: xiaomi
Device codename: santoni
Enable this package: y
Username: your future username
User interface: none (no needs for a server)
Change boot partition size: n
Extra packages: none
Timezone: change it if required, else enter y
Device hostname: your device hostname
Build outdated packages: y

Replace the file ~/.local/var/pmbootstrap/cache_git/pmaports/device/testing/linux-xiaomi-santoni/config-xiaomi-santoni.aarch64 with the content of the following file:

Open the file ~/.local/var/pmbootstrap/cache_git/pmaports/device/testing/linux-xiaomi-santoni/APKBUILD and add to the build function

make ARCH="$_carch" CC="${CC:-gcc}" CFLAGS_MODULE="-fno-pic" \
       KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" modules

And to the package function:

cd "$builddir"
unset LDFLAGS
make ARCH="$_carch" CC="${CC:-gcc}" \
   KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" \
   INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1 \
   modules_install

We will now configure pmbootstrap to enable our modifications and compile our new kernel.

pmbootstrap pkgrel_bump linux-xiaomi-santoni
pmbootstrap checksum linux-xiaomi-santoni
pmbootstrap kconfig check -f
pmbootstrap build linux-xiaomi-santoni --force

Flashing to the device

Hold volume down key and the power button to boot in Fastboot mode and plug your device to your computer.

pmbootstrap install

Lets flash our device

pmbootstrap flasher flash_rootfs
pmbootstrap flasher flash_kernel

Reboot the device

Docker installation

Connect to your device

ssh user@172.16.42.1

Configure the WiFi network

sudo nmcli --ask dev wifi connect

Install docker, enable cgroups, add everything on startup and start the daemons

sudo apk add docker
sudo rc-update add cgroups
sudo rc-update add docker
sudo service cgroups start
sudo service docker start

We can now check if docker is working

xiaomi-santoni:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Partitions

The system is flashed in a 3GB partition, so there is extra space that we could use. Run the following command from SSH and pick the biggest partition (/dev/mmcblk0p49 for me).

sudo fdisk -l

Format it using ext4 (don’t forget to adapt to your case)

mkfs.ext4 /dev/mmcblk0p49

Our partition is now ready, you can mount it using the /etc/fstab file, some suggestions:

  • /home
  • /var/lib/docker
  • /var/log

You can also split it and adapt the result to your use case. To extend the storage you can add a micro sd card.

Conclusion

We have installed postmarketOS and Docker on our phone. Tell me in the comments how you plan to use yours. On my side, it will run some basics tools and maybe an integration server for my code.

Bugs encountered:

  • It needs to be started before plugging it
  • htop is showing a load average of 4 minimum, even if only the default services are started
  • Difficult to switch off the device, I have to disconnect it from the power cable and power it off using ssh

2 comments

  1. hi, I have a Xiaomi mi A1 (tissot) at the time of modifying the kernel by changing the parameters of cgroup that are in your file (.aarch64) and adding the modules to the APKBUILD the compilation fails. Any recommendation?

Leave a Reply

Your email address will not be published. Required fields are marked *