Jump to content

Installing packages on a running phone

From postmarketOS Wiki
Warning WARNING: Do not install suspicious apk packages from unknown sources!

This article explains how to install packages that were built with pmbootstrap on your phone via Wi-Fi or USB network.

pmbootstrap sideload

This method copies a package via SSH to your phone and installs it. It makes installing a single package relatively easy. If you need to install multiple packages with dependencies on each other, hosting a repository locally (see below) is recommended instead.

Connect your phone using USB Network (or Wi-Fi) and make sure you can login into it with SSH. Then excecute the following:

pc:~$ pmbootstrap sideload --host 172.16.42.1 --user user --arch <arch> package-name

replace arch with actual architecture (for example, aarch64).

Add --install-key argument if you see the error about untrusted signature.

Add --port NUM if your device's SSH server is running on a non-standard port (not 22). This may be needed for example, for an image that is running using pmbootstrap qemu (see QEMU).

For Wi-Fi use your device's Wi-Fi IP address.

Host a reverse proxy to postmarketOS and Alpine Repositories

When you don't have the access to Internet, it would be annoying to setup route and packet forwarding/masquerading on a PC. What if you just want to install a package from apk repositories, but it depends on a lot of packages? This guide shows you how to setup a reverse proxy to APK repositories on PC.

Nginx

We use Nginx for example.

Installation

Debian/Ubuntu

# apt-get install nginx

Fedora/RHEL/CentOS/Rocky

# dnf install nginx

Alpine/postmarketOS

# apk add nginx

Configuration

Reverse proxy

The configs could be stored in /etc/nginx/conf.d/ or /etc/nginx/http.d/. In this config we use port 8000.

# nano /etc/nginx/http.d/apk_reverse_proxy.conf
server {
	listen 8000;
	listen [::]:8000;

	location /alpine {
		proxy_pass http://dl-cdn.alpinelinux.org/alpine;
	}

	location /postmarketos {
		proxy_pass http://mirror.postmarketos.org/postmarketos;
	}
}

Local repository server

Like the other HTTP servers, Nginx can serve a local path. Note that a standard HTTP port 80 is used in this example.

# nano /etc/nginx/http.d/apk_local_repo.conf
server {
	listen 80;
	listen [::]:80;

	location /local {
        	alias /home/user/.local/pmbootstrap/packages;
	        autoindex on;
	}
}

All-in-one

# nano /etc/nginx/http.d/apk_aio.conf
server {
	listen 80;
	listen [::]:80;

	location /alpine {
		proxy_pass http://dl-cdn.alpinelinux.org/alpine;
	}

	location /postmarketos {
		proxy_pass http://mirror.postmarketos.org/postmarketos;
	}

	location /local {
        	alias /home/user/.local/pmbootstrap/packages;
	        autoindex on;
	}
}

Restart

Restart to apply the changes.

systemd distros

# systemctl restart nginx

OpenRC distros

# rc-service nginx restart

Add the repository

http://172.16.42.2/local/edge
http://172.16.42.2/postmarketos/master
http://172.16.42.2/alpine/edge/main
http://172.16.42.2/alpine/edge/community
http://172.16.42.2/alpine/edge/testing

http://mirror.postmarketos.org/postmarketos/master
http://dl-cdn.alpinelinux.org/alpine/edge/main
http://dl-cdn.alpinelinux.org/alpine/edge/community
http://dl-cdn.alpinelinux.org/alpine/edge/testing

Install packages

# apk update
fetch http://172.16.42.2/local/edge/aarch64/APKINDEX.tar.gz
fetch http://172.16.42.2/postmarketos/master/aarch64/APKINDEX.tar.gz
fetch http://172.16.42.2/alpine/edge/main/aarch64/APKINDEX.tar.gz
fetch http://172.16.42.2/alpine/edge/community/aarch64/APKINDEX.tar.gz
fetch http://172.16.42.2/alpine/edge/testing/aarch64/APKINDEX.tar.gz
2022-10-21 23:17:22.167857 [http://172.16.42.2/local/edge]
2022-10-22 12:50:04.451869 [http://172.16.42.2/postmarketos/master]
v20220809-6418-g42ed31be94 [http://172.16.42.2/alpine/edge/main]
v20220809-6433-g8fe86c9aea [http://172.16.42.2/alpine/edge/community]
v20220809-6434-geafcdb2299 [http://172.16.42.2/alpine/edge/testing]
# apk add postmarketos-ui-phosh

Host repository locally using a web server with Python http.server

This method is easier when you need to install multiple dependent packages at once, or simulate the regular upgrade process from repositories. For single packages, pmbootstrap sideload is probably easier, see above.

Start the webserver

Go to the pmbootstrap packages dir and start a web server:

pc:~$ cd ~/.local/var/pmbootstrap/packages/edge && python3 -m http.server

Add the repository

Install your favorite editor and open /etc/apk/repositories on your phone via SSH:

phone:~$ sudo apk add neovim
phone:~$ sudo nvim /etc/apk/repositories

Add your own repository on top:

http://172.16.42.2:8000

http://mirror.postmarketos.org/postmarketos/v20.05
http://dl-cdn.alpinelinux.org/alpine/v3.12/main
http://dl-cdn.alpinelinux.org/alpine/v3.12/community

Copy the package signing keys

If you did not generate the postmarketOS installation from the same PC, which is now running pmbootstrap to build the packages you want to install, then you need to copy the package signing keys. Otherwise, apk will refuse to install the packages ("UNTRUSTED signature").

On your PC (replace 172.16.42.1 with the IP of your phone, user with your ssh username, mind the : at the end of the scp command):

pc:~$ scp ~/.local/var/pmbootstrap/config_apk_keys/pmos*.rsa.pub user@172.16.42.1:
pc:~$ ssh user@172.16.42.1

Run on your phone via SSH:

phone:~$ sudo mv pmos*.rsa.pub /etc/apk/keys/

Use your repository

Now apk should recognize your repository, and you should be able to install or upgrade packages built on your PC:

phone:~$ sudo apk update
fetch http://172.16.42.2:8000/aarch64/APKINDEX.tar.gz
fetch http://postmarketos1.brixit.nl/postmarketos/v20.05/aarch64/APKINDEX.tar.gz                                                                  
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/aarch64/APKINDEX.tar.gz                                                                     
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/aarch64/APKINDEX.tar.gz                                                                
postmarketOS [http://172.16.42.2:8000]
2020-09-01 17:02:31.099145 [http://postmarketos1.brixit.nl/postmarketos/v20.05]                                                                   
v3.12.0-283-g612cd12ab6 [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]                                                                         
v3.12.0-276-gbdd3966958 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]                                                                    
OK: 12967 distinct packages available
phone:~$ sudo apk upgrade hello-world

pmos-update-kernel

Warning WARNING: Do not use pmos-update-kernel on lk2nd devices, such as MSM8916 devices. lk2nd in boot partition will be replaced and the booting will be broken!

While devices in main and community categories are expected to update the kernel fully automatically, many Android devices currently need to run pmos-update-kernel after a kernel upgrade, to actually write the new kernel to the partition expected by the bootloader (see boot process). You should check the page for your device or it's platform to know if you need this extra step.

Run it manually

Install postmarketos-update-kernel, figure out the kernel flavor (in the example below: postmarketos-qcom-msm8974) and update the kernel:

phone:~$ sudo apk add postmarketos-update-kernel
phone:~$ ls /boot/boot.img-*
/boot/boot.img-postmarketos-qcom-msm8974
phone:~$ sudo pmos-update-kernel postmarketos-qcom-msm8974

Automate with a script

If you're experimenting with mainline kernel and adding new features you might end up wanting to update your kernel and restart your phone very often. On the kernel building end you can use envkernel.sh + pmbootstrap build --envkernel MAINLINE_LINUX_PACKAGE_NAME. That will produce a fresh new kernel package with the changes you made. Then you need to install that package to the phone.

Use this script to automate the steps above (adjust postmarketos-qcom-msm8974!):

#!/bin/sh -ex
# Upgrade all packages (should have your kernel upgrade)
sudo apk update
sudo apk add postmarketos-update-kernel
sudo apk upgrade

# Write kernel to location expected by LK
sudo pmos-update-kernel postmarketos-qcom-msm8974

# Prompt for restart
set +x
echo -n 'reboot [yN]? '
read ans
test "$ans" = 'y' && sudo reboot