Types of Storage in Linux

Block Storage stores data in Storage Area Networks (SAN) or cloud platforms. Block storage breaks data into blocks in separate pieces with unique identifiers and stores them wherever they are efficient. This means that these blocks can be configured to work with different operating systems.

Object Storage breaks data files into units called objects and keeps them in a single repository that can be spread out over multiple distributed systems. The objects have unique identifiers and the metadata that describes the data that can contain simple to complex details.

File Storage stores data as a single piece of information inside a folder. Access to the data is restrained to the system knowing the path of the stored data which makes it also known as hierarchical storage. File storage operates with file-level protocols like Network File System (NFS) for Linux and New Technology File System (NTFS) for Windows.

Network File System (NFS)

NFS is a client/server application that lets users store data and manipulate files in a remote computer as though they were on their local computer. It uses the NFS protocol that is used to share files on a network.

There are currently 3 versions of NFS,

  • NFSv2 is the oldest and widely supported.
  • NFSv3 is more common and has more features like 64bit file handles which makes an average use of 2GB of content to access.
  • NFSv4 is the latest and can work over the internet and through firewalls.

The benefits of using NFS are many which include

  • Many users can access the same file over a distributed system
  • Multiple computers can share the same applications reducing disk space.
  • Mounting the file system is transparent

There are services required to make NFS work.

  • nfs which is the service that starts the server and RPC processes.
  • nfslock that starts the appropriate RPC process that allows users to lock files
  • portmap that accepts port reservations from RPC services which states that certain ports are available for file access.

This guide will show you how to install the NFS server on KDE Neon|Kubuntu system.

Installation of NFS Server on KDE Neon / Kubuntu

First, update your system packages using the following commands.

### KDE Neon ###
sudo apt update && sudo pkcon update -y

### Kubuntu ###
sudo apt update &&& sudo apt upgrade -y

Next, install the nfs-kernel-server using the following command

sudo apt install nfs-kernel-server

Check its status using the following command.

$ systemctl status nfs-kernel-server
● nfs-server.service - NFS server and services
     Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
     Active: active (exited) since Wed 2022-04-13 17:52:10 EAT; 39s ago
   Main PID: 52264 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 4572)
     Memory: 0B
     CGroup: /system.slice/nfs-server.service

Apr 13 17:52:09 kdeneon systemd[1]: Starting NFS server and services...
Apr 13 17:52:10 kdeneon systemd[1]: Finished NFS server and services.

If it is not active, use the following command to enable it on boot time.

$ sudo systemctl enable nfs-kernel-server
Synchronizing state of nfs-kernel-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nfs-kernel-server

Create the directory for storing the files

sudo mkdir -p /mnt/server_nfsshare

Then remove permissions to allow clients to access the data.

sudo chown -R nobody:nogroup /mnt/server_nfsshare/

Configure NFS exports on KDE Neon / Kubuntu host

To configure the directory to share data remotely, Edit the exports file.

sudo nano /etc/exports

Then edit with your actual client IP address or CIDR block.

/mnt/server_nfsshare  192.168.200.0/24(rw,sync,no_subtree_check)

## Single IP ###
/mnt/server_nfsshare  192.168.200.24/24(rw,sync,no_subtree_check)

If you want to add multiple clients, add each client on a separate line.

/mnt/server_nfsshare  client_IP_1 (rw,sync,no_subtree_check)
/mnt/server_nfsshare  client_IP_2 (rw,sync,no_subtree_check)

rw ensures clients have read-write permissions.
sync allows data to sync with the host server.
no_subtree_checks disables the tree checks.

Export the shares and restart the NFS server using the following commands.

sudo exportfs -ar
sudo systemctl restart nfs-kernel-server

Adjust the firewall to allow communication from the client by using the actual client IP address.

sudo ufw allow from 192.168.200.0/24 to any port nfs
Rules updated

Then enable the firewall and check the status using the following commands.

$ sudo ufw enable
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
2049                       ALLOW       192.168.200.57

Install the NFS Client package on the Client Machine

Use the following commands to install the NFS client

### Ubuntu / Debian ###
sudo apt update
sudo apt install nfs-common

### CentOS / RHEL ###
sudo yum -y install nfs-utils

Manually mount NFS file system

Create a directory for the mount point where the NFS share will be mounted.

sudo mkdir -p /mnt/client_nfsshare

Mount NFS shares on the client system using the server’s IP address.

sudo mount 192.168.200.36:/mnt/server_nfsshare  /mnt/client_nfsshare

To check, use

$ df -h
Filesystem                           Size  Used Avail Use% Mounted on
192.168.200.36:/mnt/server_nfsshare   51G   12G   37G  25% /mnt/client_nfsshare

Automatically mount NFS file system with /etc/fstab

There is another way to automatically mount the NFS file with /etc/fstab. It is a file that contains a list of entries of where and how file systems will be mounted on startup.

Create a directory for the mount point where the NFS share will be mounted.

sudo mkdir -p /mnt/client_nfsshare

Open the /etc/fstab file with a text editor.

sudo nano /etc/fstab

Then add the following line containing the NFS server IP address, the exported directory, and the local mount point.

# <file system>              <dir>                       <type>   <options>   <dump>	<pass>
192.168.200.36:/mnt/server_nfsshare /mnt/client_nfsshare  nfs      defaults     0          0

Save and close the file. Then run the mount command using either of the commands to mount the NFS share.

sudo mount /mnt/client_nfsshare
sudo mount 192.168.200.36:/mnt/server_nfsshare

Testing NFS Access on KDE Neon / Kubuntu

Create some files on the server machine remote folder using the following commands.

cd /mnt/server_nfsshare/
touch file1.txt file2.txt

Then go back to the client machine and list down the details in the shared folder.

$ ls -l /mnt/client_nfsshare/
total 0
-rw-r--r-- 1 root root 0 Elb 13 18:10 file1.txt
-rw-r--r-- 1 root root 0 Elb 13 18:10 file2.txt

This shows your NFS setup is working correctly.

Conclusion

From this guide, we have gone through installing the NFS server package on the KDE Neon system and installing the NFS client package on the Kubuntu system. We have created the server and client shared folder and then mounted them on their respective systems which can be done manually or automatically using /etc/fstab file.. The test was successful and that’s just about it in installing the NFS server.

Read more guides available in our website.

LEAVE A REPLY

Please enter your comment!
Please enter your name here