Difference between revisions of "Using a dedicated Hard Drive"

From ZoneMinder Wiki
Jump to navigationJump to search
m (changed "otherdrive" to "newdrive" for consistency. clarified subfolder structure. added mount -a prior to restart)
Line 15: Line 15:
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.  
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  ''(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 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. There is no need to remove the "orphaned" entries in the database, zmaudit will take care of those.
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.


Eg:  
Eg:  


mkdir /newdrive/events
mkdir /newdrive/zoneminder/events


mv /var/lib/zoneminder/events /var/lib/zoneminder/events_old
mv /var/lib/zoneminder/events/* /var/lib/zoneminder/events_old/
-- or --
-- or --
rm -rf /var/lib/zoneminder/events
rm -rf /var/lib/zoneminder/events/


Add these lines in fstab to bind-mount an alternate location:
Add these lines in fstab to bind-mount an alternate location:


  /dev/sdX1 /otherdrive ext3 defaults 0 2
  /dev/sdX1 /newdrive ext3 defaults 0 2
  /otherdrive/zoneminder/images /var/cache/zoneminder/images none defaults,bind  0 2
  /newdrive/zoneminder/images /var/cache/zoneminder/images none defaults,bind  0 2
  /otherdrive/zoneminder/events /var/cache/zoneminder/events none defaults,bind 0 2
  /newdrive/zoneminder/events /var/cache/zoneminder/events none defaults,bind 0 2


or in some cases,
or in some cases,


  /otherdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind  0 2
  /newdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind  0 2
  /otherdrive/zoneminder/events /var/lib/zoneminder/events 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:
or if you have a separate partition for each:
Line 47: Line 47:
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".   
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 /otherdrive/zoneminder
  chown -R apache:apache /newdrive/zoneminder


6. Finally, 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.
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
FREQUENTLY ASKED QUESTIONS

Revision as of 08:26, 22 October 2015

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 protection

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.

Eg:

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

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.