# Connecting a NAS to Linux via iSCSI

If your **vCloud server** and **NAS storage** are on separate machines, the most reliable way to connect them is **iSCSI**.

iSCSI allows the NAS to present a disk over the network, and Linux sees it as a **local block device** (like `/dev/sdb`). This is ideal for video storage because it usually performs better than SMB/NFS for large sequential writes.

---

#### Architecture

```text
+-------------------+        iSCSI        +-------------------+
|   vCloud Server   | <-----------------> |        NAS        |
| Ubuntu Server     |                     | Synology/TrueNAS  |
| 192.168.1.10      |                     | 192.168.1.20      |
+-------------------+                     +-------------------+

```

---

#### **Step 1 — Prepare the NAS**

You need to configure the NAS and create an iSCSI LUN. To do this, refer to the user manual for your NAS server.

---

#### **Step 2 — Install iSCSI Client on Ubuntu**

On the **vCloud server**:

```bash
sudo apt update
sudo apt install open-iscsi -y
```

Enable the service:

```bash
sudo systemctl enable --now iscsid
```

---

#### **Step 3 — Discover the NAS Target**

Replace `192.168.1.20` with your NAS IP.

```bash
sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.20
```

You should see something like:

```bash
192.168.1.20:3260,1 iqn.2026-07.local.synology:vcloud-storage
```

---

#### **Step 4 — Configure Authentication (if CHAP is enabled)**

Edit the node configuration:

```bash
sudo nano /etc/iscsi/iscsid.conf
```

Find and set:

```bash
node.session.auth.authmethod = CHAP
node.session.auth.username = vcloud
node.session.auth.password = StrongPassword123
```

Save the file.

Restart the service:

```bash
sudo systemctl restart iscsid
```

---

#### **Step 5 — Log In to the iSCSI Target**

```bash
sudo iscsiadm -m node --login
```

Expected output:

```text
Login to [iface: default, target: iqn.2026-07.local.synology:vcloud-storage, portal: 192.168.1.20,3260] successful.
```

---

#### **Step 6 — Verify the New Disk**

List disks:

```bash
lsblk
```

Example:

```text
sda    1.8T
├─sda1
└─sda2
sdb   10.0T
```

The iSCSI disk is usually `sdb`.

---

#### **Step 7 — Create a Filesystem**

⚠️ **This will erase the iSCSI disk.**

```bash
sudo mkfs.ext4 /dev/sdb
```

---

#### **Step 8 — Create a Mount Point**

```bash
sudo mkdir -p /mnt/vcloud-storage
```

---

#### **Step 9 — Mount the Disk**

```bash
sudo mount /dev/sdb /mnt/vcloud-storage
```

Check:

```bash
df -h
```

Example:

```text
/dev/sdb        9.8T   24K  9.3T   1% /mnt/vcloud-storage
```

---

#### **Step 10 — Make the Mount Persistent**

Get the UUID:

```bash
sudo blkid /dev/sdb
```

Example:

```text
/dev/sdb: UUID="a1b2c3d4-e5f6-7890-abcd-1234567890ef"
```

Edit `/etc/fstab`:

```bash
sudo nano /etc/fstab
```

Add:

```fstab
UUID=a1b2c3d4-e5f6-7890-abcd-1234567890ef /mnt/vcloud-storage ext4 _netdev,nofail 0 2
```

Test:

```bash
sudo umount /mnt/vcloud-storage
sudo mount -a
```

If there are no errors, the configuration is correct.

---

#### **Step 11 — Ensure iSCSI Reconnects After Reboot**

Enable automatic login:

```bash
sudo iscsiadm -m node --op update -n node.startup -v automatic
```

Check:

```bash
sudo iscsiadm -m node
```

---

# Useful Commands

#### **Check iSCSI sessions**

```bash
sudo iscsiadm -m session
```

#### **Log out**

```bash
sudo iscsiadm -m node --logout
```

#### **Rediscover targets**

```bash
sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.20
```