目录:

一、实战平台 

二、lxc源码下载

三、lxc交叉编译

四、lxc基本配置

五、lxc运行环境变量配置

六、lxc所在宿主机rootfs制作

七、lxc容器创建

八、lxc运行启动

九、lxc运行情况

十、lxc中运行程序

其他:注意事项说明

一、实战平台

通用Linux平台

二、lxc源码下载

可以从以下网站去下载

2.1git clone https://github.com/lxc/lxc.git

2.2https://gitee.com/mirrors/lxc.git

三、交叉编译

3.1 ./autogen.sh 
+ test -d autom4te.cache
+ libtoolize
+ aclocal -I config
+ autoheader
+ autoconf
+ automake --add-missing --copy

3.2 ./configure --prefix=/home/rd/lxc_src1/lxc/test --host=aarch64-poky-linux --target=aarch64-poky-linux --build=x86_64-linux

3.3 $make 
3.4 $sudo make install

3.5 $make maintainer-clean(clean方法)

四、LXC所需linux标准内核配置

CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_NS=y
CONFIG_CGROUP_SCHED=y
CONFIG_GROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CGROUPS=y
CONFIG_PROC_PID_CPUSET=y
CONFIG_UNIX_DIAG
CONFIG_INET_DIAG=y
CONFIG_EPOLL=y
CONFIG_EVENTFD=y
CONFIG_FHANDLE
CONFIG_UTS_NS
CONFIG_IPC_NS
CONFIG_USER_NS
CONFIG_PID_NS
CONFIG_NET_NS
CONFIG_VETH=m
CONFIG_MACVLAN=m
CONFIG_VLAN_8021Q=y
CONFIG_VLAN_8021Q_GVRP=y
CONFIG_VLAN_8021Q_MVRP=y

CONFIG_RESOURCE_COUNTERS
CONFIG_CGROUP_MEM_RES_CTLR
CONFIG_CGROUP_MEM_RES_CTLR_SWAP

MM_OWNER
SECURITY_FILE_CAPABILITIES
DEVPTS_MULTIPLE_INSTANCES

CONFIG_SYSVIPC=y
CONFIG_SYSVIPC_SYSCTL=y
CONFIG_SYSVIPC_COMPAT=y
CONFIG_POSIX_MQUEUE=y
CONFIG_POSIX_MQUEUE_SYSCTL=y
CONFIG_CGROUP_PIDS=y
CONFIG_MEMCG_KMEM=y

CGROUP_HUGETLB

CONFIG_CGROUP_PERF=y
CONFIG_CGROUP_WRITEBACK=y
CONFIG_NETFILTER_XT_MATCH_CGROUP=y

CONFIG_NETFILTER_XT_MATCH_DEVGROUP
CONFIG_NET_CLS_CGROUP
CONFIG_CGROUP_NET_PRIO
CONFIG_CGROUP_NET_CLASSID

CONFIG_CGROUPS=y
CONFIG_PROC_CHILDREN=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_IPC_NS=y
CONFIG_USER_NS=y
CONFIG_PID_NS=y
CONFIG_NET_NS=y
CONFIG_CHECKPOINT_RESTORE=y
117:CONFIG_CGROUPS=y
123:CONFIG_BLK_CGROUP=y
124:# CONFIG_DEBUG_BLK_CGROUP is not set
125:CONFIG_CGROUP_WRITEBACK=y
126:CONFIG_CGROUP_SCHED=y
131:CONFIG_CGROUP_PIDS=y
132:# CONFIG_CGROUP_RDMA is not set
133:CONFIG_CGROUP_FREEZER=y
136:CONFIG_CGROUP_DEVICE=y
137:CONFIG_CGROUP_CPUACCT=y
138:CONFIG_CGROUP_PERF=y
139:CONFIG_CGROUP_BPF=y
140:# CONFIG_CGROUP_DEBUG is not set
141:CONFIG_SOCK_CGROUP_DATA=y
689:# CONFIG_BLK_CGROUP_IOLATENCY is not set
1044:CONFIG_NETFILTER_XT_MATCH_CGROUP=y
1281:# CONFIG_NET_CLS_CGROUP is not set
1329:# CONFIG_CGROUP_NET_PRIO is not set
1330:CONFIG_CGROUP_NET_CLASSID=y

高通侧建议参考:

CONFIG_BUG_ON_DATA_CORRUPTION=y
CONFIG_DEBUG_CREDENTIALS=y
CONFIG_QCOM_MEMORY_DUMP_V2=y
CONFIG_LKDTM=m
+# LXC support
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CPUSETS=y
+CONFIG_PROC_PID_CPUSET=y
+CONFIG_MEMCG=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_RT_GROUP_SCHED=y
+CONFIG_CHECKPOINT_RESTORE=y
+CONFIG_NAMESPACES=y
+CONFIG_UTS_NS=y
+CONFIG_IPC_NS=y
+CONFIG_USER_NS=y
+CONFIG_PID_NS=y
+CONFIG_NET_NS=y
+CONFIG_NET_CLS_CGROUP=m
+CONFIG_BLK_CGROUP=y
+CONFIG_CGROUP_NET_PRIO=y
+# Virtual drivers
+CONFIG_HVC_DRIVER=y
+
+# Base support for live boot
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_VFAT_FS=y
+CONFIG_RD_GZIP=y

+# Support for virtual ethernet and LXC
+CONFIG_VETH=y
+CONFIG_MACVLAN=y
+CONFIG_VXLAN=m

四、lxc基本配置

lxc.net.0.type = none
lxc.autodev = 1
lxc.log.level = 1
lxc.log.file = /var/log/lxc/lxc.log
lxc.console.path = none
lxc.rootfs.path = dir:/lxc/rootfs
lxc.mount.fstab = /lxc/rootfs/etc/fstab
lxc.rootfs.mount = /lxc/rootfs

五、lxc运行环境变量配置

export LD_LIBRARY_PATH=/log/lxc/test/lib:$LD_LIBRARY_PATH
export PATH=/log/lxc/test/bin:$PATH

六、lxc所在宿主机rootfs制作

mkdir /lxc/rootfs

mkdir bin dev etc lib lib64 proc sbin sys usr var

vi /lxc/rootfs/fstab

/bin /lxc/rootfs/bin none ro,bind 0 0
/sbin /lxc/rootfs/sbin none ro,bind 0 0
/lib /lxc/rootfs/lib none ro,bind 0 0
/lib64 /lxc/rootfs/lib64 none ro,bind 0 0
/etc /lxc/rootfs/etc none ro,bind 0 0
/usr /lxc/rootfs/usr none ro,bind 0 0
/dev /lxc/rootfs/dev none rw,bind 0 0
/dev/pts /lxc/rootfs/dev/pts none rw,bind 0 0
/proc /lxc/rootfs/proc proc defaults 0 0
/sys /lxc/rootfs/sys sysfs defaults 0 0
 

七、lxc容器创建

lxc-create  -n mylxc  -f ./lxc.conf  -t none

八、lxc运行启动

lxc-start -n mylxc

九、lxc运行情况

lxc-info  mylxc
Name:           mylxc
State:          RUNNING
PID:            24516
IP:             169.254.125.133
IP:             169.254.23.44
CPU use:        157.17 seconds
Memory use:     44.27 MiB
KMem use:       15.21 MiB

十、lxc中运行程序

lxc-attach -n mylxc /data/lxc_test
lxc-attach: mylxc: confile.c: set_config_unsupported_key: 153 Invalid argument - Unsupported config key "lxc.seccomp"
lxc_test success

#include <stdio.h>
int main()
{
    printf("lxc_test success\n");

}

其他注意说明:

1、lxc编译环境安装包

1.1 host编译环境:

Linux ubuntu 4.15.0-142-generic #146~16.04.1-Ubuntu SMP Tue Apr 13 09:27:15 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux


1.2 host编译环境环境安装包

apt-get install libtool

apt-get install m4

apt-get install automake

1.3 lxc内核配置检测

#lxc-checkconfig -v
LXC version 4.0.12
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
newuidmap is not installed
newgidmap is not installed
Network namespace: enabled

--- Control groups ---
Cgroups: enabled
Cgroup namespace: enabled

Cgroup v1 mount points:
/sys/fs/cgroup/systemd
/sys/fs/cgroup/freezer
/sys/fs/cgroup/cpu,cpuacct
/sys/fs/cgroup/perf_event
/sys/fs/cgroup/cpuset
/sys/fs/cgroup/blkio
/sys/fs/cgroup/memory
/sys/fs/cgroup/schedtune
/sys/fs/cgroup/pids
/sys/fs/cgroup/devices
/sys/fs/cgroup/net_cls

Cgroup v2 mount points:
/sys/fs/cgroup/unified

Cgroup v1 clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled, not loaded
Macvlan: enabled, not loaded
Vlan: enabled, not loaded
Bridges: enabled, not loaded
Advanced netfilter: enabled, not loaded
CONFIG_NF_NAT_IPV4: enabled, not loaded
CONFIG_NF_NAT_IPV6: enabled, not loaded
CONFIG_IP_NF_TARGET_MASQUERADE: enabled, not loaded
CONFIG_IP6_NF_TARGET_MASQUERADE: enabled, not loaded
CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled, not loaded
CONFIG_NETFILTER_XT_MATCH_COMMENT: enabled, not loaded
FUSE (for use with lxcfs): enabled, not loaded

--- Checkpoint/Restore ---
checkpoint restore: enabled
CONFIG_FHANDLE: enabled
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
CONFIG_UNIX_DIAG: enabled
CONFIG_INET_DIAG: enabled
CONFIG_PACKET_DIAG: enabled
CONFIG_NETLINK_DIAG: enabled
File capabilities:

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /log/lxc/test/bin/lxc-checkconfig

1.4 lxc 容器rootfs目录

STATE  custom  dev  home  lib64  misc  proc  sbin  sys     tmp  var
bin    data    etc  lib   log    mnt   run   srv   system  usr

./etc/fstab
./var/log/syslog.log
./var/log/tcpdump.cap0
./var/log/lastlog
./var/log/wtmp
./var/log/btmp
./var/.updated
./sbin/init

1.5 启动lxc,执行bash命令

lxc-execute -n lxc1 -f config bash
 

1.6 lxc运行成功的log

lxc-start mylxc 20230419032202.135 INFO     lxccontainer - lxccontainer.c:do_lxcapi_start:997 - Set process title to [lxc monitor] /home/rd/##_lxc/lxc_src1/lxc/test/var/lib/lxc mylxc
lxc-start mylxc 20230419032202.137 INFO     start - start.c:lxc_check_inherited:328 - Closed inherited fd 11
lxc-start mylxc 20230419032202.138 DEBUG    lxccontainer - lxccontainer.c:wait_on_daemonized_start:858 - First child 24514 exited
lxc-start mylxc 20230419032202.139 INFO     lsm - lsm/lsm.c:lsm_init_static:38 - Initialized LSM security driver nop
lxc-start mylxc 20230419032202.142 INFO     start - start.c:lxc_init:884 - Container "mylxc" is initialized
lxc-start mylxc 20230419032202.149 INFO     cgfsng - cgroups/cgfsng.c:cgfsng_monitor_create:1029 - The monitor process uses "lxc.monitor.mylxc" as cgroup
lxc-start mylxc 20230419032202.156 DEBUG    storage - storage/storage.c:get_storage_by_name:209 - Detected rootfs type "dir"
lxc-start mylxc 20230419032202.164 INFO     cgfsng - cgroups/cgfsng.c:cgfsng_payload_create:1138 - The container process uses "lxc.payload.mylxc" as inner and "lxc.payload.mylxc" as limit cgroup
lxc-start mylxc 20230419032202.170 ERROR    utils - utils.c:lxc_can_use_pidfd:1792 - Kernel does not support pidfds
lxc-start mylxc 20230419032202.170 INFO     start - start.c:lxc_spawn:1765 - Cloned CLONE_NEWNS
lxc-start mylxc 20230419032202.170 INFO     start - start.c:lxc_spawn:1765 - Cloned CLONE_NEWPID
lxc-start mylxc 20230419032202.170 INFO     start - start.c:lxc_spawn:1765 - Cloned CLONE_NEWUTS
lxc-start mylxc 20230419032202.170 INFO     start - start.c:lxc_spawn:1765 - Cloned CLONE_NEWIPC
lxc-start mylxc 20230419032202.171 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved mnt namespace via fd 40 and stashed path as mnt:/proc/24515/fd/40
lxc-start mylxc 20230419032202.171 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved pid namespace via fd 41 and stashed path as pid:/proc/24515/fd/41
lxc-start mylxc 20230419032202.171 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved uts namespace via fd 42 and stashed path as uts:/proc/24515/fd/42
lxc-start mylxc 20230419032202.171 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved ipc namespace via fd 43 and stashed path as ipc:/proc/24515/fd/43
lxc-start mylxc 20230419032202.177 INFO     start - start.c:do_start:1207 - Unshared CLONE_NEWCGROUP
lxc-start mylxc 20230419032202.177 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved net namespace via fd 7 and stashed path as net:/proc/24515/fd/7
lxc-start mylxc 20230419032202.177 WARN     start - start.c:lxc_spawn:1835 - File exists - Failed to allocate new network namespace id
lxc-start mylxc 20230419032202.180 DEBUG    conf - conf.c:lxc_mount_rootfs:1438 - Mounted rootfs "/lxc/rootfs" onto "/lxc/rootfs" with options "(null)"
lxc-start mylxc 20230419032202.180 INFO     conf - conf.c:mount_autodev:1219 - Preparing "/dev"
lxc-start mylxc 20230419032202.180 DEBUG    conf - conf.c:mount_autodev:1251 - Using mount options: size=500000,mode=755
lxc-start mylxc 20230419032202.181 INFO     conf - conf.c:mount_autodev:1280 - Prepared "/dev"
lxc-start mylxc 20230419032202.182 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/bin" on "/lxc/rootfs//bin" to respect bind or remount options
lxc-start mylxc 20230419032202.182 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/bin" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.182 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/bin" on "/lxc/rootfs//bin" with filesystem type "none"
lxc-start mylxc 20230419032202.183 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/sbin" on "/lxc/rootfs//sbin" to respect bind or remount options
lxc-start mylxc 20230419032202.183 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/sbin" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.183 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/sbin" on "/lxc/rootfs//sbin" with filesystem type "none"
lxc-start mylxc 20230419032202.183 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/lib" on "/lxc/rootfs//lib" to respect bind or remount options
lxc-start mylxc 20230419032202.184 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/lib" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.184 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/lib" on "/lxc/rootfs//lib" with filesystem type "none"
lxc-start mylxc 20230419032202.184 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/lib64" on "/lxc/rootfs//lib64" to respect bind or remount options
lxc-start mylxc 20230419032202.184 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/lib64" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.184 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/lib64" on "/lxc/rootfs//lib64" with filesystem type "none"
lxc-start mylxc 20230419032202.185 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/etc" on "/lxc/rootfs//etc" to respect bind or remount options
lxc-start mylxc 20230419032202.185 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/etc" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.185 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/etc" on "/lxc/rootfs//etc" with filesystem type "none"
lxc-start mylxc 20230419032202.185 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/usr" on "/lxc/rootfs//usr" to respect bind or remount options
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/usr" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/usr" on "/lxc/rootfs//usr" with filesystem type "none"
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/dev" on "/lxc/rootfs//dev" to respect bind or remount options
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/dev" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2444 - Mountflags already were 4096, skipping remount
lxc-start mylxc 20230419032202.186 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/dev" on "/lxc/rootfs//dev" with filesystem type "none"
lxc-start mylxc 20230419032202.187 DEBUG    conf - conf.c:mount_entry:2417 - Remounting "/dev/pts" on "/lxc/rootfs//dev/pts" to respect bind or remount options
lxc-start mylxc 20230419032202.187 DEBUG    conf - conf.c:mount_entry:2436 - Flags for "/dev/pts" were 4096, required extra flags are 0
lxc-start mylxc 20230419032202.187 DEBUG    conf - conf.c:mount_entry:2444 - Mountflags already were 4096, skipping remount
lxc-start mylxc 20230419032202.187 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/dev/pts" on "/lxc/rootfs//dev/pts" with filesystem type "none"
lxc-start mylxc 20230419032202.187 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/proc" on "/lxc/rootfs//proc" with filesystem type "proc"
lxc-start mylxc 20230419032202.188 DEBUG    conf - conf.c:mount_entry:2480 - Mounted "/sys" on "/lxc/rootfs//sys" with filesystem type "sysfs"
lxc-start mylxc 20230419032202.189 INFO     conf - conf.c:lxc_fill_autodev:1317 - Populating "/dev"
lxc-start mylxc 20230419032202.189 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "full"
lxc-start mylxc 20230419032202.189 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "null"
lxc-start mylxc 20230419032202.189 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "random"
lxc-start mylxc 20230419032202.189 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "tty"
lxc-start mylxc 20230419032202.190 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "urandom"
lxc-start mylxc 20230419032202.190 DEBUG    conf - conf.c:lxc_fill_autodev:1326 - Created device node "zero"
lxc-start mylxc 20230419032202.190 INFO     conf - conf.c:lxc_fill_autodev:1405 - Populated "/dev"
lxc-start mylxc 20230419032202.190 INFO     conf - conf.c:lxc_transient_proc:3775 - Caller's PID is 1; /proc/self points to 1
lxc-start mylxc 20230419032202.190 DEBUG    conf - conf.c:lxc_setup_devpts_child:1695 - No new devpts instance will be mounted since no pts devices are required
lxc-start mylxc 20230419032202.264 INFO     conf - conf.c:lxc_setup_ttys:1072 - Finished setting up 0 /dev/tty<N> device(s)
lxc-start mylxc 20230419032202.326 DEBUG    conf - conf.c:setup_personality:1911 - Retaining original personality
lxc-start mylxc 20230419032202.326 DEBUG    conf - conf.c:capabilities_deny:3203 - Capabilities have been setup
lxc-start mylxc 20230419032202.326 NOTICE   conf - conf.c:lxc_setup:4469 - The container "mylxc" is set up
lxc-start mylxc 20230419032202.328 DEBUG    conf - conf.c:lxc_send_devpts_to_parent:1893 - No devpts file descriptor will be sent since no pts devices are requested
lxc-start mylxc 20230419032202.328 DEBUG    start - start.c:lxc_try_preserve_namespace:140 - Preserved cgroup namespace via fd 9 and stashed path as cgroup:/proc/24515/fd/9
lxc-start mylxc 20230419032202.328 INFO     terminal - terminal.c:lxc_terminal_setup:1109 - No terminal requested
lxc-start mylxc 20230419032202.329 NOTICE   utils - utils.c:lxc_drop_groups:1365 - Dropped supplimentary groups
lxc-start mylxc 20230419032202.329 NOTICE   start - start.c:start:2161 - Exec'ing "/sbin/init"
lxc-start mylxc 20230419032202.335 NOTICE   start - start.c:post_start:2172 - Started "/sbin/init" with pid "24516"
lxc mylxc 20230419032405.364 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_init_pid" received response
lxc mylxc 20230419032405.367 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.368 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.368 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.369 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.369 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.369 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.370 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_init_pid" received response
lxc mylxc 20230419032405.373 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_init_pid" received response
lxc mylxc 20230419032405.378 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.378 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.379 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:137 - Received exact number of file descriptors 1 == 1 for command "get_limit_cgroup_fd"
lxc mylxc 20230419032405.380 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.380 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.381 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:137 - Received exact number of file descriptors 1 == 1 for command "get_limit_cgroup_fd"
lxc mylxc 20230419032405.383 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.383 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.383 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:137 - Received exact number of file descriptors 1 == 1 for command "get_limit_cgroup_fd"
lxc mylxc 20230419032405.384 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_state" received response
lxc mylxc 20230419032405.385 DEBUG    commands - commands.c:lxc_cmd_get_state:1064 - Container "mylxc" is in "RUNNING" state
lxc mylxc 20230419032405.385 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:137 - Received exact number of file descriptors 1 == 1 for command "get_limit_cgroup_fd"
lxc mylxc 20230419032405.386 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_config_item" received response
lxc mylxc 20230419032405.387 DEBUG    commands - commands.c:lxc_cmd_rsp_recv_fds:147 - Command "get_config_item" received response
lxc-execute mylxc 20230419040513.102 ERROR    commands - commands.c:lxc_server_init:2069 - Container "mylxc" appears to be already running
lxc-execute mylxc 20230419040513.103 ERROR    commands - commands.c:lxc_server_init:2071 - Address already in use - Failed to create command socket /home/rd/##_lxc/lxc_src1/lxc/test/var/lib/lxc/mylxc/command
lxc-execute mylxc 20230419040513.103 ERROR    start - start.c:lxc_init_handler:751 - Failed to set up command socket

 常见问题:

Failed to create container test
如果/var/lib/lxc是只读的话,可以通过-P来指定可写的地方,如

lxc-create -t xxx -n test1 -P /writ_dir

lxc-create -t busybox -n test11 -f /log/lxc/test/share/lxc/templates/lxc-busybox :

lxc-create -t busybox -n test11 -f /log/lxc/test/share/lxc/templates/lxc-busybox 
lxc-create: test11: confile.c: add_cap_entry: 2267 Invalid argument - Invalid capability specified
lxc-create: test11: parse.c: lxc_file_for_each_line_mmap: 130 Failed to parse config file "/log/lxc/test/share/lxc/templates/lxc-busybox" at line "lxc.cap.drop = sys_module mac_admin mac_override sys_time"
lxc-create: test11: utils.c: get_template_path: 898 No such file or directory - bad template: busybox
lxc-create: test11: lxccontainer.c: __lxcapi_create: 1798 Template "busybox" not found
lxc-create: test11: tools/lxc_create.c: main: 317 Failed to create container test11

lxc-start -n name /bin/echo hello

  还可以用以下指令,在已经启动的container里执行进程。

lxc-attach -n name /bin/echo hello

以下指令是用来在未启动的container里执行进程的

lxc-execute -n name /bin/echo hello
Logo

openvela 操作系统专为 AIoT 领域量身定制,以轻量化、标准兼容、安全性和高度可扩展性为核心特点。openvela 以其卓越的技术优势,已成为众多物联网设备和 AI 硬件的技术首选,涵盖了智能手表、运动手环、智能音箱、耳机、智能家居设备以及机器人等多个领域。

更多推荐