banner
late autumn

lateautumn

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

Android運行Lxd

image.png
簡介:
LXD 是 Linux 容器 (LXC) 的開源容器管理擴展。LXD 既改進了現有的 LXC 功能,又提供了新的特性和功能來構建和管理 Linux 容器。


1. 編譯內核#

1.1. 調整內核配置#

使用此倉庫快捷添加配置

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"

然後再自行編譯
🥵🥵🥵

1.2. 內核補丁#

1. 修復可能存在的 panic 情況

--- orig/net/netfilter/xt_qtaguid.c     2020-05-12 12:13:14.000000000 +0300
+++ my/net/netfilter/xt_qtaguid.c       2019-09-15 23:56:45.000000000 +0300
@@ -737,7 +737,7 @@
{
        struct proc_iface_stat_fmt_info *p = m->private;
        struct iface_stat *iface_entry;
-       struct rtnl_link_stats64 dev_stats, *stats;
+       struct rtnl_link_stats64 *stats;
        struct rtnl_link_stats64 no_dev_stats = {0};  
@@ -745,13 +745,8 @@
        current->pid, current->tgid, from_kuid(&init_user_ns, current_fsuid()));
        iface_entry = list_entry(v, struct iface_stat, list);
+       stats = &no_dev_stats; 
-       if (iface_entry->active) {
-               stats = dev_get_stats(iface_entry->net_dev,
-                                     &dev_stats);
-       } else {
-               stats = &no_dev_stats;
-       }
        /*
         * If the meaning of the data changes, then update the fmtX
         * string.

2. 修復 cgroup 缺少 cpuset 前綴

--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3786,6 +3786,10 @@ static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
 		cfile->kn = kn;
 		spin_unlock_irq(&cgroup_file_kn_lock);
 	}
+	if (cft->ss && (cgrp->root->flags & CGRP_ROOT_NOPREFIX) && !(cft->flags & CFTYPE_NO_PREFIX)) {
+				snprintf(name, CGROUP_FILE_NAME_MAX, "%s.%s", cft->ss->name, cft->name);
+				kernfs_create_link(cgrp->kn, name, kn);
+	}
 
 	return 0;
 }

3. 禁用 ANDROID_PARANOID_NETWORK

scripts/config --file arch/arm64/configs/<defconfig> -
d ANDROID_PARANOID_NETWORK

1.3. 檢查內核配置#

生成完整內核配置後檢查

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

具體編譯內核
以下省略 n 字

2. 安裝 lxd 模塊#

下載此magisk 模塊安裝並重啟

2.1. 創建容器#

隨便找一個終端軟件執行

. /data/lxd/env.sh

然後初始化

$ lxd init
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]:
Would you like to create a new btrfs subvolume under /var/lib/lxd? (yes/no) [default=yes]:
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like the LXD server to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:

創建容器

lxc launch ubuntu:23.04 ubuntu
# lxc launch 版本:版本 容器名字

調整 lxc 容器密碼

lxc exec 容器名字 /bin/passwd
# 二進制文件位置可能不同

2.1. 配置網絡#

(無需配置,自動處理)
如果容器無法訪問網絡,請執行./network.sh

2.2. web 界面#

訪問 ip:8443 按要求操作即可

2.3. 端口映射#

lxc config device add qiuqiu ssh proxy listen=tcp::外部ip connect=tcp::容器ip

注:未經允許禁止轉載

喵喵喵喵喵

參考文章:#

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。