banner
late autumn

lateautumn

一个什么都不会的职中生
github
email
telegram
bilibili

Running Lxc natively on Android

image.png
Introduction:
LXC is an operating system-level virtualization technology that provides a user-space interface for Linux kernel container functionality. It packages the application software system into a software container, which includes the code of the application software itself, as well as the required operating system kernel and libraries.


1. Compile the Kernel#

1.1. Adjust Kernel Configuration#

Use this repository to quickly add configurations

git fetch https://github.com/lateautumn233/android_kernel_docker main
git merge -s ours --no-commit --allow-unrelated-histories --squash FETCH_HEAD
git read-tree --prefix=docker -u FETCH_HEAD
echo "source \"docker/Kconfig\"" >> arch/arm64/Kconfig
git commit -a -m "Imported docker/ from https://github.com/lateautumn233/android_kernel_docker"

Then compile it yourself
🥵🥵🥵

1.2. Kernel Patch#

  1. Fix possible panic situations
  1. Fix missing cpuset prefix in cgroup
  1. Disable ANDROID_PARANOID_NETWORK
scripts/config --file arch/arm64/configs/<defconfig> -
d ANDROID_PARANOID_NETWORK

1.3. Check Kernel Configuration#

Check after generating the complete kernel configuration

wget https://raw.githubusercontent.com/lxc/lxc/main/src/lxc/cmd/lxc-checkconfig.in -O lxc-checkconfig
chmod a+x lxc-checkconfig
CONFIG=out/.config lxc-checkconfig

Specific kernel compilation
The following is omitted

2. Install Lxc Module#

Download and install this Magisk module and restart

2.1. Start Lxc Container#

Execute in any terminal software

. /data/lxc/env.sh

Create a container

lxc-create -t download -n my-container -- --server mirrors.tuna.tsinghua.edu.cn/lxc-images
# Fill in the distribution, version number, and architecture in order
# Then start
lxc-start -n my-container -d -F

Adjust the password for the lxc container

chroot path /bin/su -
lxc-attach -n my-container passwd

2.1. Configure Network#

(Optional, default is veth and can be left unchanged)

2.1.1 Use Host Mode#

sed -i 's/lxc\.net\.0\.type = veth/lxc.net.0.type = none/g' /data/lxc/etc/lxc/default.conf

Meow meow meow meow meow

Reference Articles:#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.