How to use a USB Drive as a Dedicated Drive for ZoneMinder, v1.31.46. on Ubuntu 18.04 LTS Computer

This post explains how to use a usb drive attached to a PC to store zoneminder events instead of saving on the computer ( At /var/cache/zoneminder/events).

Saving of zoneminder events on a dedicated drive is facilitated on the latest zoneminder versions to avoid the disk of the PC is getting filled with videos and images.

Please refer the following site for the latest details

How to use a USB Drive as a Dedicated Drive for ZoneMinder

To enable to write data of zoneminder to the usb drive , It is necessary to mount the usb drive  on a folder of the PC . Please refer the link1 and link2  for further details.

For the installation details of Zoneminder please refer my  post here

First insert the usb drive to the computer .Then get the details of USB using the following procedure

Format the usb drive to ext4 using gnome-disk-utility

Then open the Ubuntu terminal

ls -l /dev/disk/by-uuid

Screenshot from 2018-08-23 17-45-57

figure 1:- Getting details of USB using the Ubuntu terminal ( ls -l /dev/disk/by-uuid )

Screenshot from 2018-08-23 17-36-40.png

figure 2:- Getting details of USB using gnome-disk-utility

 

 

Creating Systemd Mount Unit

Open the Ubuntu terminal

sudo mkdir /mnt/sdb

sudo gedit /etc/systemd/system/mnt-sdb.mount

and paste the following codes into mnt-sdb.mount and save
(details of uuid of usb was taken from figure 1 and figure 2)

 

Screenshot from 2018-08-24 19-06-31

Figure 3:-Codes in mnt-sdb.mount

sudo systemctl enable mnt-sdb.mount

sudo systemctl start mnt-sdb.mount

 

Then restart the computer

Now if you see the folder /mnt/sdb ,you can see that the usb drive is mounted on /mnt

Create a folder called “zoneminder” on the mounted usb. Then create folders “events” and “images” with in the folder “zoneminder”

Open the ubuntu terminal

cd /mnt/sdb

mkdir zoneminder

cd zoneminder

mkdir events

mkdir images

sudo chown -R www-data:www-data /mnt/sdb/zoneminder

sudo chown -R www-data:www-data /mnt/sdb/zoneminder/events

 

Figure 4:-After setting the owner and group to that of the web server user account

 

 

Create a config file under /etc/zm/conf.d . Name the file anything you want just as long as it ends in “.conf”. Add the following content to the file and save your changes:

(In my case I have used bkj.conf as the file name )

sudo gedit /etc/zm/conf.d/bkj.conf

and pasted following codes and  saved  the file in /etc/zm/conf.d

Screenshot from 2018-08-23 19-30-58

Figure 5:-

Open the ZM console and go to Options/Storage and add a NewStorage

added Storage path as /mnt/sdb/zoneminder/events

Please refer the following figure for the details

 

Figure 6:-Creating  a New Storage for the Monitor

sudo systemctl start zoneminder

 

Screenshot from 2018-08-23 18-01-44

Figure 7:-ZM Console and the monitor

 

Screenshot from 2018-08-23 21-06-32.png

 

Figure 8:- Saved ZM events on the mounted USB drive

 

Advertisements

33 thoughts on “How to use a USB Drive as a Dedicated Drive for ZoneMinder, v1.31.46. on Ubuntu 18.04 LTS Computer

  1. Hello Jayasundera! I hope you are well. I am going to ask questions about this. I have a fixed disk instead of a usb drive. Mine is sda instead of sdb as in your example. I received an error following your instructions. Here is a list of commands I entered in terminal.

    user74@nvr:~$ sudo fdisk /dev/sda

    Welcome to fdisk (util-linux 2.31.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Command (m for help): n
    Partition number (1-128, default 1): 1
    First sector (34-7814037134, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-7814037134, default 7814037134):

    Created a new partition 1 of type ‘Linux filesystem’ and of size 3.7 TiB.
    Partition #1 contains a ext4 signature.

    Do you want to remove the signature? [Y]es/[N]o: n

    Command (m for help): w

    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

    user74@nvr:~$ sudo mkdir /mnt/sda
    user74@nvr:~$ sudo gedit /etc/systemd/system/mnt-sda.mount

    ** (gedit:6895): WARNING **: 13:03:29.622: Set document metadata failed: Setting attribute metadata::gedit-position not supported
    user74@nvr:~$ ls -l /dev/disk/by-uuid
    total 0
    lrwxrwxrwx 1 root root 15 Aug 28 12:12 13E1-AF1C -> ../../nvme0n1p1
    lrwxrwxrwx 1 root root 15 Aug 28 12:12 560ec66b-9f45-11e8-bb2d-b06ebfbcdb7e -> ../../nvme0n1p2
    lrwxrwxrwx 1 root root 10 Aug 28 12:53 7cc913c9-6eb0-49e0-961b-aaa289a60696 -> ../../sda1
    user74@nvr:~$ sudo gedit /etc/systemd/system/mnt-sda.mount

    ** (gedit:6987): WARNING **: 13:07:47.392: Set document metadata failed: Setting attribute metadata::gedit-spell-language not supported

    ** (gedit:6987): WARNING **: 13:07:47.392: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported

    ** (gedit:6987): WARNING **: 13:07:50.125: Set document metadata failed: Setting attribute metadata::gedit-position not supported
    user74@nvr:~$ sudo systemctl enable mnt-sda.mount
    Created symlink /etc/systemd/system/multi-user.target.wants/mnt-sda.mount → /etc/systemd/system/mnt-sda.mount.
    user74@nvr:~$ sudo systemctl start mnt-sda.mount
    Failed to start mnt-sda.mount: Unit mnt-sda.mount is not loaded properly: Invalid argument.
    See system logs and ‘systemctl status mnt-sda.mount’ for details.
    user74@nvr:~$ ^C

    What do you think happened?

    • Hi Marty
      Are you going to use the same disk where you have installed Zoneminder or a partition of the disk for storing ZM events ?Please send me the code details entered in mnt-sda.mount .Can you show me the mounted disk that you want to store images using the gnome-disk-utility ?(gnome-disk-utility is installed by default in Ubuntu 18.04)

  2. I tried starting over and still received the same error. I tried looking for an answer myself and did stumble across information that said I should not use sudo with a graphical application. (gedit) Does this apply to this situation? I am attempting to add screenshots here but I don’t know if that will work. Here are screen shots that may help you.
    /home/user74/Pictures/Screenshot from 2018-08-28 15-34-08.png
    /home/user74/Pictures/Screenshot from 2018-08-28 15-41-04.png
    /home/user74/Pictures/Screenshot from 2018-08-28 15-54-50.png

    ** I did notice that when I put in the uuid the second time that the 4 numbers did not highlight in pink like they did the first time????

    /home/user74/Pictures/Screenshot from 2018-08-28 15-57-30.png

  3. Hi Martin
    According to your screenshot you are going to use disk sda1 as the dedicated drive to store ZM images .First sda1 has to be mounted on your file system ( /mnt )where the zoneminder has been installed .In my post I have used sdb as my USB storage for ZM images. In your case please replace sdb with sda1 in all my instructions in the post .The name of the file that you have to create in /etc/systemd/system has to be mnt-sda1.mount.
    The line no 8 of the file mnt-sda1.mount has to amend to suit your uuid number of sda1 .As shown in your screenshot .

    Note :-
    If you think that your hard disk is too big for ZM images , you can make a partition and use it. For partitioning It is easy to use GParted-LiveCD .Ref https://gparted.org/download.php (You will have to download GParted live and write it to a cd )
    If you make a partition you will have to use its corresponding identification name ( ie sda1 …sda2..) and uuid number .

  4. I understand now. It is a very basic mistake and I feel somewhat foolish. I struggle to work with drives, partitions and mounting. I thank you for taking the time to review my work and guide me to the solution. I will update you on my progress. I hope you have a great day!

  5. I still seem to have the same problem I had yesterday. I am not sure you saw all of the screenshots so I will post them one at a time. Here is my disk-utility showing that I mounted the drive.

    • Hi Martin
      Actually, I have no idea about the reason for becoming those letters pink colour. Instead of entering numbers one by one , copy the numbers from disk utility and paste on the file and see the outcome. Please see whether the /mnt/sda1 is accessible using the file manager . If sda1 folder is accessible after mounting , you can proceed.

  6. Thank you for the answer. I have another question regarding the permissions on the zoneminder, events and images folders. My group permissions do not match yours. www-data only has Access instead of Create and delete. Here is a screenshot.

    How do I change the group permissions for www-data?

  7. Hello B.K. Jayasundera,

    I have been having a hard time getting a dedicated drive working for for Zoneminder 1.32 on Ubuntu 18.04. I am unsure if it is an issue caused by the new version of ZM or if there is something else that needs to be done. I’ve tried your instructions and also instructions from the ZM wiki, but both end up having the same issue. With my setup, I have a 64GB SSD that has the OS, and a separate 4TB hard drive which I would like to have all the recorded video. The UUID was set to the 4TB drive, along with the permissions correctly being set to www-data for both Owner and Group with Created and Delete privileges. I used sdb1 as my mount point.

    In the log, I’m getting the two following errors repeatedly:

    Cannot write to content dirs(‘/mnt/sdb1/zoneminder/events’,’/mnt/sdb1/zoneminder/images’). Check that these exist and are owned by the web account user.

    Path /mnt/sdb1/zoneminder/events does not exist.

    • Hi Brian
      Did you manually create folders zoneminder, and events under /mnt/sdb1 ? It seems sdb1 has not mounted properly ? Could you send me a screenshot showing details of sdb1 using Gnome disk . Please go to /mnt/sdb1/ and right click the mouse on zoneminder and events folders and goto /properties/permissions to check whether the permissions are OK.

      • Hi Brian
        In your pictures with disk details , I have noticed 2 numbers of 4 TB disks mounted at the same time. Is this the same disk or two disks? This may be the reason for causing the problem. If the same disk is mounted twice , You will have to unmount one . Please check whether there are two mount files for the same disk .

      • When I made the mount file and mounted the drive, I only put the information for the one 4TB drive which is the one mounted under /mnt/sdb1. The other one was mounted or touched, it was merely left connected to the system. Even if I disconnect the unmounted drive, the problem persists.

      • Hello Jayasundera,
        I disconnected the second 4TB drive and reinstalled Ubuntu. I reinstalled Zoneminder using your guide and set up the dedicated drive using your guide. I am still getting the same issues as before.

        The permissions are set correctly, the mount is set correctly and appears within the filesystem. Is there an option I have to change within Ubuntu itself that is causing this issue?

      • Hi Brian
        I could not find any mistake in your procedure. But according to the logs , It seems the sdb1 has not mounted properly .It should be mounted on the root system ( /mnt) instead of /media/CLR). Please go to /mnt/sdb1 and check whether the sdb1 is mounted. If it is mounted you will be able to find the folders zoneminder and events , inside sdb1. Otherwise sdb1 is empty .I presume that you have installed zoneminder on 64GB disk (Not on 4TB disk)

      • Hi Brian
        Are you still getting 4 TB hard desks mounted on the “Disk management utility for GNOME” ? Then there may be two mount files for same disk on /etc/systemd/system/ . If there are 2 mount files for sdb1 , delete one. Please send me a screen print of codes written in the “mnt-sdb1.mount ” file . Zoneminder uninstallation will not delete these mount files .For a clean reinstallation , you will have to delete these mount files also . Please check whether you have created a file shown on the figure 5 in my blog post .

  8. I am sharing this in case it helps. I also am using v 1.32.0
    B.K. Jayasundera previously helped me with this problem. I was successful in using his method. Long story short, I reinstalled everything because I was having problems with all kinds of errors in my logs. It seemed to occur after I updated zoneminder. Anyway, when I got to the part where I directed zoneminder to my 4TB storage drive, i searched and found this alternative method. I tried it and it seems to be working fine.
    https://wiki.zoneminder.com/Common_Issues_with_Zoneminder_Installation_on_Ubuntu#Use_Systemd_to_Mount_Internal_Drive_or_NAS

  9. Hello B.K. Jayasundera! I have a question for you. I have searched high and low and am unable to find out the answer to this question. I have my camera set to mocord in zoneminder. When I go to the events folder and look at the actual video clip that is being recorded, I find that my clip is 8 seconds long, then it goes to the next clip. Surely this can’t be right? How can you review video when it is all in 8 second clips. It would take forever to enter each folder and view all of them to find what you are looking for? I did find the section length that is set to 600 and I assume this is how long it records when it detects motion? Do you know the answer? Thanks, Martin

    • Hi Martin
      The motion events can easily identified by activating WEIGHTED_ALARM_CENTRES . In Zm panel press ‘Options’ button ,then press ‘Config’ button ,tick the box at WEIGHTED_ALARM_CENTRES and save.When you run zoneminder ,go to total motion detection events shown on the zm panel you will see a tab named “Show TimeLine” at the right hand corner of the screen . If you press “Show TimeLine” button . you can easily identify the center of alarm .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s