Difference between revisions of "Using a dedicated Hard Drive"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 4: Line 4:


Some commands here are based on Debian/Ubuntu installs
Some commands here are based on Debian/Ubuntu installs


1. Become root or "sudo -s" to gain root privs.
1. Become root or "sudo -s" to gain root privs.


2. Stop Zoneminder.  "/etc/init.d/zoneminder stop" or "/usr/bin/zmpkg.pl stop"
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
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
Line 14: Line 13:
''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''  
''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, these are usually in /usr/share/zoneminder  
4. Locate Zoneminder's "events" and "images" directories. In Debian and Ubuntu, these are in /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 if it cannot locate these files as zmaudit.pl will delete the database entries for any events it cannot match files to''  
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 if it cannot locate these files as zmaudit.pl will delete the database entries for any events it cannot match files to''  


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 and link to them from the original locations. 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. There is no need to remove the "orphaned" entries in the database, zmaudit will take care of those.


Eg:  
Eg:  
Line 24: Line 23:
mkdir /newdrive/events
mkdir /newdrive/events


mv /usr/share/zoneminder/events /usr/share/zoneminder/events_old
mv /var/lib/zoneminder/events /var/lib/zoneminder/events_old


Note: It was recommended to use ''ln -s /newdrive/events /usr/share/zoneminder/events'' to link the new partition in. However, at least with the debian and ubuntu packages, upgrading zoneminder later will delete these symlinks and create new dirs. This will result in all your existing events being removed from the database.
Update: debian's upgrader will now (v.1.25) abort if it detects a symbolic link instead of silently deleting it.


It has been suggested this is used instead to mount the new drives;
Add these lines in fstab to bind-mount an alternate location:
 
''
these lines in fstab could allow you to bind-mount an alternate location:


  /dev/sdX1 /otherdrive ext3 defaults 0 2
  /dev/sdX1 /otherdrive ext3 defaults 0 2
Line 40: Line 34:
or in some cases,
or in some cases,


  /otherdrive/zoneminder/images /usr/share/zoneminder/images none defaults,bind  0 2
  /otherdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind  0 2
  /otherdrive/zoneminder/events /usr/share/zoneminder/events none defaults,bind 0 2
  /otherdrive/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 48: Line 42:
  /dev/sdX2 /var/cache/zoneminder/events ext3 defaults 0 2
  /dev/sdX2 /var/cache/zoneminder/events ext3 defaults 0 2
(Repeat for images)
(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".   
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".   
Line 54: Line 48:
  chown -R apache:apache /otherdrive/zoneminder
  chown -R apache:apache /otherdrive/zoneminder


6. Finally, restart zoneminder ( "/etc/init.d/zoneminder start" or "/usr/bin/zmpkg.pl start")  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, restart zoneminder ( "service zonemidner 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 newdrive 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.

Revision as of 19:24, 9 April 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 in /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 if it cannot locate these files as zmaudit.pl will delete the database entries for any events it cannot match files to

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.

Eg:

mkdir /newdrive/events

mv /var/lib/zoneminder/events /var/lib/zoneminder/events_old


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

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

or in some cases,

/otherdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind  0 2
/otherdrive/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 /otherdrive/zoneminder

6. Finally, restart zoneminder ( "service zonemidner 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 newdrive 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.