A Magisk module that keeps Android 16's native Linux Terminal VM running persistently, preventing Android from killing it.
Android 16 introduced a native Linux Terminal that runs a full Debian virtual machine using the Android Virtualization Framework (AVF). By default, this VM has two major issues:
- Closes when you exit the app - The VM lifecycle is tied to the Terminal app
- Gets killed by Android - The low memory killer can terminate the VM process
This Magisk module solves both problems by keeping the Terminal app running in the background and protecting the VM from being killed.
- β Keeps Terminal VM running 24/7
- β
Protects
crosvmprocesses from OOM killer (score: -1000) - β Auto-starts on boot
- β Monitors and restarts if stopped
- β Includes control script for manual management
- β Minimal battery impact optimization
| Requirement | Details |
|---|---|
| Android Version | Android 16+ (or Android 15 with Terminal backport) |
| Root | Magisk 20.4+ or KernelSU |
| AVF Support | Device must support Android Virtualization Framework |
| Terminal Enabled | Enable in Developer Options β Linux development environment |
- Samsung devices with Knox may not support AVF properly
- Devices without
/dev/kvmsupport - Some custom ROMs that modify AVF
- Download the latest release or create the module:
# Clone or download these files
VM_Magisk_Module/
βββ module.prop
βββ service.sh
βββ uninstall.sh
βββ vm_control.sh
βββ system.prop- Package the module:
cd VM_Magisk_Module
zip -r terminal_vm_persist.zip .- Install via Magisk:
- Open Magisk Manager
- Go to Modules β Install from storage
- Select
terminal_vm_persist.zip - Reboot your device
# Push files to Magisk modules directory
adb push VM_Magisk_Module /data/adb/modules/
# Set proper permissions
adb shell
su
cd /data/adb/modules/VM_Magisk_Module
chmod 755 *.sh
rebootAfter installation and reboot, the module runs automatically. The Terminal VM will:
- Start on boot
- Stay running in background
- Restart automatically if stopped
- Be protected from memory management
Use the included control script for manual management:
# Check VM status
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh status
# Protect processes immediately
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh protect
# Start Terminal app
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh start
# View VM information
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh info
# Show VM logs
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh logs
# Force restart Terminal
su -c /data/adb/modules/VM_Magisk_Module/vm_control.sh force-restart# View service logs
logcat -s Terminal-Persist
# Check crosvm protection
ps -A | grep crosvm
cat /proc/$(pidof crosvm)/oom_score_adj
# Should output: -1000
# Check Terminal app status
ps -A | grep terminal
# List running VMs
/apex/com.android.virt/bin/vm listTerminal app: RUNNING (PID: 12345)
OOM score: -800
VMs running:
crosvm (PID: 12346)
OOM score: -1000
The module leverages the Android Virtualization Framework's architecture:
-
VM Lifecycle Management
- VirtualizationService manages VMs through
IVirtualMachinebinder objects - When all binder references are dropped, the VM shuts down
- Keeping the Terminal app alive maintains the binder reference
- VirtualizationService manages VMs through
-
OOM Protection
- Sets
oom_score_adjto-1000for crosvm processes - Sets
oom_score_adjto-800for Terminal app - Prevents Android's low memory killer from terminating them
- Sets
-
Continuous Monitoring
- Background service checks every 30 seconds
- Restarts Terminal app if stopped
- Re-applies OOM protection if needed
Terminal Package: com.android.virtualization.terminal
VM Command: /apex/com.android.virt/bin/vm
Data Directory: /data/data/com.android.virtualization.terminal/
VM Images: /sdcard/linux/images.tar.gz (optional custom)
Logs: /data/data/com.android.virtualization.terminal/files/
Check AVF support:
# Verify KVM device exists
ls -l /dev/kvm
# Check virtualization APEX
ls -l /apex/com.android.virtDisable battery optimization:
- Settings β Apps β Terminal β Battery β Unrestricted
Check for Knox restrictions (Samsung):
getprop ro.boot.warranty_bit
# 0 = Knox intact, 1 = Knox trippedThis is expected when running a full Linux VM continuously. To reduce:
- Limit VM resources in Terminal settings
- Reduce disk size to minimum needed
- Disable unused services inside the VM
- Only enable when needed - disable module when not in use
Some operations require additional access:
# Enable debuggable mode (if needed)
su -c "magisk resetprop ro.debuggable 1; stop; start"
# Check SELinux status
getenforce
# If "Enforcing" is causing issues, can temporarily set to Permissive (not recommended)# Check module installation
ls -l /data/adb/modules/VM_Magisk_Module/
# Verify file permissions
ls -l /data/adb/modules/VM_Magisk_Module/*.sh
# Check service logs
logcat -s Terminal-Persist
# Manually start service
su -c "/data/adb/modules/VM_Magisk_Module/service.sh &"- Battery Impact - Running a VM 24/7 consumes battery
- App Coupling - Must keep entire Terminal app running, not just VM
- System Permissions - MANAGE_VIRTUAL_MACHINE permission is restricted
- Device Support - Limited to AVF-compatible devices
- Memory Usage - VM consumes RAM continuously (typically 512MB-2GB)
If this module doesn't work for your needs:
Keep Terminal in foreground with persistent notification (no root required)
Use automation apps to restart Terminal periodically
Build your own ROM with a dedicated system service for the VM
Use vm command with custom scripts:
/apex/com.android.virt/bin/vm run /data/local/tmp/vm_config.json- Open Magisk Manager
- Go to Modules
- Remove "Android 16 Terminal VM Persistence"
- Reboot
su
/data/adb/modules/VM_Magisk_Module/uninstall.sh
rm -rf /data/adb/modules/VM_Magisk_Module
reboot- Android Virtualization Framework Documentation
- AVF Architecture Details
- VirtualizationService API
- Crosvm Documentation
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is provided as-is for educational purposes. Use at your own risk.
- Android Virtualization Framework by Google
- Magisk by topjohnwu
- NixOS-AVF project for research insights
Note: This module is for advanced users who understand the implications of running persistent VMs on Android. Always backup your data before installation.