This topic describes how to use ossfs to mount an Object Storage Service (OSS) bucket to a local file system in Linux.
Prerequisite
Install ossfs 1.0 and configure ossfs 1.0.
Mount command format
Command format:
ossfs bucket_name /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com -o sigv4 -o region=cn-hangzhou
Parameter description
ossfs
: The ossfs startup program.bucket__name
: The name of the bucket to be mounted./tmp/ossfs
: The local directory to which the target bucket is mounted.-o
: The prefix parameter for mount options. This parameter is required in the mount command.url=http://oss-cn-hangzhou.aliyuncs.com
: Theurl
mount option specifies the endpoint of the target bucket. The option value format ishttp://Endpoint
.To view the endpoint of the target bucket, go to the Bucket List page, select the target bucket, and then click Overview in the left-side navigation pane. You can view the region of the target bucket in the Access Points section on the Overview page. In this example, a bucket in the China (Hangzhou) region is used.
sigv4
: Controls whether to use V4 signatures. Add-osigv4
when mounting. By default, ossfs uses OSS V1 signatures. After this mount option is added, ossfs uses the OSS V4 signature process to send requests to OSS.region=cn-hangzhou
: The region identifier for OSS bucket requests. Add-oregion=<region_id>
when mounting. The default value is empty. When using V4 signatures, you must add this option as the identifier of the region where the request is initiated.
Basic mounting
Mount using configuration files
Create a mount directory.
Run the following command to create custom empty directories
/tmp/ossfs-1
and/tmp/ossfs-2
as mount directories for the target bucket.mkdir /tmp/ossfs-1 /tmp/ossfs-2
Run the mount command.
Run the following two commands to mount
bucket-test-1
andbucket-test-2
configured in the default configuration file to the local/tmp/ossfs-1
and/tmp/ossfs-2
directories respectively.ossfs bucket-test-1 /tmp/ossfs-1/ -o url=http://oss-cn-hangzhou.aliyuncs.com -o sigv4 -o region=cn-hangzhou ossfs bucket-test-2 /tmp/ossfs-2/ -o url=http://oss-cn-hangzhou.aliyuncs.com -o sigv4 -o region=cn-hangzhou
The mount result is shown in the following figure.
Mount using ECS RAM Role
Create a mount directory.
Run the following command to create an empty directory
/tmp/ossfs
as the mount directory for the target bucket.mkdir /tmp/ossfs
Run the mount command.
NoteWhen using the instance metadata URL to mount ossfs, only normal mode access is supported. For information about metadata access modes, see Metadata access modes.
Run the following command to mount a bucket named
bucket1
to the local/tmp/ossfs
directory.Note: When mounting a bucket using the ECS RAM Role method, you need to use the
ram_role
parameter to specify the instance metadata URL.100.100.100.200
is the default IP address of the Alibaba Cloud ECS instance metadata service and does not need to be changed.EcsRamRoleOssTest
is the name of the role bound to the ECS instance. Please replace it with your target role name. The rest of the information does not need to be changed.ossfs bucket1 /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com -o ram_role=http://100.100.100.200/latest/meta-data/ram/security-credentials/EcsRamRoleOssTest -o sigv4 -o region=cn-hangzhou
The mount result is shown in the following figure.
Scenario-based mounting
You can mount only specific directories when mounting, or add mount options to choose appropriate mount options based on different usage scenarios to complete the bucket mounting. Note: Make sure that the local directory is empty before you run the mount command.
Mount a specific directory
Run the following command to mount the folder
directory in bucket-ossfs-test
to the local /tmp/ossfs-folder
directory.
ossfs bucket-ossfs-test:/folder /tmp/ossfs-folder -o url=http://oss-cn-hangzhou.aliyuncs.com -o sigv4 -o region=cn-hangzhou
Mount using a specified configuration file
Mount option: The passwd_file mount option is used to specify the path of a non-default ossfs 1.0 configuration file during mounting. The permissions of the specified configuration file must be set to 600.
Mount example
Run the following command to mount
bucket-test-3
configured in the specified configuration file to the local/tmp/ossfs-3
directory.ossfs bucket-test-3 /tmp/ossfs-3 -o url=http://oss-cn-hangzhou.aliyuncs.com -o passwd_file=/etc/passwd-ossfs-3 -o sigv4 -o region=cn-hangzhou
Enable debug logs when mounting
Mount option: The dbglevel mount option is used to set the log information level. The supported log information levels are
critical
,error
,warn
,info
, anddebug
. The default value iscritical
. Default log retention path: CentOS systems save logs in /var/log/messages, while Ubuntu systems save logs in /var/log/syslog. You can also specify the target log file path using thelogfile
mount option.Mount example 1
Run the following command to mount
bucket-ossfs-test-1
to the local/tmp/ossfs-1
directory, enablelibfuse
debug logs using-d
, and set the log information level todebug
using thedbglevel
mount option.ossfs bucket-ossfs-test-1 /tmp/ossfs-1 -d -o dbglevel=debug -o sigv4 -o region=cn-hangzhou
Mount example 2
Run the following command to mount
bucket-ossfs-test-2
to the local/tmp/ossfs-2
directory, set the log information level todebug
, enablelibfuse
debug logs, and output the log information to the foreground terminal using the-f
mount option.ossfs bucket-ossfs-test-2 /tmp/ossfs-2 -d -o dbglevel=debug -f -o sigv4 -o region=cn-hangzhou
Configure access permissions when mounting
By default, the directory to which ossfs mounts the bucket can be accessed only by the owner of the mount point. The owner of the mount point is the user who performs the mount operation. To modify the default permission configurations and allow other users or user groups to access the mount point, you can use the following options when you run ossfs:
Mount option | Description |
allow_other | Modifies the permissions on the mount point to allow all users to access the directory instead of the objects in the directory. The permissions for files in the directory need to be set separately. Use the |
uid | Specifies the user ID (UID) of the owner of the directory. |
gid | Specifies the group ID (GID) of the owner of the directory. |
umask | Specifies the permission mask of files and directories on the mount point. For example, to set the permissions of files on the mount point to 770, add -o umask=007. To set the permissions of files on the mount point to 700, add -o umask=077. |
Mount example 1
Run the following command to mount
bucket_name
to the localmount_point
directory, and use theallow_other
mount option to set the mount directory permissions to 777, allowing all users to access it.ossfs bucket_name mount_point -o url=endpoint -o allow_other -o sigv4 -o region=cn-hangzhou
Mount example 2
Run the following command to mount
bucket_name
to the localmount_point
directory, and use theumask
mount option to set the mount directory and file permissions to 770, allowing only users in the same group to access.ossfs bucket_name mount_point -o url=endpoint -o umask=007 -o sigv4 -o region=cn-hangzhou
Mount example 3
Run the following command to obtain the UID, GID, and groups of a specified user. In this example, the www user is used.
id www
The command output is shown in the following figure.
Run the following command to mount
bucket_name
to the localmount_point
directory, and use theuid
andgid
mount options to specify the user and group, allowing only users in the same group to access with permissions set to 770. Theuid
andgid
information uses 1000 as an example. Replace them with the target user'suid
andgid
information before executing the mount command.ossfs bucket_name mount_point -o url=endpoint -o allow_other -o uid=1000 -o gid=1000 -o umask=007 -o sigv4 -o region=cn-hangzhou
Useful tips
Unmount a bucket
Run the following command to unmount a bucket that is mounted to the local file system. For example, unmount the file system mounted to the /tmp/ossfs
path.
umount /tmp/ossfs
FAQ
To mount an OSS bucket in Windows, use Cloud Storage Gateway (CSG). For more information, see Use file gateways in the Alibaba Cloud Management Console and Access SMB shared directories.
You are not charged traffic fees when you use a RAM role of an ECS instance to mount a bucket to a local file system by using an internal endpoint. For more information about traffic fees, see Traffic fees.
If your ECS instance and bucket are not located in the same region and you want to mount a bucket to a local file system across regions, make sure that the network is stable. You can use a public endpoint to mount the bucket to the local file system. In addition, you can access OSS services across regions from an ECS instance over the internal network.
If you want to build an IIS website through Cloud Storage Gateway and use OSS as data storage, see How to build an IIS website by using Alibaba Cloud Storage Gateway.
If you need to mount OSS on a Windows operating system, see Rclone.
For more information about mounting, permissions, and other related issues, see FAQ.