Automatically Mounting NFS File Systems on Linux
Method 1: Using CFS Client Assistant for Setting (Recommended)
Note:
If you have used fstab or other methods, to avoid conflicts, it is recommended to disable the existing method for restarting automatic mount before using this method.
Log in to the CFS console.
In the left navigation tree, select File System List to go to the File System List page.
On the right side of the file system to be mounted, click Action > Mount.
In the pop-up window, view the automatic mounting configuration status of the selected file systems on the CVM (only supported on CVMs with Automation Tools installed). Select the instances to be mounted and click Next step.
Status Description Configured On the CVM, the automatic mounting of selected file systems upon server restart has been configured by using the console or the client assistant. Not configured On the CVM, the automatic mounting of selected file systems upon restart has not been configured by using the console or the client assistant. Not supported For Windows clients, automatic mounting of file systems upon server restart by using the console or client assistant is not supported currently. Note:
This query method only applies to the automatic mounting implemented by using the client assistant and cannot detect the automatic mounting configured through fstab or other methods.
Fill in the target local directory and other parameters on this page, select Restart Automatic Mount, and click Next.
When the execution status is Completed, the mounting is successful, and automatic mounting upon restart has been configured.
If you have mounted the selected file system in this directory, the execution status will be Failed, because repeatedly mounting the same file system in the same directory is not supported.
However, you can hover the mouse pointer over the execution status. When the execution details display the following content, the restart automatic mounting feature has been configured and enabled.Note:
- The restart automatic mounting feature setting does not affect running CVMs and only takes effect when the server is restarted.
- This process concurrently attempts to mount the specified file systems within 5 minutes after the server is restarted, and exits upon timeout without affecting the normal operation of the Linux system.
- When a mounting failure occurs, you can view the automatic mounting logs saved in
/usr/local/reboot_mount_cfs/logsto quickly locate the issue. - To disable automatic mounting, modify the reboot_mount_cfs.sh file in
/usr/local/reboot_mount_cfs/bin. Change "true" in the conditional expression to "false" and save the changes to disable automatic mounting upon restart.
vim /usr/local/reboot_mount_cfs/bin/reboot_mount_cfs.sh # ... The above content is omitted... if false; then # Change "true" in the conditional expression to "false". vDoMount="sudo mount.lustre x.x.x.x@tcp:/xxxxxxxx/cfs /path/to/mountpoint_x" # Command to disable the restart automatic mounting feature for the specified file systems # ... The following content is omitted...
Method 2: Using Systemd for Configuration
Note:
Essentially, both Method 2 and Method 1 implement file system mounting based on systemd. The difference is that Method 1 implements configuration automatically, while Method 2 implements configuration manually.
Create a folder in
/usr/local/to store execution scripts and running logs.Note:
To avoid failure in querying the status in the console, it is recommended not to change the file name.
cd /usr/local/ mkdir -p reboot_mount_cfs/logs mkdir -p reboot_mount_cfs/binCreate the reboot_mount_cfs.sh script in
reboot_mount_cfs/bin, modify the mount command where prompted as needed, and grant executable permissions.cd /usr/local/reboot_mount_cfs/bin file="reboot_mount_cfs.sh" if [ -e "$file" ]; then echo "File already exists, skipping creation." else cat > "$file" << 'EOF' #!/bin/bash ####Logs during file system mounting in the startup process#### readonly LOG_FILE=/usr/local/reboot_mount_cfs/logs/reboot_mount_cfs-$(date +%Y%m%d_%H%M%S).log function main() { local vDryRun=false local vDoMount ####Usage Instructions#### # 0) Mount a file system. # 1) Change the true in the conditional expression to false to disable automatic mounting upon server restart. # 2) Replace vDoMount with the actual mount command for the file system. ####Usage Instructions#### if true; then vDoMount="mount.lustre x.x.x.x@tcp:/xxxxxxxx/cfs /path/to/mountpoint_x" if ${vDryRun}; then echo "${vDoMount}" else echo "[$(date +%Y-%m-%d\ %H:%M:%S)]Try to run: ${vDoMount}" >> "${LOG_FILE}" local vTimesRetried=0 while [[ ${vTimesRetried} -le ${MAX_MOUNTS2RETRY} ]]; do timeout 300 ${vDoMount}& pid=$! wait $pid vRc=$? if [[ ${vRc} -ne 0 ]]; then echo "[$(date +%Y-%m-%d\ %H:%M:%S)][${vRc}]Failed to run: ${vDoMount}" >> "${LOG_FILE}" sleep 120 # Delay for 2 minutes before retry to avoid network slow start. vTimesRetried=$((vTimesRetried + 1)) continue else echo "[$(date +%Y-%m-%d\ %H:%M:%S)]Succeed to run: ${vDoMount}" >> "${LOG_FILE}" break fi done fi fi echo "====All mountings tried====" >> "${LOG_FILE}" # This is a positioning line, do not delete or modify it. echo >> "${LOG_FILE}" echo "Current mountpoints of CFS:" >> "${LOG_FILE}" mount -t nfs >> "${LOG_FILE}" mount -t nfs4 >> "${LOG_FILE}" mount -t lustre >> "${LOG_FILE}" wait ####Tool Usage Constraints### # Only for assisting the systemd service in completing the initial mounting during system startup. # Do not use it in non-startup scenarios. ###Tool Usage Constraints### } main EOF fi chmod a+x reboot_mount_cfs.shCreate reboot_mount_cfs.service in
/etc/systemd/system.cd /etc/systemd/system echo '[Unit] Description=Used to automatically mount Turbo filesystems. After=default.target [Service] ExecStart=/usr/local/reboot_mount_cfs/bin/reboot_mount_cfs.sh [Install] WantedBy=default.target ' > reboot_mount_cfs.serviceSet the reboot_mount_cfs.service service to start automatically at boot. When the system starts, the mount command with the status of True in reboot_mount_cfs.sh will be executed automatically.
systemctl daemon-reload && systemctl enable reboot_mount_cfs.service
Method 3: Using fstab for Configuration
Note:
- After the automatic mounting is configured by using this method, if a file system cannot be mounted properly (for example, it has been deleted), the Linux system cannot start normally. In this case, enter the rescue mode during system startup, delete the automatic mount command in fstab, and then restart the host.
- Method 1 or Method 2 is recommended to avoid the above situation.
First, connect to the CVM instance that needs to automatically mount the file system by logging in through the CVM console or by remote login. Open the
/etc/fstabfile (ensure the account you logged in has root permissions).//Use the following command to open the fstab file. vi /etc/fstabAfter opening the fstab file, enter i (insert), and add the following command line in
/etc/fstab. The following mounting methods are supported:Using NFS v4.0 to mount file systems <Mount target IP address>:/ <target mount directory> nfs vers=4,minorversion=0,hard,timeo=600,retrans=2,_netdev,noresvport 0 0 For example: 10.10.19.12:/ /local/test nfs vers=4,minorversion=0,hard,timeo=600,retrans=2,_netdev,noresvport 0 0Using NFS v3.0 to mount file systems <Mount target IP address>:/<fsid> <target mount directory> nfs vers=3,nolock,proto=tcp,hard,timeo=600,retrans=2,_netdev,noresvport 0 0 For example: 10.10.19.12:/djoajeo4 /local/test nfs vers=3,nolock,proto=tcp,hard,timeo=600,retrans=2,_netdev,noresvport 0 0Mounting with Turbo <Mount target IP address>@tcp0:/<fsid>/cfs <target mount directory> lustre defaults,_netdev 0 0 Example: 172.16.0.7@tcp0:/01184207/cfs /root/turbo lustre defaults,_netdev 0 0Press the Esc key on the keyboard and enter ":wq" to save the above modifications. After restarting the client, you can see that the file system is automatically mounted.
Automatically Mounting File Systems on Windows
When mounting a file system, select Reconnect at sign-in, as shown in the following figure. For more help information on mounting, see Using CFS File Systems on Windows Clients.