CIFS VFS: cifs_mount failed w/return code = -22错误

本文解决在Ubuntu虚拟机中使用CIFS协议挂载文件系统时遇到的错误问题,通过安装smbfs文件系统包来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在ununtu虚机里面挂在文件,总是提示下面的错误:

root@ljk:/home# mount -t cifs //192.168.25.12/sources /home/ljk -o username=name,password=123456

mount: wrong fs type, bad option, bad superblock on //172.18.1.87/sources,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so


查看/var/log/syslog:

Oct  8 16:41:28 host-40-40-40-13 kernel: [ 8848.377815] CIFS VFS: Connecting to DFS root not implemented yet
Oct  8 16:41:28 host-40-40-40-13 kernel: [ 8848.379315] CIFS VFS: cifs_mount failed w/return code = -22
Oct  8 16:41:37 host-40-40-40-13 kernel: [ 8856.976371] CIFS VFS: Connecting to DFS root not implemented yet
Oct  8 16:41:37 host-40-40-40-13 kernel: [ 8856.977982] CIFS VFS: cifs_mount failed w/return code = -22


解决:

apt-get install smbfs

安装smbfs文件系统

+ mkdir -p stamp lib usr/include usr/lib make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' make[3]: Nothing to be done for 'prepare'. make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' make[3]: Nothing to be done for 'compile'. make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' make[3]: Nothing to be done for 'install'. make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/wrapper' rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' make[3]: Nothing to be done for 'prepare'. make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' make[3]: Nothing to be done for 'compile'. make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' cp -fpR /home/felix/mydisk/enterprise_gateway/build_dir/toolchain-aarch64-marvell-linux-gnu/linux-dev/* /home/felix/mydisk/enterprise_gateway/staging_dir/marvell-tools-249.0/ cp: preserving times for '/home/felix/mydisk/enterprise_gateway/staging_dir/marvell-tools-249.0/include': Operation not permitted Makefile:109: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/toolchain-aarch64-marvell-linux-gnu/stamp/.linux_installed' failed make[3]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/toolchain-aarch64-marvell-linux-gnu/stamp/.linux_installed] Error 1 make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/toolchain/kernel-headers' toolchain/Makefile:95: recipe for target 'toolchain/kernel-headers/install' failed make[2]: *** [toolchain/kernel-headers/install] Error 2 make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' toolchain/Makefile:93: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/toolchain-aarch64-marvell-linux-gnu/stamp/.toolchain_install' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/toolchain-aarch64-marvell-linux-gnu/stamp/.toolchain_install] Error 2 make[1]: Leaving directory '/home/felix/mydisk/enterprise_gateway' /home/felix/mydisk/enterprise_gateway/include/toplevel.mk:171: recipe for target 'world' failed make: *** [world] Error 2
最新发布
07-29
<think>我们正在解决的是在构建工具链时出现的 'cp: preserving times for ... Operation not permitted' 错误。 根据引用[2]中的信息,这个错误通常是由于cp或mv命令在尝试保留文件属性(如时间戳、权限)时,目标文件系统不支持这些属性(如ACL)而导致的。 具体来说,当从一个支持ACL(访问控制列表)的文件系统向一个不支持ACL的文件系统移动或复制文件时,如果使用了保留属性的选项(如cp的-p或-a选项,或者mv命令默认会尝试保留时间戳和权限),就会报错。 在构建工具链的过程中,我们可能会使用cp命令(可能带有保留属性的选项)来复制文件,而目标文件系统可能不支持源文件系统所具有的某些属性(如ACL、时间戳等),从而导致操作被拒绝。 解决方案: 1. 检查目标文件系统是否支持ACL等特性。例如,如果目标文件系统是FAT32或NTFS(在Linux中挂载),那么它们可能不支持Linux的权限、时间戳等特性。在这种情况下,我们需要避免使用保留属性的选项。 2. 如果构建脚本中使用了cp命令并带有保留属性的选项(如-p, -a, --preserve等),我们可以尝试去掉这些选项,或者使用其他方式复制文件。 3. 如果必须保留时间戳,但目标文件系统支持时间戳而不支持权限,我们可以使用--no-preserve选项来忽略权限,只保留时间戳(如果目标文件系统支持的话)。例如: ``` cp --no-preserve=mode,ownership,timestamps source dest # 不保留这些属性 ``` 但是,如果我们只想保留时间戳,可以尝试: ``` cp --preserve=timestamps source dest ``` 如果目标文件系统支持时间戳,那么这样可能可行;如果不支持,则仍然会报错。 4. 如果目标文件系统是网络文件系统(如Samba共享),则可能需要检查挂载选项。在挂载时,可以尝试添加一些选项来忽略权限,例如在挂载CIFS/Samba时使用`nounix`选项(这样不会尝试使用Unix扩展,包括权限)或者设置文件模式(file_mode)和目录模式(dir_mode)为777,例如: ``` mount -t cifs //server/share /mnt/win -o username=user,password=pass,file_mode=0777,dir_mode=0777 ``` 5. 如果问题发生在向Samba共享复制文件时,可以尝试在Samba服务器配置中设置`map archive = no`,`map system = no`和`map hidden = no`,这样Samba就不会尝试保留这些属性。 6. 如果构建工具链的脚本我们无法修改,那么我们可以尝试在复制之前临时改变umask,或者使用一个包装脚本来替换cp命令,在包装脚本中去掉有问题的选项。 7. 另外,引用[4]中提到Mac OS X中可能遇到类似问题,需要关闭SIP(系统完整性保护)或者使用csrutil来设置。但我们的问题是在构建工具链时,可能是在Linux环境下,所以这个参考可能不直接适用。 8. 如果目标文件系统是FAT32,那么它不支持权限和符号链接,也不支持超过4GB的文件。因此,在复制时,我们应该避免保留权限,并且不要复制符号链接(除非使用特殊方式处理)。 具体步骤: 步骤1:确认目标文件系统的类型。 使用`df -T`命令查看目标目录所在的文件系统类型。 步骤2:根据文件系统类型调整cp命令。 如果是FAT32/NTFS(挂载为vfat或ntfs): 使用不带任何保留属性的cp命令,或者使用`--no-preserve=all`选项。 步骤3:调整挂载选项(如果是挂载的文件系统)。 在/etc/fstab中修改挂载选项,例如对于vfat文件系统,可以添加`umask=000`选项,这样所有用户都有读写权限,并且不保留权限属性(因为FAT本身不支持)。 步骤4:如果构建脚本中使用了mv或cp命令,并且我们无法修改脚本,我们可以尝试设置别名(alias)来覆盖cp命令,例如: 在运行构建脚本之前,执行: alias cp='cp --no-preserve=all' 但是注意,这样可能会影响脚本中其他需要保留属性的复制操作。 步骤5:如果问题仍然存在,可以考虑使用rsync命令代替cp,并设置相应的选项来避免保留不支持属性。例如: rsync -rt --no-perms --no-owner --no-group source/ dest/ 这样只保留时间戳(如果目标文件系统支持的话),但不保留权限和所有者。 步骤6:对于Samba共享,确保在挂载时使用了正确的选项(如前所述)。 注意:在构建工具链时,可能需要保留一些文件的执行权限。如果目标文件系统不支持权限,那么我们需要在复制后手动添加执行权限(如果文件需要执行的话)。 示例解决方案(针对Samba共享): 假设错误信息为: cp: preserving times for '...': Operation not permitted 我们可以这样挂载Samba共享(以CIFS方式): sudo mount -t cifs //server/share /mnt/win -o username=user,password=pass,file_mode=0777,dir_mode=0777,nounix,nostrictsize 其中,`nounix`选项表示不使用Unix扩展(包括权限),而`file_mode`和`dir_mode`设置默认权限(尽管在nounix下可能无效,但设置宽权限以避免问题)。另外,`nostrictsize`可以避免检查磁盘空间限制(有时会有用)。 如果问题仍然存在,可以尝试使用`noperm`选项(允许客户端绕过权限检查): ... -o username=user,password=pass,noperm 但是注意,这可能会降低安全性。 总结:解决此问题的关键在于识别目标文件系统的限制,并调整复制命令或挂载选项以适应该限制。 相关问题: 1. 如何查看Linux中已挂载文件系统的类型和挂载选项? 2. 在复制文件到FAT32文件系统时如何保留时间戳? 3. 如何修改Samba服务器的配置以允许保留文件属性? 4. 在构建工具链时如何避免文件权限问题? 5. 使用rsync如何保留文件属性但忽略权限?</think>### 解决构建工具链时出现 `cp: preserving times for ... Operation not permitted` 错误的方法 #### 问题原因分析 1. **文件系统特性不兼容** - 当从支持完整 Linux 权限的文件系统(如 ext4)向**不支持权限继承**的文件系统(如 FAT32/NTFS/Samba共享)复制文件时,`cp -p` 或 `cp -a` 命令会尝试保留元数据(时间戳、权限等),但目标文件系统不支持这些特性[^2] - 常见场景: ```bash # 尝试保留权限复制到Samba/NTFS共享时 cp -p source_file /mnt/samba_share/ # 触发 Operation not permitted ``` 2. **挂载选项限制** - Windows 文件系统(NTFS/FAT32)挂载时默认不启用 Unix 权限支持 - Samba 共享可能未配置权限映射 3. **ACL 属性冲突** - 源文件包含 ACL 扩展属性,但目标文件系统不支持 ACL 存储[^2] --- ### 解决方案 #### 方法 1:修改挂载选项(推荐) 在挂载时启用权限支持: ```bash # 对于 NTFS 文件系统 sudo mount -t ntfs -o uid=1000,gid=1000,umask=000 /dev/sdX1 /mnt/win # 对于 Samba 共享 sudo mount -t cifs //server/share /mnt/win -o username=user,password=pass,file_mode=0777,dir_mode=0777,nounix ``` **关键参数**: - `uid/gid`:指定所有者 - `umask=000`:允许所有权限 - `file_mode/dir_mode=0777`:强制 777 权限 - `nounix`:禁用 Unix 扩展(解决 Samba 兼容性问题) > 永久生效:在 `/etc/fstab` 添加: > ```bash > //server/share /mnt/win cifs credentials=/etc/samba/creds,file_mode=0777,dir_mode=0777 0 0 > ``` #### 方法 2:使用 rsync 替代 cp ```bash rsync -rt --no-perms --no-owner --no-group source_file /mnt/win/ ``` **参数说明**: - `-r`:递归复制 - `-t`:保留修改时间 - `--no-perms/--no-owner`:跳过权限和所有者复制 #### 方法 3:禁用权限保留 ```bash # 复制时不保留权限 cp --no-preserve=all source_file /mnt/win/ # 仅复制内容(最安全) cp source_file /mnt/win/ # 不使用 -p/-a 参数 ``` #### 方法 4:修复现有文件权限 ```bash # 递归修复目标目录权限 sudo chmod -R 777 /mnt/win/ sudo chown -R $USER:$USER /mnt/win/ ``` --- ### 验证步骤 1. 检查挂载选项: ```bash mount | grep /mnt/win # 应包含 file_mode=0777 或类似权限设置 ``` 2. 测试文件复制: ```bash cp -v testfile /mnt/win/ && echo "Success" ``` 3. 检查文件属性: ```bash ls -l /mnt/win/testfile # 应显示 -rwxrwxrwx 权限 ``` --- ### 疑难解答 1. **Samba 特定问题**: - 在 Samba 配置中 (`/etc/samba/smb.conf`) 添加: ```ini [share] path = /srv/samba force user = youruser force group = yourgroup create mask = 0777 directory mask = 0777 ``` 2. **MacOS 系统限制**: - 如果是 macOS 环境,需禁用 SIP 保护[^4]: ```bash # 重启进入恢复模式 → 终端 csrutil disable ``` --- ### 关键注意事项 1. **安全警告**: - 777 权限意味着**所有用户可任意修改文件**,仅限封闭环境使用 - 生产环境建议使用更严格的权限(如 775) 2. **文件系统差异**: ```mermaid graph LR A[Linux 文件系统] -->|ext4/xfs| B[支持完整权限] A -->|NTFS/FAT32| C[部分支持权限] A -->|Samba/NFS| D[依赖服务端配置] ``` 3. **工具链构建建议**: ```bash # 在构建脚本开头添加权限修复 [[ -d /mnt/win ]] && sudo chmod -R u+rwX /mnt/win ``` > 参考原理:Linux 文件复制时的权限保留机制受文件系统特性限制[^2][^3],挂载选项决定权限兼容性[^1]。 --- ### 相关问题 1. 如何永久修改 Linux 对 NTFS 分区的挂载权限? 2. Samba 共享中如何实现 Linux 和 Windows 的权限映射? 3. 使用 rsync 时如何保留符号链接但不保留权限? 4. 在 Docker 容器中挂载 volume 时如何避免权限问题? 5. 如何批量修复已复制文件的权限错误
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值