后浪笔记一零二四

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# 将rootfs.tar.gz和runc拷贝到目标机器上
# 创建config.json文件,文件内容如下:
{
        "ociVersion": "1.0.2-dev",
        "process": {
                "terminal": false,
                "user": {
                        "uid": 0,
                        "gid": 0
                },
                "args": [
                        "tail",
                        "-f",
                        "/etc/hosts"
                ],
                "env": [
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                        "TERM=xterm"
                ],
                "cwd": "/",
                "capabilities": {
                        "bounding":[
                                "CAP_CHOWN",
                                "CAP_DAC_OVERRIDE",
                                "CAP_FSETID",
                                "CAP_FOWNER",
                                "CAP_MKNOD",
                                "CAP_NET_RAW",            //// 不加这个,会报:ping: socket: Operation not permitted
                                "CAP_SETGID",
                                "CAP_SETUID",
                                "CAP_SETFCAP",
                                "CAP_SETPCAP",
                                "CAP_NET_BIND_SERVICE",
                                "CAP_SYS_CHROOT",
                                "CAP_KILL",
                                "CAP_AUDIT_WRITE"
                        ],
                        "effective":[
                                "CAP_CHOWN",
                                "CAP_DAC_OVERRIDE",
                                "CAP_FSETID",
                                "CAP_FOWNER",
                                "CAP_MKNOD",
                                "CAP_NET_RAW",
                                "CAP_SETGID",
                                "CAP_SETUID",
                                "CAP_SETFCAP",
                                "CAP_SETPCAP",
                                "CAP_NET_BIND_SERVICE",
                                "CAP_SYS_CHROOT",
                                "CAP_KILL",
                                "CAP_AUDIT_WRITE"
                        ],
                        "permitted":[
                                "CAP_CHOWN",
                                "CAP_DAC_OVERRIDE",
                                "CAP_FSETID",
                                "CAP_FOWNER",
                                "CAP_MKNOD",
                                "CAP_NET_RAW",
                                "CAP_SETGID",
                                "CAP_SETUID",
                                "CAP_SETFCAP",
                                "CAP_SETPCAP",
                                "CAP_NET_BIND_SERVICE",
                                "CAP_SYS_CHROOT",
                                "CAP_KILL",
                                "CAP_AUDIT_WRITE"
                        ]
                },
                "rlimits": [
                        {
                                "type": "RLIMIT_NOFILE",
                                "hard": 1024,
                                "soft": 1024
                        }
                ],
                "noNewPrivileges": true
        },
        "root": {
                "path": "rootfs",
                "readonly": false
        },
        "hostname": "runc",
        "mounts": [
                {
                        "destination": "/proc",
                        "type": "proc",
                        "source": "proc"
                },
                {
                        "destination": "/dev",
                        "type": "tmpfs",
                        "source": "tmpfs",
                        "options": [
                                "nosuid",
                                "strictatime",
                                "mode=755",
                                "size=65536k"
                        ]
                },
                {
                        "destination": "/dev/pts",
                        "type": "devpts",
                        "source": "devpts",
                        "options": [
                                "nosuid",
                                "noexec",
                                "newinstance",
                                "ptmxmode=0666",
                                "mode=0620",
                                "gid=5"
                        ]
                },
                {
                        "destination": "/dev/shm",
                        "type": "tmpfs",
                        "source": "shm",
                        "options": [
                                "nosuid",
                                "noexec",
                                "nodev",
                                "mode=1777",
                                "size=65536k"
                        ]
                },
                {
                        "destination": "/dev/mqueue",
                        "type": "mqueue",
                        "source": "mqueue",
                        "options": [
                                "nosuid",
                                "noexec",
                                "nodev"
                        ]
                },
                {
                        "destination": "/sys",
                        "type": "sysfs",
                        "source": "sysfs",
                        "options": [
                                "nosuid",
                                "noexec",
                                "nodev",
                                "ro"
                        ]
                },
                {
                        "destination": "/etc/resolv.conf",
                        "options": [
                                "rbind",
                                "rprivate"
                        ],
                        "source": "/etc/resolv.conf",
                        "type": "bind"
                },
                {
                        "destination": "/etc/hostname",
                        "options": [
                                "rbind",
                                "rprivate"
                        ],
                        "source": "/etc/hostname",
                        "type": "bind"
                },
                {
                        "destination": "/etc/hosts",
                        "options": [
                                "rbind",
                                "rprivate"
                        ],
                        "source": "/etc/hosts",
                        "type": "bind"
                },
                {
                        "destination": "/sys/fs/cgroup",
                        "type": "cgroup",
                        "source": "cgroup",
                        "options": [
                                "nosuid",
                                "noexec",
                                "nodev",
                                "relatime",
                                "ro"
                        ]
                }
        ],
        "linux": {
                "resources": {
                        "devices": [
                                {
                                        "allow": false,
                                        "access": "rwm"
                                }
                        ]
                },
                "namespaces": [
                        {
                                "type": "pid"
                        },
                        {
                                "type": "ipc"
                        },
                        {
                                "type": "uts"
                        },
                        {
                                "type": "mount"
                        }
                ],
                "maskedPaths": [
                        "/proc/acpi",
                        "/proc/asound",
                        "/proc/kcore",
                        "/proc/keys",
                        "/proc/latency_stats",
                        "/proc/timer_list",
                        "/proc/timer_stats",
                        "/proc/sched_debug",
                        "/sys/firmware",
                        "/proc/scsi"
                ],
                "readonlyPaths": [
                        "/proc/bus",
                        "/proc/fs",
                        "/proc/irq",
                        "/proc/sys",
                        "/proc/sysrq-trigger"
                ]
        }
}
 
tar -xzf rootfs.tar.gz
./runc run -d --pid-file init.pid   supervisord
./runc exec -t supervisord bash
# yum clean, yum clean all (= yum clean packages; yum clean oldheaders)
# yum clean headers      清除header
# yum clean oldheaders   清除缓存目录(/var/cache/yum)下旧的 headers
# yum clean packages     清除下载的rpm包
yum clean all; yum clean headers

runc在arm64 麒麟系统中,有个bug:

unable to start container process: error adding pid 2047088 to cgroups: failed to write 2047088: open /sys/fs/cgroup/blkio/system.slice/supervisord/cgroup.procs: no such file or directory

需要改runc的代码,并重新编译,改动分支release-1.1,改动如下:

diff --git a/Makefile b/Makefile
index e3af9bc..0c0a2fd 100644
--- a/Makefile
+++ b/Makefile
@@ -68,15 +68,16 @@ recvtty sd-helper seccompagent:
 static:
        $(GO_BUILD_STATIC) -o runc .
 
-releaseall: RELEASE_ARGS := "-a arm64 -a armel -a armhf -a ppc64le -a riscv64 -a s390x"
+releaseall: RELEASE_ARGS := "-a arm64"
 releaseall: release
 
-release: runcimage
+release:
        $(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
                --rm -v $(CURDIR):/go/src/$(PROJECT) \
                -e RELEASE_ARGS=$(RELEASE_ARGS) \
+               --pull never \
                $(RUNC_IMAGE) make localrelease
-       script/release_sign.sh -S $(GPG_KEYID) -r release/$(VERSION) -v $(VERSION)
+       #script/release_sign.sh -S $(GPG_KEYID) -r release/$(VERSION) -v $(VERSION)
 
 localrelease: verify-changelog
        script/release_build.sh -r release/$(VERSION) -v $(VERSION) $(RELEASE_ARGS)
diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go
index fc4ae44..e84295d 100644
--- a/libcontainer/cgroups/utils.go
+++ b/libcontainer/cgroups/utils.go
@@ -393,6 +393,10 @@ func WriteCgroupProc(dir string, pid int) error {
                return nil
        }
 
+       if err := os.MkdirAll(dir, 0o755); err != nil {
+               return err
+       }
+
        file, err := OpenFile(dir, CgroupProcesses, os.O_WRONLY)
        if err != nil {
                return fmt.Errorf("failed to write %v: %w", pid, err)

编译命令:

# runc_dev-main.tar 使用 make runcimage 命令生成,生成时间较长,一般10h
$ docker load -i runc_dev-main.tar
$ docker tag runc_dev:main runc_dev:release-1-1
$ make releaseall

本文发表于 0001-01-01,最后修改于 0001-01-01。

本站永久域名「 jiavvc.top 」,也可搜索「 后浪笔记一零二四 」找到我。


上一篇 « 下一篇 »

赞赏支持

请我吃鸡腿 =^_^=

i ysf

云闪付

i wechat

微信

推荐阅读

Big Image