Mount file system nfs linux

Как смонтировать общий ресурс NFS в Linux

Сетевая файловая система (NFS) — это протокол распределенной файловой системы, который позволяет вам обмениваться удаленными каталогами по сети. С помощью NFS вы можете монтировать удаленные каталоги в своей системе и работать с удаленными файлами, как если бы они были локальными файлами.

В операционных системах Linux и UNIX вы можете использовать команду mount для монтирования общего каталога NFS в определенной точке монтирования в локальном дереве каталогов.

В этом руководстве мы покажем вам, как вручную и автоматически смонтировать общий ресурс NFS на машинах Linux.

Установка клиентских пакетов NFS

Чтобы смонтировать общий ресурс NFS в системе Linux, сначала необходимо установить клиентский пакет NFS. Название пакета отличается в разных дистрибутивах Linux.

    Установка клиента NFS в Ubuntu и Debian:

sudo apt update sudo apt install nfs-common
sudo yum install nfs-utils

Монтирование файловых систем NFS вручную

Подключение удаленного общего ресурса NFS аналогично монтированию обычных файловых систем.

Чтобы смонтировать файловую систему NFS в заданной точке монтирования, используйте команду mount в следующей форме:

mount [OPTION. ] NFS_SERVER:EXPORTED_DIRECTORY MOUNT_POINT 

Выполните следующие действия, чтобы вручную смонтировать удаленный общий ресурс NFS в вашей системе Linux:

    Сначала создайте каталог, который будет точкой монтирования для удаленного общего ресурса NFS:

sudo mount -t nfs 10.10.0.10:/backups /var/backups

После монтирования общего ресурса точка монтирования становится корневым каталогом смонтированной файловой системы.

Когда вы монтируете общий ресурс вручную, подключение общего ресурса NFS не сохраняется после перезагрузки.

Автоматическое монтирование файловых систем NFS с помощью /etc/fstab

Как правило, вы хотите автоматически монтировать удаленный каталог NFS при загрузке системы.

Файл /etc/fstab содержит список записей, определяющих, где, как и какая файловая система будет монтироваться при запуске системы.

Чтобы автоматически монтировать общий ресурс NFS при запуске системы Linux, добавьте строку в файл /etc/fstab . Строка должна включать имя хоста или IP-адрес сервера NFS, экспортированный каталог и точку монтирования на локальном компьютере.

Используйте следующую процедуру для автоматического монтирования общего ресурса NFS в системах Linux:

    Настройте точку монтирования для удаленного общего ресурса NFS:

#     10.10.0.10:/backups /var/backups nfs defaults 0 0
mount /var/backups mount 10.10.0.10:/backups

Размонтирование файловых систем NFS

Команда umount отсоединяет (размонтирует) смонтированную файловую систему от дерева каталогов.

Чтобы отсоединить смонтированный общий ресурс NFS, используйте команду umount за которой следует либо каталог, в котором он был смонтирован, либо удаленный общий ресурс:

umount 10.10.0.10:/backups umount /var/backups

Если для монтирования NFS есть запись в fstab , удалите ее.

Команда umount не сможет отсоединить общий ресурс, когда смонтированный том используется. Чтобы узнать, какие процессы обращаются к общему ресурсу NFS, используйте команду fuser :

Как только вы найдете процессы, вы можете остановить их с помощью команды kill и отключить общий ресурс NFS.

Если у вас все еще есть проблемы с —lazy ресурса, используйте параметр -l ( —lazy ), который позволяет вам отключать загруженную файловую систему, как только она больше не занята.

Если удаленная система NFS недоступна, используйте параметр -f ( —force ) для принудительного размонтирования.

Как правило, не рекомендуется использовать опцию принудительного выполнения, так как это может повредить данные в файловой системе.

Выводы

Мы показали вам, как подключать и отключать удаленный общий ресурс NFS. Те же команды применимы для любого дистрибутива Linux, включая Ubuntu, CentOS, RHEL, Debian и Linux Mint.

Не стесняйтесь оставлять комментарии, если у вас есть вопросы.

Источник

How to Mount NFS File System in Ubuntu 20.04

The network file system NFS enables you to share files and directories among systems in a network. NFS is based on client-server architecture; the NFS server shares the specific directories which client can connect and access by mounting them locally. With NFS, the mounted directory appears as if it resides on your local system. NFS is still the most used way of sharing files between Linux systems.In Linux OS, you can easily mount an NFS shared directory on your local system using the mount command. The mount command mounts the file system temporarily. Once the system has been restarted, you will have to mount it again to access it. However, if you want to mount the file system permanently so that you do not have to mount it every time you boot the system, you will need to add an entry in the /etc/fstab file.

In this article, we will explain how to manually and automatically mount the NFS file system on the local system.

Pre-requisites

Before you move ahead, make sure the following pre-requisites are completed on the remote server.

  • NFS server is installed on the remote machine
  • NFS Service is running
  • NFS shared directory is exported
  • A firewall is not blocking access to client IP

We have performed the procedure mentioned in this article on the Ubuntu 20.04 system. Moreover, we have used the command line Terminal application for running the commands in Ubuntu. To open the Terminal, you can use the Ctrl+Alt+T keyboard shortcut.

Installing NFS Client Packages

To mount the NFS shared directory on your local client system, you will require the NFS client package. First, update the system repository index using the following command in Terminal:

Then install the NFS client package in your client machine using the following command in Terminal:

Mounting an NFS File System Manually

In the following method, we will mount the NFS directory manually using the mount command.

Step 1: Create a mount point for the NFS server’s shared directory

Our first step will be to create a mount point directory in the client’s system. This will be the directory where all the shared files from the NFS server can be accessed.

We have created a mount point directory with the name “client_sharedfolder” under the /mnt directory.

Step 2: Mount the NFS server shared directory on the client

The next step is to mount the shared directory on the NFS server to the client’s mount point directory. Use the following syntax to mount the NFS server shared directory to the mount point directory in the client:

  • NFS_IP is the NFS server’s IP address
  • NFS_export is the shared directory on the NFS server
  • Local_mountpoint is the mount point directory on the client’s system

In our example, the command would be:

Where 192.168.72.136 is our NFS server IP, /mnt/sharedfolder is the shared directory on the NFS server, and /mnt/sharedfolder is the mount point on the client system.

Once you have mounted the NFS share, you can confirm it using the following command:

Step 3: Test NFS share

After you have mounted the NFS shared directory on the client machine, test it by accessing some files from the NFS server. On the NFS server machine, create any test file or directory and try accessing it from the client machine.

Use the cd command to navigate to the NFS server’s shared directory:

Then using the touch or mkdir command, create a test file or directory. We have created some sample files named “testfile1” and “testfile2”.

Now on the client’s machine, verify if the same files exist.

The mount command mounts the NFS file system temporarily on the client system. Every time you reboot the system, you will have to manually mount it. In the next step, we will see how to make the NFS file system mount automatically at boot time.

Mounting an NFS File System automatically

In the following method, we will set up the NFS file system to automatically mount at boot time. Using this way, you will not have to mount the file system manually every time you boot your system.

Edit the /etc/fstab file using the following command:

Then add an entry in /etc/fstab file using the following format.

NFS server:directory mountpoint nfs defaults 0 0

Where the NFS server: directory is the NFS server IP and its shared directory, the mount point is the mount point on the client’s machine where the NFS directory is mounted, and the nfs defines the file system type.

In our example, the entry would be:

Where 192.168.72.136 is our NFS server IP, /mnt/sharedfolder is the shared directory on the NFS server, and /mnt/client_sharedfolder is the mount point on the client system.

Once you have added the above entry in the /etc/fstab file, save, and close the file. Use the Ctrl+O and then Ctrl+X to do so.

Next time you start your machine the NFS share will be automatically mounted at the specified mount point.

Unmounting the NFS File Systems

You can unmount an NFS file system from your local system at any time. Type the umount command followed by the mount point name where it is mounted.

Note: The command is “umount” not unmount.

In our example, it would be:

However, remember that, if the NFS file system has been mounted using the /etc/fstab, it will be again mounted next time you boot your system. Also note that the file system will not be unmounted if it is busy like if there are some files opened on it, or you are working on some directory.

That is all there is to it! In this article, you have explained how to mount the NFS shared directory on the Ubuntu 20.04 system both manually and automatically. In the end, we have also explained how to unmount the NFS shared directory when you no longer need it.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

Читайте также:  No buffer space available on linux
Оцените статью
Adblock
detector