From Hack Sphere Labs Wiki
Jump to: navigation, search


Clear Events

cd /var/cache/zoneminder/events/
rm -rf *

Debian Squeeze

  • Enable Backports
nano /etc/apt/sources.list


deb squeeze-backports main contrib non-free

Install other stuff:

apt-get install libfaac-dev
apt-get install libmp3lame-dev
apt-get install libogg-dev
apt-get install libjpeg-dev
apt-get install libtheora-dev
apt-get install libvorbis-dev
apt-get install libx264-dev
apt-get -t squeeze-backports install libxvidcore-dev

Install Zoneminder:

apt-get install zoneminder
ln -s /etc/zm/apache.conf    /etc/apache2/conf.d/zoneminder.conf
/etc/init.d/apache2 restart

  • zmwatch[22830]: ERR [Can't get shared memory id '7a6d0002', 2: No such file or directory]

Make shared memory key work:

Test it:

echo 167772160 >/proc/sys/kernel/shmall
echo 167772160 >/proc/sys/kernel/shmmax

Restart Zoneminder

/etc/init.d/zoneminder stop

Make it perm

nano /etc/sysctl.conf
# Increase the maximum shared memory
kernel.shmall = 167772160
kernel.shmmax = 167772160

/etc/init.d/zoneminder start

libjpeg turbo

You can use libjpeg-turbo to speed things up. This is worth it. I had a system at like 6.0 load and now it is at .10 Plus they just released a new version of libjpeg turbo.

root@hslmonitor:~# locate libjpeg

replace libjpeg with libjpeg-turbo (64bit)

dpkg --remove --force-depends libjpeg62
dpkg --remove --force-depends libjpeg62-dev
wget libjpeg-turbo 64bit deb file
mv (downloaded name) to libjpeg-turbo-official_1.3.0_amd64.deb or whatever
dpkg -i libjpeg-turbo-official_1.3.0_amd64.deb
ln -s /opt/libjpeg-turbo/lib/libjpeg.a /usr/lib/libjpeg.a && \
ln -s /opt/libjpeg-turbo/include/jconfig.h /usr/include/jconfig.h && \
ln -s /opt/libjpeg-turbo/include/jerror.h /usr/include/jerror.h && \
ln -s /opt/libjpeg-turbo/include/jmorecfg.h /usr/include/jmorecfg.h && \
ln -s /opt/libjpeg-turbo/include/jpeglib.h /usr/include/jpeglib.h

  • I used (64bit):
ln -s /opt/libjpeg-turbo/lib64/libjpeg.a /usr/lib/libjpeg.a && \
ln -s /opt/libjpeg-turbo/include/jconfig.h /usr/include/jconfig.h && \
ln -s /opt/libjpeg-turbo/include/jerror.h /usr/include/jerror.h && \
ln -s /opt/libjpeg-turbo/include/jmorecfg.h /usr/include/jmorecfg.h && \
ln -s /opt/libjpeg-turbo/include/jpeglib.h /usr/include/jpeglib.h
  • Taken from same link:
echo "/opt/libjpeg-turbo/lib" > /etc/ && \
echo "/usr/local/lib" > /etc/ && \
echo "LD_LIBRARY_PATH=/usr/local/lib:/opt/libjpeg-turbo/lib:$LD_LIBRARY_PATH" >> /etc/bash.bashrc && \
echo "export LD_LIBRARY_PATH" >> /etc/bash.bashrc
  • I used (just for turbo)
echo "/opt/libjpeg-turbo/lib64" > /etc/ && \
echo "LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib64:$LD_LIBRARY_PATH" >> /etc/bash.bashrc && \
echo "export LD_LIBRARY_PATH" >> /etc/bash.bashrc

Disable Corrupt JPEG Data

zmc_m3[12280]: WAR [Corrupt JPEG data: 1 extraneous bytes before marker 0xd9] 

Another way is just disable writing these messages to log files. If you are using rsyslog (default in debian):

#cat /etc/rsyslog.d/00-zm-foscam.conf
:msg, contains, "WAR [Corrupt JPEG data: 1 extraneous bytes before marker 0xd9]" ~
:msg, contains, "WAR [Corrupt JPEG data: 2 extraneous bytes before marker 0xd9]" ~
#service rsyslog restart

If you are use syslog-ng:

destination df_null { };
filter f_libjpeg { message(“WAR \\[Corrupt JPEG data: .+ extraneous bytes before marker”); };
log {

Controlling CPU Usage

The lib turbo jpeg is reccomended but if you are using modetect it is best to lower the framrate. From the Zoneminder FAQ's:

  • Capture frame rates. Unless there's a compelling reason in your case there is often little benefit in running cameras at 25fps when 5-10fps would often get you results just as good. Try changing your monitor settings to limit your cameras to lower frame rates. You can still configure ZM to ignore these limits and capture as fast as possible when motion is detected.

I had a VM cpu at 100 percent with 3 cams. I lowered to 5fps and cpu is at 30 percent.


CentOS 7 w/ Repo Install


Install CentOS Min

sudo yum install --nogpgcheck zmrepo-7-4.el7.centos.noarch.rpm
sudo yum install zoneminder
less /usr/share/doc/zoneminder-*/README.Centos7
systemctl enable mariadb
systemctl start mariadb
mysql -u root -p < /usr/share/zoneminder/db/zm_create.sql
mysql -u root -p
grant select,insert,update,delete,lock tables,alter on zm.* to 'zmuser'@localhost identified by 'zmpass';
mysqladmin -u root -p reload
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

On Upgrade

1. The Apache ScriptAlias has been changed from "/cgi-bin/zm/zms" to

  "/cgi-bin-zm/zms". This has been to done to avoid this bug:
  IMPORTANT: ZoneMinder will not update this value during an upgrade. You must
  manually update ZM_PATH_ZMS yourself under Options. This does not affect
  new installs.

2. Verify /etc/zm/zm.conf.

  If zm.conf was manually edited before running the upgrade, the installation
  may not overwrite it. In this case, it will create the file
  For example, this will happen if you are using database account credentials
  other than zmuser/zmpass.
  Compare /etc/zm/zm.conf to /etc/zm/zm.conf.rpmnew. Verify that zm.conf
  contains any new config settings that may be in zm.conf.rpmnew.

3. Verify permissions of the zmuser account.

  Overtime, the database account permissions required for normal operation
  have changed. Verify the zmuser database account has been granted select,
  insert, update, delete, lock tables, and alter permission to the ZoneMinder
    mysql -u root -p
        mysql> show grants for zmuser@localhost;
        mysql> exit;

4. Verify the database was upgraded automatically.

  From the web console, ZoneMinder should show a status of "Running", and the
  version number should have incremented.
  If it is not running, then try to start it. The web console will indicate
  if there is a database version conflict. If this is the case, then you may
  need to manually update the database from the command line:
  Modern versions of ZoneMinder don't require any parameters added to the
  zmupdate command. However, if ZoneMinder complains, you may need to call
  zmupdate in the following manner:
    sudo --user=root --pass=<mysql_root_pwd> --version=<from version>


nano /etc/zm/zm.conf

Moving Location Of Video Storage

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


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


You can disable SELINUX if you want.

sudo setenforce 0
  To permanently disable SELinux, edit /etc/selinux/conf and change the
  SELINUX line from "enforcing" to "disabled". This change will take
  effect after a reboot.