linuxubuntugcsfusefstab

How to use mount command in fstab file


After creating /mnt/bucket folder which is to be used as a local mounting-point for Google Bucket:

sudo mkdir /mnt/bucket
sudo chmod 777 /mnt/bucket

I can successfully mount it to mybucket Google Bucket by simply typing sudo mount followed by with all its endless arguments in Ubuntu terminal, like so:

sudo mount -t gcsfuse -o key_file=/keys/key.json -o rw -o allow_other -o file_mode=777 -o dir_mode=777 mybucket /mnt/bucket 

Since I am supplying mount command with the -o key_file=path/to/key.json option the bucket that is mounted on /mnt/bucket folder can be accessed with the full access permissions (users can read, write, create, delete files and folders stored on Bucket).

But the same command does not run properly if put inside of /etc/fstab file which is supposed to be executed at the time the machine boots. Here is the syntax as it was put inside of /etc/fstab file (the same command just no sudo and mount at the beginning):

-t gcsfuse -o key_file=/keys/key.json -o rw -o allow_other -o file_mode=777 -o dir_mode=777 mybucket /mnt/bucket 

Solution

  • The format of a line in /etc/fstab is:

    <device> <mount-point> <filesystem-type> <comma-separated-options> <dump=0|1> <fsck=0|1>
    

    You need to rearrange the mount command you have. -t is the filesystem type. -o are the options. mybucket is the device. /mnt/bucket is the mount point. End result, add this line to /etc/fstab:

    mybucket /mnt/bucket gcsfuse key_file=/keys/key.json,rw,allow_other,file_mode=777,dir_mode=777 0 0