# NFS Server

### Structure

<div class="table-wrapper" id="bkmrk-name-maj%3Amin-rm-size"><table><tbody><tr><th colspan="1" rowspan="1">NAME</th><th colspan="1" rowspan="1">MAJ:MIN</th><th colspan="1" rowspan="1">RM</th><th colspan="1" rowspan="1">SIZE</th><th colspan="1" rowspan="1">RO</th><th colspan="1" rowspan="1">TYPE</th><th colspan="1" rowspan="1">MOUNTPOINTS</th></tr><tr><td colspan="1" rowspan="1">sdb</td><td colspan="1" rowspan="1">8:16</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">3.6T</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">disk</td><td colspan="1" rowspan="1"> </td></tr><tr><td colspan="1" rowspan="1">└─ hdds-datas</td><td colspan="1" rowspan="1">253:0</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">7.3T</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">lvm</td><td colspan="1" rowspan="1">/export/media</td></tr><tr><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1">/srv/dev-disk-by-uuid-a67ae390-f36c-4b7c-98a0-4a3b5601c107</td></tr><tr><td colspan="1" rowspan="1">sdc</td><td colspan="1" rowspan="1">8:32</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">3.6T</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">disk</td><td colspan="1" rowspan="1"> </td></tr><tr><td colspan="1" rowspan="1">└─ hdds-datas</td><td colspan="1" rowspan="1">253:0</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">7.3T</td><td colspan="1" rowspan="1">0</td><td colspan="1" rowspan="1">lvm</td><td colspan="1" rowspan="1">/export/media</td></tr><tr><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1"> </td><td colspan="1" rowspan="1">/srv/dev-disk-by-uuid-a67ae390-f36c-4b7c-98a0-4a3b5601c107</td></tr></tbody></table>

</div>```bash
apt install -y lvm2
```

### Disks

```bash
fdisk -l
```

```
Disk /dev/sdb: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ST4000VN006-3CW1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdc: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ST4000VN006-3CW1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/hdds-datas: 7.28 TiB, 8001566015488 bytes, 15628058624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
```

### LVM

#### Physical Volumes (partitions)

```
pvcreate /dev/sdb
pvcreate /dev/sdc
```

#### Volume Group

```
vgcreate hdds /dev/sdb /dev/sdc
```

#### Logical Volume(s)

```
lvcreate --extents 100%FREE -n datas hdds
```

```
pvdisplay 
```

```
--- Physical volume ---
PV Name               /dev/sdb
VG Name               hdds
PV Size               <3.64 TiB / not usable <3.84 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              953861
Free PE               0
Allocated PE          953861
PV UUID               zHiPKx-t2BO-15r3-xPfQ-DPlB-7K40-YxIdM1

--- Physical volume ---
PV Name               /dev/sdc
VG Name               hdds
PV Size               <3.64 TiB / not usable <3.84 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              953861
Free PE               0
Allocated PE          953861
PV UUID               bGAdMs-JsRy-6r3M-0zWt-CYQJ-GPsB-KCnCo6
```

```bash
vgdisplay
```

```
--- Volume group ---
VG Name               hdds
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  6
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                2
Act PV                2
VG Size               <7.28 TiB
PE Size               4.00 MiB
Total PE              1907722
Alloc PE / Size       1907722 / <7.28 TiB
Free  PE / Size       0 / 0
VG UUID               DPZPo2-OwJt-R1wG-wJRB-HD38-JeVl-5ZFfnI
```

```
lvdisplay
```

```
--- Logical volume ---
LV Path                /dev/hdds/datas
LV Name                data
VG Name                hdds
LV UUID                qgdjwr-9Aau-p4mj-rksl-IeBB-SjD1-z6hede
LV Write Access        read/write
LV Creation host, time polito, 2023-08-01 10:10:14 +0200
LV Status              available
# open                 0
LV Size                <7.28 TiB
Current LE             1907722
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           254:0
```

#### Format LV
```bash
sudo mkfs.ext4 /dev/hdds/datas
```

### NFS
```
# mkdir -p /mnt/data/cloud
# mkdir -p /mnt/data/gitea
# mkdir -p /mnt/data/jellystack
# mkdir -p /mnt/data/media

sudo vim /etc/exports
```

```
# /etc/exports: the access control list for filesystems which may be exported to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
# /export 192.168.1.0/24(rw,no_root_squash,no_subtree_check)
/export/cloud      192.168.1.0/24(rw,sync,no_root_squash,subtree_check,insecure)
/export/gitea      192.168.1.0/24(rw,sync,no_root_squash,subtree_check,insecure)
/export/jellystack 192.168.1.0/24(rw,sync,no_root_squash,subtree_check,insecure)
/export/media      192.168.1.0/24(rw,sync,no_root_squash,subtree_check,insecure)
```

```bash
sudo systemctl restart nfs-server
```

##### Get LVM's UUID

```bash
sudo blkid -s UUID -o value /dev/mapper/hdds-datas
```

##### Mount LVM

```
sudo vim /etc/fstab
```

```
# LVM
UUID=0c390345-ca52-45fd-9097-6e931d651a8f       /       ext4    defaults,x-systemd.growfs       0       1
# LVM
/dev/hdds/datas         /mnt/data               ext4    defaults,nofail,user_xattr,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0,acl 0 2
# NFS exports
/mnt/data/cloud         /srv/nfs4/cloud         none    bind,nofail     0 0
/mnt/data/media         /srv/nfs4/media         none    bind,nofail     0 0
/mnt/data/ebooks        /srv/nfs4/ebooks        none    bind,nofail     0 0
/mnt/data/git           /srv/nfs4/git           none    bind,nofail     0 0
/mnt/data/photos        /srv/nfs4/photos        none    bind,nofail     0 0
/mnt/data/downloads     /srv/nfs4/downloads     none    bind,nofail     0 0
/opt/backups            /srv/nfs4/backups       none    bind,nofail     0 0
```

**PS : Check the content of /var/lib/nfs/etab to show NFS shares list and all the applied permission details**

```bash
cat /var/lib/nfs/etab
```

```shell
/srv/nfs4           192.168.1.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)
/srv/nfs4/cloud     192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/media     192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/ebooks    192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/git       192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/photos    192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/downloads 192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)
/srv/nfs4/backups   192.168.1.0/24(ro,sync,no_subtree_check)
```

#### Client(s)

```bash
sudo apt install nfs-common -y

sudo mkdir -p /nfs/jellystack
sudo mkdir -p /nfs/cloud
sudo mkdir -p /nfs/gitea
sudo mkdir -p /nfs/media

sudo vim /etc/fstab
```

```shell
krabs:/srv/nfs4/cloud   /nfs/media  nfs  _netdev,x-systemd.automount,noauto,nofail,noatime,nolock,tcp,bg,actimeo=1800   0      0
krabs:/srv/nfs4/git     /nfs/git    nfs  _netdev,x-systemd.automount,noauto,nofail,noatime,nolock,tcp,bg,actimeo=1800   0      0
krabs:/srv/nfs4/media   /nfs/media  nfs  _netdev,x-systemd.automount,noauto,nofail,noatime,nolock,tcp,bg,actimeo=1800   0      0
krabs:/srv/nfs4/ebooks  /nfs/ebooks nfs  _netdev,x-systemd.automount,noauto,nofail,noatime,nolock,tcp,bg,actimeo=1800   0      0
```

```bash
sudo mount /nfs/cloud
sudo mount /nfs/gitea
sudo mount /nfs/jellystack
sudo mount /nfs/media

sudo systemctl daemon-reload
```
