In this tutorial, we will be learning how to mount an S3 compatible storage service as a Linux machine drive. This is useful for scenarios where you need to access your S3 compatible storage as a file system on your Linux machine, such as when you want to store and access data files from within your Linux machine.
For this tutorial, we will be using the S3 compatible storage service provided by MinIO as an example. MinIO is an open-source object storage server that is compatible with Amazon S3 API. You can also use other S3 compatible storage services like AWS S3, Wasabi, DigitalOcean Spaces, etc.
Prerequisites
- A Linux machine running Ubuntu, CentOS or any other distribution
- Root or sudo privileges
- A configured and running S3 compatible storage service like MinIO, AWS S3, Wasabi, DigitalOcean Spaces etc.
- Access credentials with read and write permissions for the S3 bucket you want to mount
Step 1: Install the S3FS-FUSE package
To mount an S3 compatible storage as a file system, we need to use a package called s3fs-fuse. This package allows us to mount the S3 compatible storage as a local file system using FUSE (Filesystem in Userspace).
Run the following command to install s3fs-fuse on your Linux machine:
Ubuntu/Debian
sudo apt-get update
sudo apt-get install s3fs
CentOS/RHEL
sudo yum install s3fs-fuse
Step 2: Configure Access Credentials
To access your S3 compatible storage, you need to provide your access key ID and secret access key. You can create these access credentials on your S3 compatible storage dashboard.
Next, create a file called .passwd-s3fs
in your home directory using the following command:
touch ~/.passwd-s3fs
Open the file with your favorite text editor and enter your access key ID and secret access key in the following format:
chmod 600 ~/.passwd-s3fs
Step 3: Create a Mount Point
Next, create a directory where you want to mount your S3 compatible storage as a file system. This directory is known as the mount point. For this tutorial, we will create a directory called s3-mount
in the root directory.
sudo mkdir /s3-mount
Step 4: Mount the S3 Compatible Storage
Now that we have installed s3fs-fuse, configured our access credentials, and created a mount point, we can mount our S3 compatible storage as a file system using the following command:
sudo s3fs <bucket-name> /s3-mount -o passwd_file=~/.passwd-s3fs -o url=<storage-url> -o endpoint=<storage-endpoint> -o dbglevel=info -o curldbg
Replace <bucket-name>
with the name of the bucket you want to mount. <storage-url>
should be replaced with the URL of your S3 compatible storage. <storage-endpoint>
should be replaced with the endpoint of your S3 compatible storage.
For example, if you are using MinIO, the URL and endpoint would be http://<minio-server-ip>:9000
. Replace <minio-server-ip>
with the IP address of your MinIO server.
After running the above command, you should be able to access your S3 compatible storage as a file system in the /s3-mount
directory.
Step 5: Automounting the S3 Compatible Storage
To ensure that your S3 compatible storage is mounted every time you start your Linux machine, you can add an entry to the /etc/fstab
file.
First, create a backup of the /etc/fstab
file using the following command:
sudo cp /etc/fstab /etc/fstab.bak
Next, open the /etc/fstab
file using your favorite text editor and add the following line at the end of the file:
s3fs#<bucket-name> /s3-mount fuse _netdev,passwd_file=/home/<user>/.passwd-s3fs,url=<storage-url>,endpoint=<storage-endpoint> 0 0
Replace <bucket-name>
with the name of the bucket you want to mount. <user>
should be replaced with the name of the user who owns the .passwd-s3fs
file. <storage-url>
should be replaced with the URL of your S3 compatible storage. <storage-endpoint>
should be replaced with the endpoint of your S3 compatible storage.
Save the file and exit the text editor.
Step 6: Unmounting the S3 Compatible Storage
To unmount your S3 compatible storage from your Linux machine, use the following command:
sudo umount /s3-mount
Conclusion
In this tutorial, we learned how to mount an S3 compatible storage as a Linux machine drive using s3fs-fuse. We also learned how to configure access credentials, create a mount point, and automate the mounting process.
This method can be used to access and manage files stored on S3 compatible storage services from within your Linux machine just like you would with a local file system.