Skip to content
Advertisement

Java program is unable to write on mounted system in linux

I am currently working a scenario where we have to create a file in a shared directory in Linux as well as Windows. I have gone through the following link to achieve it :

https://www.journaldev.com/878/java-write-to-file

https://it.toolbox.com/question/how-to-write-a-file-in-a-network-folder-without-using-ftp-031208

I was able to achieve it in windows network like giving the file name as (\198.168.1.1datafiles)

But for the Linux first I used NFS to share a particular directory using below links :

https://alvinsim.wordpress.com/2012/06/21/mounting-nfs-from-linux-to-aix/

https://www.tecmint.com/how-to-setup-nfs-server-in-linux/

But got the following exception :

java.io.FileNotFoundException: /data/files (Read-only file system)

I found the following issue resolved in following thread, but I could not succeed :

https://askubuntu.com/questions/197459/how-to-fix-sudo-unable-to-open-read-only-file-system

Any advice is appreciated.

Advertisement

Answer

So finally I was able to figure what the problem was.

The entry which I made as per link in /etc/exports file is not sufficient. We would need to use some options as well like (sync,rw,etc..) for allowing any manual modifications or modifications using any java program. In my case, I should have used the options (rw,no_root_squash). And it worked. As very well explained in :

https://serverfault.com/questions/611007/unable-to-write-to-mount-point-nfs-server-getting-permission-denied/611013#611013?newreg=ce76e9417ca645da9487a5d9ccbf0371

From Docs on : https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-nfs-server-config-exports

root_squash — Prevents root users connected remotely from having root privileges and assigns them the user ID for the user nfsnobody. This effectively “squashes” the power of the remote root user to the lowest local user, preventing unauthorized alteration of files on the remote server. Alternatively, the no_root_squash option turns off root squashing. To squash every remote user, including root, use the all_squash option.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement