Using a dedicated Hard Drive
With ZM, you may want to use a 2nd HDD dedicated for videos only, with no OS or db files on it.
ZoneMinder 1.31 or Newer
Please follow the steps shown on our readthedocs site: http://zoneminder.readthedocs.io/en/latest/installationguide/dedicateddrive.html
Web Console Instructions
Here is a guide for users with 1.32.3 or newer, to add a storage device to ZM via the web portal.
1. From the console, navigate to options.
2. In options, navigate to storage.
3. Choose Add New Storage.
4. Configure paths appropriately. Here I have an external ext4 filesystem SSD which is mounted at /video/. For those curious, the scheme refers to how the files are named as they are saved in the directory. In old versions of ZM, there were a number of sub directories, (e.g. month 11 would be directory 11, day 30 would be directory 30 in folder 11, for 11/30, and so on, for year, day, hour, etc..). This option is kept for backwards compatibility, but also a newer simpler scheme is available. The default is medium and that will suffice for most.
5. After that is added and saved, return to the console. Click source tab to configure where the camera stores video. Here we have the option of configuring where each camera can store its videos. This means you can have multiple HDDs, with multiple cameras, and split the storage across as many or as few HDDs as you wish. Camera 1 can record to HDD1, and Camera 2 can record to HDD2. Or you can have both Camera 1 and 2 on HDD1.
6. In the source of each camera, configure where you want to save the videos.
7. Make sure permissions are set correctly. The folder must allocate write and read permissions to www-data (debian) or apache (rhel). See the picture above for details. Note that some filesystems don't support all permissions, so it's recommended to use ext4, unless you know what you are doing.
8. We now need a filter, that will delete on our new storage area. Navigate to filters from the console.
9. Choose the PurgeWhenFull filter. Add storage area and the default will be equal to, which will work. Choose your new storage area from the drop down. You can test the filter now, by clicking on List Matches. Click save, to make the changes permenent.
zmfilter has a log file in /var/log/zm/zmfilter.log if you've enabled these log files, and it can be tailed to view the filter in action.
ZoneMinder 1.30.4 or Older
Note: Here is a reliable method to mount a drive or external share using systemd in Ubuntu or Debian: https://wiki.zoneminder.com/Common_Issues_with_Zoneminder_Installation_on_Ubuntu#Use_Systemd_to_Mount_Internal_Drive_or_NAS This can also be done in Centos or Red Hat distros...
On many installs you may wish to dedicate a hard drive or partition for Zoneminder events. There are many reasons why you may want to change the storage location - security, data segregation, preventing encroachment onto OS partition by zoneminder etc.
It's not terribly difficult to do, but may be non-obvious to the untaught so here's a brief guide.
Some commands here are based on Debian/Ubuntu installs
1. Become root or "sudo -s" to gain root privs.
2. Stop Zoneminder. "service zoneminder stop", "/usr/bin/zmpkg.pl stop", or "systemctl stop zoneminder"
3. Mount your new partition onto the root filesystem, ensuring it is automatically remounted at boot time by editing /etc/fstab -- For the benefit of this guide, I'm calling my new partition /newdrive
Note this new partition can be a local drive, raid partition, lvm/md device, external NAS, SAN, NFS share or SMB share. The only condition is that the I/O throughput should be up to handling what Zoneminder will throw at it. For that speed reason, some favour non-journalled filesystems and accept the extra risk of data corruption
4. Locate Zoneminder's "events" and "images" directories. In Debian and Ubuntu, these are under /var/cache/zoneminder. In CentOS and Fedora, these are under /var/lib/zoneminder.
If you wish to copy the data across, MOVE the events and images directories to /newdrive/zoneminder (Note this will take a long time on systems with many events). Also, DO NOT restart zoneminder until this entire process is completed. Doing so will cause all your events to be lost!
If you don't wish to preserve the data, it is MUCH faster to simply delete or rename the original events and images dirs and create new directories in /newdrive/zoneminder. There is no need to remove the "orphaned" entries in the database, zmaudit will take care of those.
mv /var/lib/zoneminder/events/* /var/lib/zoneminder/events_old/ -- or -- rm -rf /var/lib/zoneminder/events/
Add these lines in fstab to bind-mount an alternate location:
/dev/sdX1 /newdrive ext3 defaults 0 2 /newdrive/zoneminder/images /var/cache/zoneminder/images none defaults,bind 0 2 /newdrive/zoneminder/events /var/cache/zoneminder/events none defaults,bind 0 2
or in some cases,
/newdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind 0 2 /newdrive/zoneminder/events /var/lib/zoneminder/events none defaults,bind 0 2
or if you have a separate partition for each:
/dev/sdX1 /var/cache/zoneminder/images ext3 defaults 0 2 /dev/sdX2 /var/cache/zoneminder/events ext3 defaults 0 2
(Repeat for images)
5. Ensure ZoneMinder can write to the new destination by changing the owner and group to that of the web server user account. Debian based distros typically use "www-data" as the web server user account while many rpm based distros use "apache".
chown -R apache:apache /newdrive/zoneminder
You will also want to make sure the proper permissions are set in your /var folder, e.g. for debian
chown -R www-data:www-data /var/cache/zoneminder/
6. Finally, mount /newdrive and test your fstab entries ("mount -a"). Restart zoneminder ( "service zoneminder start", "/usr/bin/zmpkg.pl start", or "systemctl start zoneminder") Monitor its operation and ensure new events are being created normally and are viewable. Zoneminder should also update the "Disk: %%" on its Console screen to reflect the disk space on its new partition.
FREQUENTLY ASKED QUESTIONS
Question: Why can't I just symlink the newdrive to the events folder? Answer: Because it does not work in every case. Many rpm and deb packages need the file folders set up exactly the way they were when the first zoneminder package was installed. Changing that around can cause package upgrades to fail, or worse you could lose all your data!
Question: I noticed that there is an events folder under /usr/share/zoneminder/www, can I mount my dedicated hard drive or volume to that folder? Answer: This will not work in every case either and should be avoided. The events and images folders under /usr/share/zoneminder/www are actually symbolic links that point to the real folders under /var/lib/zoneminder (or /var/cache/zoneminder). Altering this in any way has the same affect as the answer to the first question.