Using a dedicated Hard Drive

From ZoneMinder Wiki
Jump to: navigation, search

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:

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


mkdir /newdrive/zoneminder/events

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/ 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.


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.