Mounting an file as read-only in centos

Hello,
I am trying to mount an file in my Centos 7 server.
Here is my code:
syscall.Mount(src, dst, "auto", syscall.MS_BIND, "ro")
The issue is file is being mounted but not as read-only, it is mounting as read-write.

cat /etc/mtab | grep "firewall"
/dev/vda1 /root/firewall.txt ext4 rw,relatime,data=ordered,jqfmt=vfsv1,usrjquota=quota.user 0 0

I want to mount the file as read-only.

Anyone knows about it? How can we mount an file as read only in s Linux System ( CentOS ) ?

Hi @monsterlegend99, I’d like to help but I am a bit confused about “mounting a file”. I know I can mount a filesystem, but mounting a single file is new to me. (Although I can see that it works from your cat ouput.)

Does syscall.Mount() return any non-nill error?

From a Go point of view, did you try the package golang.org/x/sys/unix instead of syscall already?

The syscall package is deprecated and locked down, and maybe there is just a bug in syscall.Mount that has been fixed in unix.Mount already (just a wild guess).

Also, this SO thread indicates that “auto” does not work well with syscall.Mount. Maybe try passing “ext4” instead.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.