Mount an SMB file system

更新时间: 2026-06-03 18:55:15

Linux has limited compatibility with the SMB protocol. We recommend mounting an SMB file system on a Linux client only when you need to share data across different operating systems. This topic describes how to mount an SMB file system on a Linux ECS instance for read and write operations.

Prerequisites

  • A Linux ECS instance is available in the same region as the SMB file system. For more information, see Create an ECS instance.

    Important
    • For Linux clients, we recommend mounting NFS file systems. Due to the limited compatibility of Linux with the SMB protocol, mount an SMB file system on a Linux client only when you need to share data across different operating systems.

    • The SMB clients in some earlier versions of Linux have defects in certain scenarios. If you use a Linux operating system version that is not officially supported, Alibaba Cloud cannot guarantee the reliability of the SMB file system.

    This topic applies only to the following officially supported Linux distributions:

    Operating system

    Version

    CentOS

    CentOS 7.6 64-bit: 3.10.0-957.21.3.el7.x86_64 and later

    Alibaba Cloud Linux

    • Alibaba Cloud Linux 2.1903 64-bit: 4.19.43-13.2.al7.x86_64 and later

    • Alibaba Cloud Linux 3.2104 64-bit: 5.10.23-4.al8.x86_64 and later

    Debian

    Debian 9.10 64-bit: 4.9.0-9-amd64 and later

    Ubuntu

    Ubuntu 18.04 64-bit: 4.15.0-52-generic and later

    openSUSE

    openSUSE 42.3 64-bit: 4.4.90-28-default and later

    SUSE Linux

    SUSE Linux Enterprise Server 12 SP2 64-bit: 4.4.74-92.35-default and later

    CoreOS

    CoreOS 2079.4.0 64-bit: 4.19.43-coreos and later

  • An SMB file system has been created. For more information, see Create a General-purpose NAS file system.

  • A mount target has been created. For more information, see Create a mount target.

  • Network connectivity has been established.

    • Ensure that the Linux ECS instance and the SMB file system are in the same VPC.

    • Check the security group associated with the file system to ensure that the Linux ECS instance can access the SMB file system.

    • Ensure that TCP port 445 is open. SMB file systems communicate over TCP port 445.

      If port 445 is not open, add a security group rule that allows access to port 445 to the security group of the target ECS instance. For more information, see Add a security group rule.

Install a CIFS client

Before you can mount an SMB file system on a Linux client, you must install a CIFS client. This is a one-time configuration that you need to perform on each Linux server.

  1. Connect to the Linux ECS instance. For more information, see Connection methods.

  2. Install the CIFS client.

    Ubuntu and Debian

    Use the apt-get package management tool.

    sudo apt-get update
    sudo apt-get install cifs-utils

    RHEL, CentOS, and Alibaba Cloud Linux

    Use the yum package manager.

    sudo yum install cifs-utils

    OpenSUSE and SLES12-SP2

    Use the zypper tool.

    sudo zypper install cifs-utils

    CoreOS

    Use the following method to install the client:

    1. Configure SELinux.

      sed -i 's/SELINUXTYPE=mcs/SELINUXTYPE=targeted/' /etc/selinux/config
    2. Manually compile the CIFS client tools on CoreOS.

      You can follow these steps to start a Fedora container to compile the CIFS client tools. Alternatively, download the official Alibaba Cloud CIFS toolkit for CoreOS and copy it to the /tmp/ or /bin directory.

      1. On CoreOS, start a Fedora container to compile cifs-utils.

        docker run -t -i -v /tmp:/cifs fedora /bin/bash
      2. In the Docker environment, run the following commands in sequence.

        1. yum groupinstall -y "Development Tools" "Development Libraries"
        2. yum install -y bzip2
        3. curl https://download.samba.org/pub/linux-cifs/cifs-utils/cifs-utils-6.9.tar.bz2 --output cifs-utils-6.9.tar.bz2;
        4. bunzip2 cifs-utils-6.9.tar.bz2 && tar xvf cifs-utils-6.9.tar
        5. cd cifs-utils-6.9; ./configure && make
        6. cp mount.cifs /cifs/
        7. exit

Mount the SMB file system

On Linux, you can mount a NAS SMB file system either manually or automatically. A manual mount is temporary and must be repeated each time the server restarts. An automatic mount is persistent and does not need to be repeated after a restart. To ensure the mount persists after a reboot, we recommend configuring an automatic mount after you successfully mount the file system manually.

Manual mount

To mount the NAS SMB file system to a Linux ECS instance, you must use its mount target address.

  1. Connect to the Linux ECS instance. For more information, see Connection methods.

  2. Run the following command to mount the file system.

    sudo mount -t cifs //file-system-id.region.nas.aliyuncs.com/myshare /mnt -o vers=2.1,guest,uid=0,gid=0,dir_mode=0755,file_mode=0755,mfsymlinks,cache=strict,rsize=1048576,wsize=1048576

    The command syntax is: sudo mount -t cifs //<mount-target-address>/myshare <mount-directory> -o <mount-options>

    Parameter

    Description

    File system type

    When you mount an SMB file system on a Linux operating system, you must specify the -t cifs parameter.

    Mount target address

    The mount target address that is automatically generated when you create a mount target for the file system. Replace the placeholder with your actual value. To obtain the mount target address, log on to the NAS console, click the ID of the target file system, click Mount Targets, and then hover over the 挂载点 icon in the Mount Target column.

    myshare

    The name of the shared directory of the SMB file system. This name cannot be changed.

    Mount directory

    The local directory where you want to mount the file system, such as /mnt/sharepath.

    Mount options

    Specify required mount options by adding the -o parameter:

    • vers: The SMB protocol version. Versions 2.1 and later are supported.

    • guest: Enables guest access, which does not require a password. This option is required for clients that use NTLM authentication.

    • rsize: The maximum size of data in bytes for each read request. We recommend that you set this to 1048576 (1 MB).

    • wsize: The maximum size of data in bytes for each write request. We recommend that you set this to 1048576 (1 MB).

    Specify optional mount options by adding the -o parameter:

    • uid: The user ID of the file owner after the file system is mounted. If this option is not specified, the default value is 0.

    • gid: The group ID of the file owner after the file system is mounted. If this option is not specified, the default value is 0.

    • dir_mode: The permissions for directories. The value must start with 0, such as 0755 or 0644. If this option is not specified, the default value is 0755.

    • file_mode: The permissions for regular files. The value must start with 0, such as 0755 or 0644. If this option is not specified, the default value is 0755.

    • mfsymlinks: Enables support for symbolic links.

    • cache:

      • cache=strict: Enables client-side caching for the SMB file system. This is the default setting if the cache option is not specified.

      • cache=none: Disables client-side caching for the SMB file system.

    • atime|relatime: If your business is not highly sensitive to file access times, do not use the atime option. By default, the file system is mounted with the relatime option.

    Note
    • An authorized administrator has full control over the SMB file system.

    • You can run the mount | grep cifs command to query your mount target information.

    • If you use an unsupported Linux distribution, we strongly recommend that you use a kernel version of 3.10.0-514 or later. If the Linux kernel version is 3.7 or earlier, you must set the cache=strict parameter in the mount options. You can run the uname -a command to check the current kernel version.

  3. Run the mount -l command to check the mount result.

    If the output is similar to the following, the mount was successful.

    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=800928k,mode=700)
    //xxx-cn-hangzhou.nas.aliuncs.com/mushare on /mnt type cifs (rw,relatime,vers=2.1,sec=none,cache=strict,domain=,uid=0,noforceuid,gid=0,noforcegid,addr=xxx,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1)

    After a successful mount, you can run the df -h command to view the capacity information of the current file system.

    If the mount fails, troubleshoot the issue. For more information, see Troubleshoot SMB mount failures on Linux.

  4. After the file system is mounted, you can access it from the Linux ECS instance to perform read or write operations.

    You can access and use the NAS SMB file system as a regular directory. Example:

    [root@ixxxx ~]# mkdir /mnt/dir1
    [root@ixxxx ~]# mkdir /mnt/dir2
    [root@ixxxx ~]# touch /mnt/file1
    [root@ixxxx ~]# echo 'some file conent' > /mnt/file2
    [root@ixxxx ~]# ls /mnt
    dir1  dir2  file1  file2  tmp

(Optional) Automatic mount

You can configure the /etc/fstab file on the Linux ECS instance to automatically mount the SMB file system when the instance restarts.

Note

Before you configure automatic mounting, make sure that the manual mount is successful. This helps prevent the ECS instance from failing to start.

  1. Open the /etc/fstab configuration file and add the automatic mount configuration.

    • Replace <file-system-id.region.nas.aliyuncs.com> with the actual mount target address of the NAS file system, for example, 237*******-*****.cn-hangzhou.nas.aliyuncs.com.

    • Replace </mnt> with the local mount directory, for example, /mnt.

    file-system-id.region.nas.aliyuncs.com/myshare /mnt cifs vers=3,guest,uid=0,gid=0,dir_mode=0755,file_mode=0755,mfsymlinks,cache=strict,rsize=1048576,wsize=1048576 0 0

    For a description of the main parameters in the example, see the parameter table for the manual mount command. The other parameters are described as follows.

    Parameter

    Description

    0 (the first value after wsize)

    A non-zero value indicates that the file system should be backed up by the dump command. For a NAS file system, this value must be 0.

    0 (the second value after wsize)

    The order in which the fsck command checks file systems at startup. For a NAS file system, this value must be 0, which indicates that fsck should not run at startup.

  2. Run the reboot command to restart the ECS instance.

    Important

    Restarting the ECS instance interrupts your services. We recommend that you perform this operation during off-peak hours.

  3. Verify that the automatic mount was successful.

    Note

    Within one minute after the ECS instance restarts, run the df -h command to confirm that the NAS file system is mounted.

Use cases

You can configure different mount options for different use cases to achieve optimal file system performance. The following sections describe common use cases and their recommended mount option configurations.

Shared access for Linux

To share data among multiple Linux ECS instances without permission controls, an administrator can mount the file system on each instance as follows:

 mount -t cifs //file-system-id.region.nas.aliyuncs.com/myshare /mnt/sharepath -o vers=2.1,guest,mfsymlinks

The following table describes the important parameters.

  • file-system-id.region.nas.aliyuncs.com: The mount target address of the file system. Replace the placeholder with your actual value. To obtain the mount target address, log on to the NAS console, click the ID of the target file system, click Mount Targets, and then hover over the 挂载点 icon in the Mount Target column.

  • /mnt/sharepath: The local directory to which you want to mount the file system. Replace the placeholder with the actual path.

Multi-user home directories

When you share file system data among multiple Linux ECS instances, if you require permission controls, you can specify the uid, gid, dir_mode, and file_mode parameters during the mount process.

Shared access for web servers

You can install a web server, such as Apache, on multiple Linux ECS instances and use an SMB file system for shared storage.

Note
  • SMB file systems provide shared access, horizontal scalability, and high availability. However, their underlying mechanism is different from that of local disks, which can result in lower performance for small-file access in some scenarios. To achieve optimal performance for web server workloads, consider storing only the files that must be shared on the SMB file system. Keep components that do not require shared access, such as the web server application, on local disks.

  • Web server applications typically generate heavy network traffic. In this scenario, you must enable the web server acceleration feature. To apply for this feature, contact the Alibaba Cloud NAS team.

Shared access for Windows and Linux

If you need to access the content of an SMB file system from both Windows and Linux ECS instances, you must use client-side caching when you mount the file system on the Linux ECS instance. You can either explicitly set the cache=strict option or rely on the default behavior, which also uses strict caching.

Access control

Alibaba Cloud NAS SMB file systems support user authentication and file system-level permission control based on an Active Directory (AD) domain. By accessing an SMB file system as a domain user, you can implement file- and directory-level access control.

For more information about how to implement user authentication and file system-level access control based on an AD system, see Join an SMB mount target to an AD domain and Mount and use an SMB file system on a Linux client as an AD domain user.

Related documents

上一篇: Mount an NFS file system 下一篇: Mount a file system on a Windows ECS instance
阿里云首页 文件存储 NAS 相关技术圈