7

I do not know anything from storage and filesystems that's why i have created this question.

I want to mount the same disk to two linux machines and both machine must be able to read/write on the same disk at the same time.

From what i have been told that it not so easy because maybe the files will be corrupted if two different machines are accessing the same disk.

I want to understand what i have to use in order to mount the same disk on two machines and how SAN or NAS are fitting in on all this...

After some research i think in order to do this something like NFS or ACFS has to be used

Alexandros
  • 71
  • 1
  • 1
  • 3

3 Answers3

6

You can do that through NFS. Mount the disk to a machine and share that drive through NFS to the other machine.

Suppose the disk to be shared is /dev/sdb and the machines that you want to share the disk is machine1.example.com and machine2.example.com, then:

  1. Mount /dev/sdb in machine1 (You can skip this step if the said disk is already mounted and being used by machine1)

  2. Make the machine1 as the NFS server and export the directory on which /dev/sdb is mounted. Say, if /dev/sdb is mounted on /mnt/sharemount. The NFS export entries in /etc/exports should say:

    /mnt/sharemount machine2.example.com(rw,sync)

  3. Now that machine2 is allowed to use /mnt/sharemount from machine1 through NFS from step2, just mount /mnt/sharemount from machine1 on machine2

    mount machine1.example.com:/mnt/sharemount /mnt/sharemount

Data will not get corruped if these two machines start writing to the same location in /mnt/sharemount since the required locks will be applied and it will all happen transparent to you.

This answer is only an outline. If you are not familiar mounting a new disk to a server and with setting up NFS, please google how to configure nfs client and server linux. The search results will present you dozens of easy to follow tutorials and step-by-step guides. If you are comfortable using the command line(which I assume you are), you should be able to get the setup done with minimal time.

Sreeraj
  • 4,984
  • 10
  • 38
  • 57
4

If you share the storage as a file-share, no problems are to be expected. Think a CIFS (Samba) share or NFS from either the NAS appliance or from one server to another.

If you share the disk as a block device, i.e. an iSCSI or Fiber Channel LUN you'll need a cluster aware file-system on top of that to facilitate concurrent read-write operations from both systems.
The file-system needs to be cluster aware because in a normal file-system the locking is done in-memory by the kernel and one node would not be able to see which files are locked and being or have been modified on another node, resulting in file corruption.

The typical cluster file-system for Linux is the open source GFS2 or the commercial Veritas Cluster file-system.

HBruijn
  • 7,233
  • 23
  • 32
  • What is a block device? Is it something that only found in SAN ?? – Alexandros Dec 17 '14 at 11:55
  • 1
    At the most basic level storage appears as data [blocks](http://en.wikipedia.org/wiki/Block_(data_storage)) to your operating system. Spinning and solid state disks are also block devices, but you can use the same logic for using remote storage (it is effectively a disk on a longer wire). By addressing the remote storage as block device your server doesn't write files, only changed blocks, which can be efficient for large files, databases etc. Arguably the improvements in file-sharing protocols (e.g. [SMB 3](http://en.wikipedia.org/wiki/Server_Message_Block#SMB_3.0) ) make the SAN legacy tech. – HBruijn Dec 17 '14 at 12:28
  • 1
    Here's a list of other "cluster aware" file systems: https://en.wikipedia.org/wiki/Clustered_file_system#Examples – rogerdpack Aug 09 '18 at 21:41
0

You can easily achievethis via NFS

Make NFS Share which can be read/write for user, you can find the guide for the same here

Security Beast
  • 892
  • 7
  • 14