简介:
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
注:未经允许禁止转载
喵喵喵喵喵