UniFi Video - How to Add a Network Volume to the NVR Appliance

2023-05-30 09:44:35 UTC

Overview

The following article takes the user through general steps to use additional file system space for the NVR appliance. This article is focused on setting up an iSCSI initiator (client) configured to use a remote storage device (iSCSI LUN target). Not included within this how-to guide are details for troubleshooting network access, file server permissions, nor setup errors.

WARNING:External storage is for advanced users only and requires systems' administration experience. This is not in our support scope and our agents will not be able to assist you. Perform these steps at your own risk.

Table of Contents

  1. Introduction on Storage
  2. Steps: How to Add a Network Volume to the NVR Appliance
  3. Housekeeping
  4. Related Articles

Introduction on Storage

Back to Top

Since video storage is bulky, if you need to store larger amounts of recordings, you'll need to set up external storage. There are 4 main types of external storage you can use:

    • Samba (Windows File Sharing). It won’t be covered at any point due to its limits in throughput compared to the rest.
    • NFS (Network File Sharing)
    • iSCSI (Internet Small Computer System Interface)
    • USB 3.0 (See related article: How to Add an External Hard Drive to the NVR)

Samba, NFS, and iSCSI are predominantly NAS based storage protocols whereas USB 3.0 would be used for a dedicated, individual storage unit. If ordered by speed: NFS is the fastest, then iSCSI, then USB 3.0, then Samba (protocol version dependent). However, depending on network and storage, these speeds may vary. See related articles below for information about alternative extra storage options.

Steps: How to Add a Network Volume to the NVR Appliance

Back to Top

1. Use SSH to login to the NVR appliance for CLI access. The default password is ubnt.

ssh root@ip.address.of.nvr

2. Install the iSCSI initiator package.

# apt-get update ; apt-get install open-iscsi

3. Update /etc/iscsi/iscid.conf to auto-start the initiator upon system reboot.

# vi /etc/iscsi/iscsid.conf

Change the following:

# To manually startup the session set to "manual". The default is manual.
#node.startup = manual
node.startup = automatic

4. Restart the open-iscsi initiator.

# /etc/init.d/open-iscsi restart
[....] Unmounting iscsi-backed filesystems: Unmounting all devices marked _netde[.ok
[ ok ] Disconnecting iSCSI targets:.
[ ok ] Stopping iSCSI initiator service:.
[ ok ] Starting iSCSI initiator service: iscsid.
[....] Setting up iSCSI targets:
iscsiadm: No records found
. ok
[ ok ] Mounting network filesystems:.

5. Create a mount point for the network volume.

# cd /srv
# mkdir /srv/synology
# chown airvision:airvision ./synology # <- For airVision
# chown unifi-video:unifi-video ./synology # <- For UniFi-Video
# ls -l
/srv
total 32
drwxr-xr-x 5 root root 4096 Jan 29 21:30 .
drwxr-xr-x 33 root root 4096 Jan 13 20:11 ..
drwx------ 2 root root 16384 Aug 12 21:07 lost+found
drwxr-xr-x 2 airvision airvision 4096 Jan 29 21:30 synology # <- Proper output for airVision
drwxr-xr-x 2 unifi-video unifi-video 4096 Jan 29 21:30 synology # <- Proper output for UniFi-Video

6. Setup an iSCSI LUN. The following is based on Synology:

  1. Log in to the Synology DSM admin console: http://<NAS_IP>:5000/
  2. Open the storage manager dialog
  3. Click the iSCSI LUN tab
  4. Create a LUN (skipping details here)
  5. Click the iSCSI Target tab to confirm Service Status is Ready

7. Confirm the remote iSCSI target is discoverable by the NVR appliance. For example:

# iscsiadm -m discovery -t st -p <NAS_IP>:3260
<NAS_IP>:3260,0 iqn.2000-01.com.synology:av-office-nas.demo

Where, port 3260 is the registered port for iSCSI or Internet SCSI, and used to contact the Synology NAS at its assigned IP address.

8. Connect to the iSCSI target.

# iscsiadm -m node --targetname "iqn.2000-01.com.synology:av-office-nas.demo" --portal "<NAS_IP>:3260" --login
Logging in to [iface: default, target: iqn.2000-01.com.synology:av-office-nas.demo, portal: <NAS_IP>,3260] (multiple)
Login to [iface: default, target: iqn.2000-01.com.synology:av-office-nas.demo, portal: <NAS_IP>,3260] successful.

9. List the current disks and partitions. For example (where /dev/sdb is a 1 TB iSCSI LUN):

# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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
Disk identifier: 0x000a0551
Device Boot Start End Blocks Id System
/dev/sda1 * 4096 1957887 976896 83 Linux
/dev/sda2 1957888 976773119 487407616 f W95 Ext'd (LBA)
/dev/sda5 1959936 9771007 3905536 82 Linux swap / Solaris
/dev/sda6 9773056 15624191 2925568 83 Linux
/dev/sda7 15626240 976773119 480573440 8e Linux LVM
Disk /dev/mapper/lvm-data0: 492.1 GB, 492105105408 bytes
255 heads, 63 sectors/track, 59828 cylinders, total 961142784 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
Disk identifier: 0x00000000
Disk /dev/mapper/lvm-data0 doesn't contain a valid partition table
Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 cylinders, total 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table

10. Create a partition.

parted /dev/sdb
(parted) mklabel gpt

The new partition is created by first establishing the units that will be working with either GB or TB, then establishing the beginning and end of the partition. Please take note that the second size here should be the max size of your drive, the 16GB below is the size used in the drive used for this example and is only shown as a sample output.  As such:

(parted) unit GB
(parted) mkpart primary 0.00GB 16.00GB

Then confirm everything looks correct by printing the partition table with print:

(parted) print
Model: Patriot Memory (scsi)
Disk /dev/sdb: 15.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
 1 0.00GB 15.8GB 15.8GB ext4 primary

Write these changes with quit, which should then drop you back to the regular shell.

11. Create a filesystem for the new partition.

# mke2fs /dev/sdb1

12. Mount the network volume.

# mount -t ext4 /dev/sdb1 /srv/synology
# chown airvision:airvision /srv/synology # <- For airVision
# chown unifi-video:unifi-video /srv/synology # <- For UniFi-Video

13. Update /etc/rc.local to preserve setup steps between reboots.

# vi /etc/rc.local

Add the following lines:

# Setup external iSCSI target after system reboot.
# For airVision
mount -t ext4 /dev/sdb1 /srv/synology
chown airvision:airvision /srv/synology

# For UniFi-Video:
mount -t ext4 /dev/sdb1 /srv/synology
chown unifi-video:unifi-video /srv/synology

14. Reboot the NVR appliance, log in using SSH, and confirm that the network volume is mounted.

# mount -l
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=503449,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=403780k,mode=755)
/dev/disk/by-label/boot on /boot type ext2 (ro,noatime,errors=continue,user_xattr,acl) [boot]
/dev/loop0 on /mnt/.rofs type squashfs (ro,relatime)
/dev/disk/by-label/user.0 on /mnt/.rwfs type ext4 (rw,noatime,data=ordered) [user.0]
aufs-root on / type aufs (rw,relatime,si=3a448c58db75ada3)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1588660k)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,nodiratime,size=807560k)
/dev/mapper/lvm-data0 on /srv type ext4 (rw,noatime,nodiratime,data=ordered) [data]
/dev/sdb1 on /srv/synology type ext4 (rw,relatime)
tmpfs on /srv/synology/videos/temp type tmpfs (rw,relatime,size=1048576k)

Also look at the end of the system log for kernel/driver messages:

# dmesg
...
[ 18.053611] Loading iSCSI transport class v2.0-870.
[ 18.076880] iscsi: registered transport (tcp)
[ 18.444836] scsi4 : iSCSI Initiator over TCP/IP
[ 18.702584] scsi 4:0:0:0: Direct-Access SYNOLOGY iSCSI Storage 3.1 PQ: 0 ANSI: 5
[ 18.702882] sd 4:0:0:0: Attached scsi generic sg1 type 0
[ 18.703817] sd 4:0:0:0: [sdb] 2147483648 512-byte logical blocks: (1.09 TB/1.00 TiB)
[ 18.705417] sd 4:0:0:0: [sdb] Write Protect is off
[ 18.705428] sd 4:0:0:0: [sdb] Mode Sense: 3b 00 00 00
[ 18.706113] sd 4:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 18.726016] sdb: sdb1
[ 18.737119] sd 4:0:0:0: [sdb] Attached SCSI disk
[ 21.424863] EXT4-fs (sdb1): mounted filesystem without journal. Opts: (null)

15. Log in to UniFi Video and click Settings > NVR Settings > Configure tab > Recording Path. Change the path accordingly (in this case to /srv/synology) and click Save.

NOTE:The videos sub-directory must be created and given the correct permissions on the newly created file system before changing the Recording Path in NVR Settings.

Housekeeping

Back to Top

If you used the internal hard drive of the NVR for recording, it's important that you're aware of the following information:

  • Space to Keep Free (Storage based purging): This applies to the current storage location only and cannot be disabled. It will purge the oldest recordings to keep xGB (default of 10GB) free on the storage partition specified at all times.  Note that if you're using an external drive or storage larger than 500GB total, you should set this to 5% of the overall storage of the drive (overall storage of the drive * 0.05).  Each filesystem has a specified "reserved file space" that is supposed to be kept empty so the filesystem can use this space for deleting, copying, moving, etc.
  • Time-Based Purging: This applies to all recordings regardless of their storage location and can be disabled/enabled (disabled by default). It will purge any recordings older than the time you specify.

If you used the internal hard drive for recording and have now switched to external storage, it is strongly recommended to use Time-Based Purging temporarily so the recordings that remain on the internal drive are properly purged.  Although you have moved the location of the recordings using this article to external storage, the database still uses the internal storage. Therefore, there need be ample storage on the internal drive at all times.

Related Articles

Back to Top

Intro to Networking - How to Establish a Connection Using SSH

UniFi Video - How to Enable SSH on the UVC-NVR (Hardware NVR)

UniFi Video - How to Add an External Hard Drive to the NVR Appliance or a Linux Install

Was this article helpful?
4 out of 8 found this helpful