User:Z3ntu/Tips-and-tricks

From postmarketOS Wiki

Install apk in debug-shell

To install apk.static in initramfs (debug-shell), after running this you can just run e.g. apk add i2ctools and use that.

# See "USB Internet" page
route add default gw 172.16.42.2
echo nameserver 1.1.1.1 > /etc/resolv.conf

(
set -e
arch="$(uname -m)"
if [ "$arch" = "aarch64" ]; then
    file="$(wget -q -O- http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/ | sed -n '/apk-tools-static/s/.*>\(apk-tools-static-.*\.apk\)<.*/\1/p')"
    wget http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/"$file"
elif [ "$arch" = "armv7l" ]; then
    file="$(wget -q -O- http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/ | sed -n '/apk-tools-static/s/.*>\(apk-tools-static-.*\.apk\)<.*/\1/p')"
    wget http://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/"$file"
fi
tar -xvf apk-tools-static-*.apk
ln -s /sbin/apk.static /sbin/apk
mkdir -p /etc/apk/
echo -e "http://mirror.postmarketos.org/postmarketos/master\nhttp://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories
apk add --allow-untrusted --initdb alpine-keys postmarketos-keys
)

Mount rootfs from debug-shell and chroot into it

set -x
mount_root_partition
cd /sysroot
mount -t proc /proc proc/
mount -t sysfs /sys sys/
mount --rbind /dev dev/
chroot /sysroot