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

Overview

In this article users will learn how to use an external storage device with the UniFi Video hardware NVR appliance. Users can use the NVR's internal storage location or choose to use external storage; but not both.

ADVANCED: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.

Table of Contents

  1. Introduction
  2. Tools Needed
  3. Steps: How to Add an External Hard Drive to the NVR Appliance
  4. Housekeeping
  5. Troubleshooting
  6. Related Articles

Introduction

Back to Top

Video data consumes a lot of space, so if a lot of data must be retained, it is a good idea to add extra drive space to your NVR. This article describes how to add a physical drive to an NVR via USB. To add a network attached volume to an NVR, see this article: How to Add a Network Volume to the NVR Appliance.

NOTES:
  • Create a backup before following the steps below. Everything on the external USB storage drive will be wiped out with this process.
  • One of steps involves rebooting the NVR to ensure that the external storage drive mounts properly upon reboot. Take that into consideration if your system is mission critical, selecting a time that will not impact business.
  • For demonstration purposes, the example below uses a 16GB USB flash drive, but the process is the same regardless of the storage media.

Tools Needed

Back to Top

To complete this process, the following will be required:

  1. About 15 minutes of time.
  2. UVC-NVR or airVision-C powered up and plugged into the network. In the rest of this article, this will simply be referred to as "NVR".
  3. The IP address of the NVR.
  4. An SSH client.  For Linux and macOS users, this is built in natively into the Terminal application. For Windows users, please download an SSH client such as PuTTy.
  5. A USB external storage device, which is described in more detail below:

 There are 4 main types of external storage that may be used:

  • Samba (Windows File Sharing)
  • NFS (Network File Sharing)
  • iSCSI (Internet Small Computer System Interface)
  • USB 3.0

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 fasted, then iSCSI, then USB 3.0, then Samba (protocol version dependent). However, depending on network and storage, speeds will vary.

For best performance and longevity, we recommend using a USB 3.0 mechanical hard drive, as USB 1.1 is too slow, and USB 2.0 is only suitable for a couple of cameras.

The UVC-NVR/airVision-C comes equipped with 6 total USB ports; 2 USB 3.0 drives on the front of the unit and 4 USB 2.0 ports on the rear of the unit. Your USB 3.0 drive should be plugged into one of the two USB 3.0 ports on the front of the unit.

Because the NVR performs high bitrate transfers and a high number of read/write cycles, it is not recommended to use flash-based memory such as USB flash drives, Solid State Drives (SSDs), SD cards, microSD cards, etc.

Steps: How to Add an External Hard Drive to the NVR Appliance

Back to Top

1. Plug the external drive in to an appropriate USB port. The two USB 3.0 ports are located on the front of the unit.
2. SSH into the NVR. The default credentials are Username: root  / Password: ubnt

3. Find the drive designator.  Do this by issuing the following command:

fdisk -l

Sample Output:

root@UniFi-NVR:~# 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: 0x0008ce59

   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: 15.8 GB, 15846080512 bytes
255 heads, 63 sectors/track, 1926 cylinders, total 30949376 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: 0x2f08ac3c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1           16065    30941189    15462562+   f  W95 Ext'd (LBA)
/dev/sdb5           16128    30941189    15462531    7  HPFS/NTFS/exFAT

A few things of note with the same output above:

  • Note that the NVR is a Linux box and Linux drive designators always start with "/dev/sd" and usually go in alphabetical order. The first drive plugged in is /dev/sda, the second drive plugged in is /dev/sdb.
ATTENTION:Do not change /dev/sda in any way. That is where the operating system is stored. Editing /dev/sda may result in an unusable system.
  • After /dev/sdb there is a number, which designates the partition number. These are assigned in numerical order. This process will remove all partitions on the external drive and create only one.
  • In the above output, the target drive is /dev/sdb.
User Tip:Since we are using a 16GB external drive, 15.8GB is pretty close, so that's how I know that's my drive.

4. Edit the partitions of the drive by issuing:

parted /dev/sdb

5. Set the partition table to GPT with the following command, followed by typing "yes" to accept the warning that appears.

(parted) mklabel gpt

6. Create the new partition. First establish the units to be used: either GB or TB. Then establish the beginning and end of the partition.

NOTE:The second size below should be the max size of the drive used, 16GB is the size of the drive used in this article, and is shown as the sample output.
(parted) unit GB
(parted) mkpart primary 0.00GB 16.00GB
(parted)

7. Confirm everything is correct by printing the partition table with the print command:

(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

8. Finally, write these changes with quit, which will bring you back to the regular shell.
9. Create the filesystem:

mkfs.ext4 /dev/sdb1

 This step can be risky. All filesystems have a reserved amount of space for overhead. In this case, it's 5%. For 16GB, this isn't much and is probably necessary. But if using a 1TB+ drive, it's probably not necessary to keep 51GB+ reserved. If you like, you can reduce this reservation. Note that it is not recommended to go below 2%.

Reduce reservation by issuing the following command, where the number following the -m is the percentage to keep reserved.

tune2fs -m 2 /dev/sdb1

10. Create a mount point to mount the partition. For simplicity and to avoid confusion, name it something to show it is an external storage device and place it somewhere where it will not be confused with other storage. For this example, the name selected is /exthd. So:

mkdir /exthd

11. Mount the partition:

mount -t ext4 /dev/sdb1 /exthd

12. Make the mount occur at boot time. You may use vi to do this, but in this example nano will be installed and used for a simple, more notepad-like editor:

apt-get update; apt-get install nano

Then:

nano /etc/rc.local

Insert the mount command from step 11. The complete file should look like this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
mount -t ext4 /dev/sdb1 /exthd

exit 0

Ctrl+x to exit. When prompted to save, press y on the keyboard followed by enter.

13. Reboot the NVR:

reboot

14. When the system comes back up, SSH back in. Issue the mount command:

mount

Something like this will appear, signaling that the partition mounts on boot:

root@UniFi-NVR:~# mount
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=503334,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=403736k,mode=755)
/dev/disk/by-label/boot on /boot type ext2 (ro,noatime,errors=continue,user_xattr,acl)
/dev/loop0 on /mnt/.rofs type squashfs (ro,relatime)
/dev/disk/by-label/user.0 on /mnt/.rwfs type ext4 (rw,noatime,data=ordered)
aufs-root on / type aufs (rw,relatime,si=8458a27b1bc70b71)
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=1588560k)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,nodiratime,size=807468k)
/dev/mapper/lvm-data0 on /srv type ext4 (rw,noatime,nodiratime,data=ordered)
/dev/mapper/lvm-data0 on /var/lib/unifi type ext4 (rw,noatime,nodiratime,data=ordered)
/dev/mapper/lvm-data0 on /var/lib/mfi type ext4 (rw,noatime,nodiratime,data=ordered)
tmpfs on /var/cache/unifi-video type tmpfs (rw,noexec,noatime,nodiratime,size=524288k,mode=777,uid=104)
/dev/sdb1 on /exthd type ext4 (rw,relatime,data=ordered)

15. Change the permissions of the mount point of /exthd:

chown unifi-video:unifi-video /exthd

16. Log in to the UniFi Video web interface.
17. Go to Settings in the lower left hand corner.
18. Click the SYSTEM CONFIGURATION button.

system-config-button.png

19. Expand the CONFIGURE tab if it isn't already expanded.
20. Change Recording Path to /exthd.
21. Change Space To Keep Free to about 5% of the overall drive space.
22. Save these settings.
23. Keep an eye on the records in the web interface and/or the /exthd directory with the ls command, to ensure that there's data being stored there.

ls /exthd

Housekeeping

Back to Top

If the internal hard drive of the NVR was used for recording, it's important to consider the following:

  • 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 using an external drive or storage larger than 500GB total, this should be set 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 specified.

If the internal hard drive was used for recording, but now have 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 the location of the recordings was moved to external storage during the steps of this article, the database still uses the internal storage. Therefore, there need be ample storage on the internal drive at all times.

Troubleshooting

Back to Top

If the NVR experiences a power failure, it is a good idea to verify that the external drive is mounted properly when it boots back up. Follow these steps to do so:

1. Open an SSH connection to the NVR.

2. Issue the following commands hitting enter after each one:

service unifi-video stop

mount

The output will be something like this:

root@UniFi-NVR:~# mount
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=503334,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=403736k,mode=755)
/dev/disk/by-label/boot on /boot type ext2 (ro,noatime,errors=continue,user_xattr,acl)
/dev/loop0 on /mnt/.rofs type squashfs (ro,relatime)
/dev/disk/by-label/user.0 on /mnt/.rwfs type ext4 (rw,noatime,data=ordered)
aufs-root on / type aufs (rw,relatime,si=8458a27b1bc70b71)
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=1588560k)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,nodiratime,size=807468k)
/dev/mapper/lvm-data0 on /srv type ext4 (rw,noatime,nodiratime,data=ordered)
/dev/mapper/lvm-data0 on /var/lib/unifi type ext4 (rw,noatime,nodiratime,data=ordered)
/dev/mapper/lvm-data0 on /var/lib/mfi type ext4 (rw,noatime,nodiratime,data=ordered)
tmpfs on /var/cache/unifi-video type tmpfs (rw,noexec,noatime,nodiratime,size=524288k,mode=777,uid=104)
/dev/sdb1 on /exthd type ext4 (rw,relatime,data=ordered)

3. Issue the following command:

umount /dev/sdb1 (or run umount /exthd) **

NOTE: Even if the commands return with errors, continue. These commands make sure that the drive is not currently mounted.

4. Continue running these commands, hitting enter after each one: 

rm -rf /exthd/*

mount -t ext4 /dev/sdb1 /exthd

chown unifi-video:unifi-video /exthd

service unifi-video start

5. Now log in and check the recordings. They should begin writing again shortly.

Related Articles

Back to Top

Intro to Networking - How to Establish a Connection Using SSH

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

Was this article helpful?
17 out of 22 found this helpful