【问题标题】:How to determine the cgroup of a device and give it to a lxc container如何确定设备的 cgroup 并将其提供给 lxc 容器
【发布时间】:2019-12-02 16:02:39
【问题描述】:

我是 lxc 和 cgroups 的新手。我正在尝试隔离一个应用程序,并使用 LXC 构建它的容器。

到目前为止,我可以为它提供一些资源,例如 /dev/tty0/dev/fb0。没关系,但是我很难找到 /proc/*/ 对应的号码是如何找到的:

lxc.cgroup.devices.allow = c 4:0 rwm
lxc.mount.entry = /dev/tty0 dev/tty0 none bind,optional,create=file

lxc.cgroup.devices.allow = c 4:5 rwm
lxc.mount.entry = /dev/tty5 dev/tty5 none bind,optional,create=file

lxc.cgroup.devices.allow = c 29:0 rwm
lxc.mount.entry = /dev/fb0 dev/fb0 none bind,optional,create=file

例如,对于fb029 似乎来自/proc/290 来自fb0。我如何确定给定资源应关联的数量是多少?

为什么 tty 与 4 相关联,而帧缓冲区与 29 相关联?

cat /proc/devices 

给出了部分答案,但是/dev/input/* 呢? sdaX?还是/dev/mmcblk0X

知道属于给定资源的 cgroup 的方法是什么?非常欢迎任何文档或指南。

【问题讨论】:

    标签: linux device-driver lxc cgroups


    【解决方案1】:

    看起来这实际上比看起来更简单。

    如果您想共享 /dev/tty0,只需查找次要号码和主要号码:

    # ls -l /dev/tty5
    crw--w---- 1 root tty 4, 5 Jan  1 01:37 /dev/tty5
    

    如果你想共享 char 设备 /dev/tty5 那么你想允许:

    lxc.cgroup.devices.allow = c 4:5 rwm
    lxc.mount.entry = /dev/tty5 dev/tty5 none bind,optional,create=file
    

    c来自char,4是主号,5是次号

    如果你想分享 /dev/sda1 :

    # ls -l /dev/sda1
    brw-rw---- 1 root disk 8, 1 Jan  1 01:37 /dev/sda1
    

    然后添加:

    lxc.cgroup.devices.allow = b 8:1 rwm
    

    b 用于块设备,8 主设备号 1 次设备号。

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 2014-06-19
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 2017-06-02
      • 2013-08-31
      相关资源
      最近更新 更多