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


Overview


In this article, users will learn how to add an external storage device to the Ubiquiti hardware NVR appliance. 

NOTES:
  • 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. 
  • Please make sure to make a back up before following the steps below. You will lose everything on your external USB storage drive with this process.
  • One of these steps involves rebooting the NVR to ensure that the external storage drive mounts properly upon reboot. If your system is mission critical, it is recommended that you perform these steps during off-hours.
  • For demonstration purposes, the example below uses a 16GB USB flash drive, but the process is the same regardless of your storage media.

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. if you want to retain a lot of data, you’re going to want to add extra drive space to your NVR. This Article in particular deals with adding a physical drive to your nvr via USB. If you'd like to add a network attached volume to your NVR, check out our article, How to Add a Network Volume to the NVR Appliance.


Tools Needed


Back to Top

To complete this process, you will need:

  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 Mac users, this is built in natively into your Terminal application. For Windows users, you'll need to download an SSH client such as PuTTy.
  5. Your USB external storage device, which we will go into detail below.

 There are 4 main types of external storage you can use:

  • 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, these speeds may vary.

For best performance and longevity, we recommend using a USB 3.0 mechanical hard drive, as USB 1.1 is simply 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 your external drive in to an appropriate USB port. The two USB 3.0 ports are located on the front of the unit.
2. SSH in to the NVR. For Linux and Mac users using Terminal. For Windows users using PuTTy.  The default credentials are Username: root  Password: ubnt
3. Find your drive designator.  You can 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

Note that that 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, you will see a number. This designates the partition number. Again, these are assigned in order; in this case, numerical. This doesn't matter much because we're going to remove all partitions on the external drive and create only one.

In the above output, our target drive is /dev/sdb, which is most likely the same for your system.

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 that we're working with either GB or TB, then establish the beginning and end of the partition.

NOTE: The second size below should be the max size of your drive, 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. Then confirm everything looks 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, we write these changes with quit, which should then drop 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 very much so necessary. But if you're using a 1TB+ drive, it's probably not all that necessary to keep 51GB+ reserved. If you like, you can reduce this reservation. Note that we do not recommend going below 2%. If you choose to do this, you're doing so at your own risk and can do so by:

tune2fs -m 2 /dev/sdb1

The number following the -m is the percentage to keep reserved.

10. Now, create a mount point where we will be mounting our partition. For simplicity and to avoid confusion, we recommend naming it something indicative that it's an external storage device and putting it somewhere where it's not confusing. For demonstration purposes, we're going with /exthd. So:

mkdir /exthd

11. Mount the partition:

mount -t ext4 /dev/sdb1 /exthd

12. Make the mount occur at boot time. If you're familiar with Linux, you can use vi which is installed already, but we're going to install nano for a simple, more notepad-like editor:

apt-get update; apt-get install nano

Then:

nano /etc/rc.local

And insert your mount command from step 11, your whole 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, you'll be prompted to save, press y on your keyboard followed by enter on your keyboard.

13. Reboot the NVR:

reboot

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

mount

You should see 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)

That means that the partition mounts on boot.

15. Now change the permissions of the mount point of /exthd:

chown unifi-video:unifi-video /exthd

16. Log in to your UniFi-Video web interface.
17. Go to Settings in the lower left hand corner.
18. Click the NVR SETTINGS button in the upper left hand corner.


19. Expand the CONFIGURE tab if it isn't already.
20. Change your Recording Path to "/exthd" (without quotations).
21. Change your Space To Keep Free to about 5% of your overall drive space.
22. Save these settings.
23. Keep an eye on your 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

24. You're all done!


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.


Troubleshooting


Back to Top

If your NVR experiences a power failure, You'll want to make sure that your External drive is mounted properly when it boots back up. Follow these steps:

  1. Open an SSH connection to your NVR.
  2. Issue the following command:
    1. service unifi-video stop  
    2. mount. You should see something like this again:
      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. umount /dev/sdb1 (or run umount /exthd)
      NOTE: Even if those return with errors, continue. Those make sure that drive is not currently mounted.
    4.  rm -rf /exthd/*
    5. mount -t ext4 /dev/sdb1 /exthd
    6. chown unifi-video:unifi-video
    7. service unifi-video start 
  3. Now, Log in, and check your recordings. they should begin writing again shortly.

Related Articles


Back to Top

How to Establish a Connection Using SSH   

How to Add a Network Volume to the NVR Appliance