smbnetfs写入Windows Server共享时遇输入/输出错误的解决求助
smbnetfs挂载Windows Server共享写入异常问题
问题现象
在Ubuntu 22.04(含Docker容器内)使用smbnetfs挂载Windows Server共享目录时,文件读取正常,但写入操作存在异常:
- Haskell应用写入时崩溃,提示"Input/output error",仅生成0KB空文件
- 容器终端或Ubuntu 22.04主机直接写入也出现相同问题,已排除Haskell和Docker的影响,聚焦bash环境下的文件写入操作
可正常执行的操作
touch <mount-dir>/file.txt:生成0KB文件,使用nano编辑正常echo "demo content" > <mount-dir>/file.txt:执行正常(注意重定向运算符为单大于号)mkdir -p <mount-dir>/path/to/file/:创建目录无问题- 将容器本地创建的文件移动至
<mount-dir> - 删除共享目录内文件:
rm <mount-dir>/file.txt - 重命名共享目录内文件:
mv <mount-dir>/file.txt <mount-dir>/fileMv.txt
执行失败的操作
- 执行
touch <mount-dir>/file.txt生成0KB空文件 - 执行
echo "demo-content" >> <mount-dir>/file.txt时提示"Input/output error"(注意重定向运算符为双大于号)
配置信息
smbnetfs配置
smbnetfs.conf
... show_$_shares "true" ... include "smbnetfs.auth" ... include "smbnetfs.host"
smbnetfs.auth
auth "<windows-server-fqdn>/<share>" "<domain>/<user>" "<password>"
smbnetfs.host
host <windows-server-fqdn> visible=true
Docker配置
运行参数
... --device=/dev/fuse \ --cap-add SYS_ADMIN \ --security-opt apparmor:unconfined \ ...
Dockerfile
FROM debian:bullseye-20220711-slim@sha256:f52f9aebdd310d504e0995601346735bb14da077c5d014e9f14017dadc915fe5 ARG DEBIAN_FRONTEND=noninteractive # Prerequisites RUN apt-get update && \ apt-get install -y --no-install-recommends \ fuse=2.9.9-5 \ locales=2.31-13+deb11u3 \ locales-all=2.31-13+deb11u3 \ libcurl4=7.74.0-1.3+deb11u1 \ libnuma1=2.0.12-1+b1 \ smbnetfs=0.6.3-1 \ tzdata=2021a-1+deb11u4 \ jq=1.6-2.1 && \ rm -rf /var/lib/apt/lists/* # Set the locale ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 # Copy runtime artifacts WORKDIR /app COPY --from=build /home/vscode/.local/bin/Genesis-exe . COPY entrypoint.sh . ## Prepare smbnetfs configuration files and create runtime user ARG MOUNT_DIR=/home/moduleuser/mnt ARG SMB_CONFIG_DIR=/home/moduleuser/.smb RUN useradd -ms /bin/bash moduleuser && mkdir ${SMB_CONFIG_DIR} # Set file permission so, that smbnetfs.auth and smbnetfs.host can be created later RUN chmod -R 700 ${SMB_CONFIG_DIR} && chown -R moduleuser ${SMB_CONFIG_DIR} # Copy smbnetfs.conf and restrict file permissions COPY smbnetfs.conf ${SMB_CONFIG_DIR}/smbnetfs.conf RUN chmod 600 ${SMB_CONFIG_DIR}/smbnetfs.conf && chown moduleuser ${SMB_CONFIG_DIR}/smbnetfs.conf # Create module user and create mount directory USER moduleuser RUN mkdir ${MOUNT_DIR} ENTRYPOINT ["./entrypoint.sh"]
提示:该问题与Docker无关,在Ubuntu 22.04主机直接操作也存在相同问题。
更新信息
更新1:调试日志
启动smbnetfs调试模式后,执行失败操作时生成以下日志:
open flags: 0x8401 /<windows-server-fqdn>/share/sub-dir/file.txt 2022-07-25 07:36:32.393 srv(26)->smb_conn_srv_open: errno=6, No such device or address 2022-07-25 07:36:34.806 srv(27)->smb_conn_srv_open: errno=6, No such device or address 2022-07-25 07:36:37.229 srv(28)->smb_conn_srv_open: errno=6, No such device or address unique: 12, error: -5 (Input/output error), outsize: 16
更新2:跨SMB服务器测试
使用Linux-based SMB服务器时,echo "demo-content" >> <mount-dir>/file.txt可正常执行。该服务器配置如下:
Dockerfile
FROM alpine:3.7@sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b RUN apk add --no-cache --update \ samba-common-tools=4.7.6-r3 \ samba-client=4.7.6-r3 \ samba-server=4.7.6-r3 RUN mkdir -p /Shared && \ chmod 777 /Shared COPY ./conf/smb.conf /etc/samba/smb.conf EXPOSE 445/tcp CMD ["smbd", "--foreground", "--log-stdout", "--no-process-group"]
smb.conf
[global] map to guest = Bad User log file = /var/log/samba/%m log level = 2 [guest] public = yes path = /Shared/ read only = no guest ok = yes
更新3:补充正常操作
除初始列出的操作外,以下操作也可正常执行:
- 将容器本地创建的文件移动至
<mount-dir> - 删除共享目录内文件:
rm <mount-dir>/file.txt - 重命名共享目录内文件:
mv <mount-dir>/file.txt <mount-dir>/fileMv.txt
更新4:问题匹配
已确认该问题为smbnetfs针对Windows Server SMB共享的兼容性问题,存在相同问题的公开报告,核心表现为以追加模式打开文件时触发I/O错误。
内容的提问来源于stack exchange,提问作者Joe
相关产品推荐
相关产品推荐

