cgroup--device测试

The devices subsystem allows or denies access to devices by tasks in a cgroup.

devices.allow

   specifies devices to which tasks in a cgroup have access. Each entry has four fields:type,major, minor, and access. The values used in the type, major, and minor fields correspondto device types and node numbers specified in Linux Allocated Devices,


type
       type can have one of the following three values:
            a — applies to all devices, both character devices and block devices
            b — specifies a block device
            c — specifies a character device


major, minor
      major and minor are device node numbers specified by Linux Allocated Devices. The major and minor numbers are separated by a colon. For example, 8 is the major
number that specifies SCSI disk drives, and the minor number 1 specifies the first partition on the first SCSI disk drive; therefore 8:1 fully specifies this partition,corresponding to a file system location of /dev/sda1.

 * can stand for all major or all minor device nodes, for example 9:* (all RAID devices) or * :* (all devices).

access
     access is a sequence of one or more of the following letters:
             r — allows tasks to read from the specified device
             w — allows tasks to write to the specified device 
             m — allows tasks to create device files that do not yet exist
For example, when access is specified as r, tasks can only read from the specified device, but when access is specified as rw, tasks can read from and write to the device.



devices.deny
specifies devices that tasks in a cgroup cannot access. T he syntax of entries is identical with devices.allow.


在/devices/cgroup  目录下创建目录  first,并设置禁止设备读:

root@ubuntu:/sys/fs/cgroup/devices# mkdir first

root@ubuntu:/sys/fs/cgroup/devices/first# echo "a 1:5 r" > devices.deny


在另外一个终端中设置:

root@ubuntu:~# cgexec -g devices:first dd if=/dev/zero of=zero bs=1M count=128 &
可见提示如下:
[1] 8973
root@ubuntu:~# dd: 正在打开"/dev/zero": 不允许的操作


<think>好的,用户现在的问题是如何卸载nvidia-container-toolkit并清理相关依赖。我需要结合之前的回答和用户提供的引用内容来给出准确的步骤。首先,用户提到参考了四个引用,其中引用1、2、3提到了卸载的不同部分,比如卸载工具包、驱动、旧版nvidia-docker等。 用户的上一次问题是关于强制安装指定版本的依赖,而这次是卸载,所以需要确保卸载步骤彻底,包括依赖和配置文件。根据引用1,卸载nvidia-container-toolkit需要用apt-get purge命令,这样会删除配置文件。同时,用户可能需要清理残留的依赖项,比如libnvidia-container等。 引用3提到nvidia-docker已经被废弃,所以如果用户之前安装过,可能需要先卸载nvidia-docker。此外,引用2提到GPU Operator卸载后驱动模块可能还在,需要重启或手动卸载模块。但用户的问题是关于nvidia-container-toolkit,所以可能需要处理相关模块。 接下来,我需要分步骤来写: 1. 卸载nvidia-container-toolkit和相关包:使用purge命令,包括toolkit、runtime、lib库等,确保所有组件都被移除。 2. 清理残留配置文件:比如docker的运行时配置,如/etc/docker/daemon.json中的nvidia配置。 3. 处理内核模块:如果驱动模块还在,可能需要卸载或者重启。 4. 验证卸载结果:检查dpkg列表和docker运行时,运行测试命令确认是否彻底移除。 5. 额外清理:比如旧版nvidia-docker的残留,第三方仓库的清理。 需要注意引用中的内容,比如引用4提到的nvidia-container-cli命令可以用来调试,可能在验证步骤中使用。同时要提醒用户谨慎操作,因为卸载可能会影响依赖其他软件的环境。 还需要考虑用户可能的后续问题,比如如何彻底删除驱动、如何处理依赖冲突等,可以在相关问题里列出。同时,确保步骤清晰,命令准确,避免误操作。</think>### 彻底卸载 nvidia-container-toolkit 的完整指南 --- #### 一、核心卸载流程(分步操作) ##### 1. 卸载主程序链(严格按依赖顺序) ```bash # Step1: 卸载运行时接口 sudo apt-get purge -y nvidia-container-runtime # Step2: 卸载核心工具包 sudo apt-get purge -y nvidia-container-toolkit # Step3: 清理底层库(按引用[1]扩展) sudo apt-get purge -y libnvidia-container-tools libnvidia-container1 ``` ##### 2. 深度清理残留配置 ```bash # 删除Docker运行时配置(引用[3]相关) sudo sed -i '/nvidia/d' /etc/docker/daemon.json 2>/dev/null sudo rm -f /etc/nvidia-container-runtime/config.toml # 清理cgroup规则(关键残留) sudo rm -f /etc/systemd/system/docker.service.d/nvidia-container-runtime.conf ``` --- #### 二、内核模块处理(按引用[2]优化) ##### 1. 立即卸载GPU驱动模块(无需重启) ```bash # 强制卸载模块(适用于未重启场景) sudo rmmod nvidia_uvm nvidia_modeset nvidia_drm nvidia 2>/dev/null # 检查残留 lsmod | grep nvidia ``` ##### 2. 持久化清理(防止自动加载) ```bash # 黑名单机制(针对未完全卸载驱动的情况) echo -e "blacklist nvidia\nblacklist nvidia_uvm\nblacklist nvidia_modeset" | sudo tee /etc/modprobe.d/blacklist-nvidia.conf sudo update-initramfs -u ``` --- #### 三、依赖关系验证与修复 ##### 1. 检查孤立依赖包 ```bash # 使用deborphan查找残留(关键步骤) sudo apt-get install deborphan -y deborphan --guess-all | grep -E 'nvidia|container' # 示例输出: # libnvidia-decode-510 # libnvidia-extra-510 ``` ##### 2. 批量清理命令 ```bash # 自动移除孤立包(慎用!确认列表后再执行) sudo apt-get autoremove --purge -y $(deborphan --guess-all | grep -E 'nvidia|container') ``` --- #### 四、验证卸载结果 ##### 1. 基础验证命令 ```bash # 检查软件包状态(应无nvidia-container相关输出) dpkg -l | grep -E 'nvidia-container|libnvidia-container' # 验证Docker运行时配置 docker info 2>/dev/null | grep -i runtime ``` ##### 2. 高级验证(按引用[4]方法扩展) ```bash # 检查设备挂载能力(预期报错) nvidia-container-cli list 2>&1 | grep -i 'not found' # 测试GPU容器(应显示错误) docker run --rm --gpus all ubuntu nvidia-smi 2>&1 | grep -i 'could not select device driver' ``` --- #### 五、特殊场景处理 ##### 1. 混合安装模式清理(如通过源码安装) ```bash # 手动删除二进制文件 sudo rm -f /usr/bin/nvidia-container-* /usr/local/bin/nvidia-container-* # 清理动态库缓存 sudo ldconfig ``` ##### 2. 处理第三方仓库残留 ```bash # 移除nvidia-docker仓库配置(按引用[3]) sudo rm -f /etc/apt/sources.list.d/nvidia-docker.list sudo apt-key del "$(apt-key list | grep 'NVIDIA Corporation' -B 1 | head -n 1 | cut -d' ' -f3)" sudo apt-get update ``` --- ### 关键注意事项 1. **依赖关系警告**:若系统安装过CUDA工具包,清理可能导致`cuda-runtime-*`等包被误删 2. **生产环境建议**:在关键节点操作前创建快照 `sudo apt-get install timeshift && timeshift --create` 3. **容器持久化影响**:已创建的GPU容器需手动重建(即使容器仍在运行也会失去GPU访问能力) --- ### 相关问题扩展 1. **如何彻底清除NVIDIA GPU驱动程序?** > 执行 `sudo apt-get purge 'nvidia-*'` 后手动删除 `/usr/lib/nvidia` 目录 > 注意:可能导致Xorg显示服务中断[^1] 2. **卸载后如何恢复默认Docker运行时?** > 需手动编辑 `/etc/docker/daemon.json` 移除`nvidia`运行时配置,并执行 `sudo systemctl restart docker` 3. **卸载过程中出现`E: Sub-process /usr/bin/dpkg returned an error code`怎么办?** > 尝试 `sudo dpkg --purge --force-all <包名>` 强制清除,再执行 `sudo apt-get install -f` --- [^1]: 彻底卸载NVIDIA组件可能导致图形界面崩溃,建议在SSH会话中操作 [^2]: `deborphan`可能误判依赖关系,操作前建议备份`/var/lib/dpkg/status` [^3]: 残留的GPU内核模块会导致`nvidia-smi`等命令仍可运行,需重启或手动`rmmod`
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值