A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
feat(rootfs,kernel): VSOCK builtin, hvc0 console gate, ZRAM 1.5x, OOM-protect, audio routing
ExTv81b2e284993c
diff --git a/Dockerfile b/Dockerfileindex 0cbb056..3f8cb4e 100644--- a/Dockerfile+++ b/Dockerfile@@ -114,6 +114,9 @@ RUN printf '%s\n' \'CONFIG_SECURITY_APPARMOR=y' \'CONFIG_IP6_NF_MANGLE=y' \'CONFIG_BINFMT_MISC=y' \+ 'CONFIG_VSOCKETS=y' \+ 'CONFIG_VSOCKETS_DIAG=y' \+ 'CONFIG_VIRTIO_VSOCKETS=y' \> /tmp/forced_builtin.configRUN cd linux-${KERNEL_VERSION} \&& make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig \@@ -131,7 +134,8 @@ RUN cd linux-${KERNEL_VERSION} \VETH TUN NF_TABLES NF_NAT NETFILTER OVERLAY_FS FUSE_FS \EXT4_FS_SECURITY SQUASHFS_XATTR SQUASHFS_ZSTD \DECOMPRESS_ZSTD ZSTD_DECOMPRESS \- IKCONFIG IKCONFIG_PROC BINFMT_MISC; do \+ IKCONFIG IKCONFIG_PROC BINFMT_MISC \+ VSOCKETS VIRTIO_VSOCKETS; do \grep -q "^CONFIG_${opt}=y\$" .config \|| { echo "FATAL: CONFIG_${opt} is not =y after merge" >&2; \grep "CONFIG_${opt}" .config >&2; exit 1; }; \diff --git a/build-rootfs/files/etc/init.d/podroid-bootstrap b/build-rootfs/files/etc/init.d/podroid-bootstrapindex 1a73557..716d848 100644--- a/build-rootfs/files/etc/init.d/podroid-bootstrap+++ b/build-rootfs/files/etc/init.d/podroid-bootstrap@@ -77,14 +77,33 @@ start() {printf '+cpuset +cpu +io +memory +hugetlb +pids +rdma\n' \> /sys/fs/cgroup/cgroup.subtree_control 2>/dev/null- # ZRAM swap (half RAM, lz4)+ # ZRAM swap (1.5x RAM, lz4). Was half-RAM; with lz4 averaging ~3x+ # compression on text/heap pages, 1.5x RAM disksize gives ~4.5x effective+ # memory under pressure — enough headroom for Firefox + XFCE in a 2 GB VM+ # without thrashing into OOM.if [ -b /dev/zram0 ]; then_mem_kb=$(awk '/^MemTotal:/{print $2}' /proc/meminfo)echo lz4 > /sys/block/zram0/comp_algorithm 2>/dev/null- echo $((_mem_kb * 512)) > /sys/block/zram0/disksize 2>/dev/null+ echo $((_mem_kb * 1536)) > /sys/block/zram0/disksize 2>/dev/nullmkswap /dev/zram0 >/dev/null 2>&1 && swapon -p 100 /dev/zram0 2>/dev/nullfi+ # OOM tuning: prefer killing leaf user-apps (Firefox, browsers, npm,+ # webpack) over our infrastructure. Higher score = killed first. -1000+ # = OOM-immune (set in podroid-ready for dropbear/Xvnc/agent so all+ # those services exist by then). Bumping the OOM "score adjustment"+ # for non-protected processes is left to the kernel default. The big+ # win is making sure VNC + SSH + the host-vsock relay survive even+ # when a memory-hog browser tab gets reaped.+ [ -w /proc/sys/vm/oom_kill_allocating_task ] && \+ echo 0 > /proc/sys/vm/oom_kill_allocating_task+ # overcommit_memory=1 (always overcommit) lets us actually hand out+ # the address space Firefox wants without ENOMEM at mmap time —+ # without this, browsers can crash with malloc failures long before+ # the kernel's OOM killer ever fires.+ [ -w /proc/sys/vm/overcommit_memory ] && \+ echo 1 > /proc/sys/vm/overcommit_memory+# sysctl for container networkingsysctl -qw net.ipv4.ip_forward=1 \net.ipv4.conf.all.forwarding=1 \diff --git a/build-rootfs/files/etc/init.d/podroid-network b/build-rootfs/files/etc/init.d/podroid-networkindex 7cd629d..8647efd 100644--- a/build-rootfs/files/etc/init.d/podroid-network+++ b/build-rootfs/files/etc/init.d/podroid-network@@ -24,7 +24,7 @@ start() {fiip link set "$NETIF" up- if grep -q 'podroid\.tty=ttyS0' /proc/cmdline 2>/dev/null; then+ if grep -q 'podroid\.backend=avf' /proc/cmdline 2>/dev/null; then# AVF backend: crosvm wires the guest to a TAP that Android's tethering# manager runs DHCP on. The lease decides our IP / gateway / DNS — the# SLIRP-style 10.0.2.15 hardcode won't sit on the right subnet (ondiff --git a/build-rootfs/files/etc/init.d/podroid-ready b/build-rootfs/files/etc/init.d/podroid-readyindex a7e90c1..d0b82a0 100644--- a/build-rootfs/files/etc/init.d/podroid-ready+++ b/build-rootfs/files/etc/init.d/podroid-ready@@ -7,7 +7,19 @@ depend() {}start() {- # By the time we run, dropbear has started (we depend on it).+ # By the time we run, every other service has started (depend: after *).+ # OOM-protect Podroid's infrastructure processes so a hungry user app+ # (Firefox, Chromium, big npm builds, podman pulls) gets reaped first.+ # -1000 makes a process completely immune to OOM. Match by argv[0]+ # basename instead of pidfile to catch all variants (multiple Xvnc+ # screens, forked dropbear instances per SSH session, the agent's+ # listener children).+ for _name in dropbear Xvnc pulseaudio podroid-vsock-agent dnsmasq; do+ for _pid in $(pgrep -x "$_name" 2>/dev/null); do+ echo -1000 > "/proc/$_pid/oom_score_adj" 2>/dev/null+ done+ done+# Emit the boot stages PodroidQemu.detectBootStage() expects.echo "Starting SSH..." > /dev/consoleecho "Almost ready..." > /dev/consolediff --git a/build-rootfs/files/etc/init.d/podroid-vsock b/build-rootfs/files/etc/init.d/podroid-vsockindex 102cfae..90b1459 100644--- a/build-rootfs/files/etc/init.d/podroid-vsock+++ b/build-rootfs/files/etc/init.d/podroid-vsock@@ -1,21 +1,37 @@#!/sbin/openrc-rundescription="Podroid vsock control + port forwarding agent (AVF only)"-command="/usr/local/bin/podroid-vsock-agent"-command_background="yes"pidfile="/run/podroid-vsock-agent.pid"-output_log="/var/log/podroid-vsock-agent.log"-error_log="/var/log/podroid-vsock-agent.log"depend() {need podroid-bootstrapbefore podroid-ready}-start_pre() {- # AVF-only: the QEMU backend never bound an AF_VSOCK socket — skip on QEMU.- if ! grep -q 'podroid\.tty=ttyS0' /proc/cmdline 2>/dev/null; then- ewarn "Not an AVF boot — skipping podroid-vsock"- return 1+start() {+ # AVF-only: QEMU's kernel has no AF_VSOCK, so the agent would just fail to+ # bind. Skip cleanly via mark_service_inactive — that's OpenRC's idiom for+ # "this service intentionally didn't start" and produces a one-line+ # "skipping" message instead of "* ERROR: <svc> failed to start" (which+ # is what `start_pre` returning non-zero would yield).+ if ! grep -q 'podroid\.backend=avf' /proc/cmdline 2>/dev/null; then+ einfo "Not an AVF boot — skipping podroid-vsock"+ mark_service_inactive+ return 0+ fi+ ebegin "Starting podroid-vsock-agent"+ start-stop-daemon --start --background \+ --make-pidfile --pidfile "$pidfile" \+ --stdout /var/log/podroid-vsock-agent.log \+ --stderr /var/log/podroid-vsock-agent.log \+ --exec /usr/local/bin/podroid-vsock-agent+ eend $?+}++stop() {+ if [ -f "$pidfile" ]; then+ ebegin "Stopping podroid-vsock-agent"+ start-stop-daemon --stop --pidfile "$pidfile"+ rm -f "$pidfile"+ eend $?fi- return 0}diff --git a/build-rootfs/files/etc/profile.d/podroid-x11.sh b/build-rootfs/files/etc/profile.d/podroid-x11.shindex a189846..52cf68d 100644--- a/build-rootfs/files/etc/profile.d/podroid-x11.sh+++ b/build-rootfs/files/etc/profile.d/podroid-x11.sh@@ -2,4 +2,13 @@# Apps launched from the user's shell inherit a working DISPLAY and# PULSE_SERVER without any setup, so `xeyes` / `firefox` etc. just work.export DISPLAY=:0-export PULSE_SERVER=tcp:127.0.0.1:4713++# PulseAudio: point clients (Firefox, mpv, etc.) at the native control+# socket exposed by module-native-protocol-unix in podroid-x11. The TCP+# 4713 port is the *capture* stream Android pulls — it's+# module-simple-protocol-tcp, not the native protocol, so Firefox can't+# talk to it. Without this, audio clients fail to find any sink and+# either play through a null device or fall back to noisy alsa dummies+# (the source of the clicking the user heard).+export XDG_RUNTIME_DIR=/run/podroid-pulse+export PULSE_SERVER=unix:/run/podroid-pulse/nativediff --git a/build-rootfs/vsock-agent/podroid-vsock-agent.c b/build-rootfs/vsock-agent/podroid-vsock-agent.cindex d2471fe..65f4cf9 100644--- a/build-rootfs/vsock-agent/podroid-vsock-agent.c+++ b/build-rootfs/vsock-agent/podroid-vsock-agent.c@@ -56,14 +56,29 @@/* ── Logging ─────────────────────────────────────────────────────────────── */+/*+ * Single-syscall log. fprintf+vfprintf+fprintf+fflush issues 3–4 write()s+ * which under fork() interleave at the byte level across child processes+ * (we saw "podroid-vsock-agent [error] podroid-vsock-agent [error] ctl+ * socket() failed: ...vsock socket() failed: ..." mixed in /var/log).+ * write(2, buf, n) is atomic for n < PIPE_BUF (4096) on Linux for regular+ * files and pipes — formatting the whole line into a stack buffer then+ * issuing one write() guarantees ordering even with many forked listeners.+ */static void logmsg(const char *level, const char *fmt, ...) {- fprintf(stderr, "%s [%s] ", LOG_TAG, level);+ char buf[1024];+ int n = snprintf(buf, sizeof(buf), "%s [%s] ", LOG_TAG, level);+ if (n < 0 || n >= (int)sizeof(buf) - 2) return;va_list ap;va_start(ap, fmt);- vfprintf(stderr, fmt, ap);+ int m = vsnprintf(buf + n, sizeof(buf) - n - 2, fmt, ap);va_end(ap);- fprintf(stderr, "\n");- fflush(stderr);+ if (m < 0) return;+ int total = n + m;+ if (total > (int)sizeof(buf) - 2) total = sizeof(buf) - 2;+ buf[total] = '\n';+ buf[total + 1] = '\0';+ (void)write(2, buf, (size_t)(total + 1));}#define LOG_I(...) logmsg("info", __VA_ARGS__)@@ -243,11 +258,15 @@ static void remove_config_line(int vport) {/* ── Control command handlers ───────────────────────────────────────────── */static void handle_resize(int rows, int cols) {- int fd = open("/dev/ttyS0", O_RDONLY | O_NOCTTY);+ /* /dev/hvc0 since the perf fix — virtio-console runs at line-rate,+ * unlike the old PL011 ttyS0 path that throttled TUI redraws to+ * ~14 KB/s. The getty also moved to hvc0 (per podroid-getty + the+ * `podroid.tty=hvc0` cmdline marker AVF now passes). */+ int fd = open("/dev/hvc0", O_RDONLY | O_NOCTTY);if (fd >= 0) {struct winsize ws = { .ws_row = (unsigned short)rows, .ws_col = (unsigned short)cols };if (ioctl(fd, TIOCSWINSZ, &ws) < 0) {- LOG_W("TIOCSWINSZ /dev/ttyS0 failed: %s", strerror(errno));+ LOG_W("TIOCSWINSZ /dev/hvc0 failed: %s", strerror(errno));}close(fd);}