hikvision samba manual

samox86

n3wb
Jan 10, 2022
3
0
Europe
Hi guys,
I have used synology as a samba storage for my hikvision IP cams.
However, after a recent storage replace with linux server, I was no longer able to successfully connect, format and keep disk formatted (disk status changed to unformated after cam reboot).
I gather some tips from this site, so I would like to write the manual here :)
It describes connecting disk from linux via smb/cifs option.

!!! 1st 2 steps can be omitted in case you use compatible FS (XFS,ext3, ext4). I use btrfs which handle quotas in different way !!!

1.) create a 1TB file
# mkdir /mnt/cam1
# dd if=/dev/zero of=/mnt/cam1/cam1.img bs=1M count=1048576

2.) format it
# mkfs.ext4 /mnt/cam1/cam1.img

3.) create user, add to samba with password
# useradd cam1
# smbpasswd -a cam1

4.) add next line to /etc/fstab, create mount point and mount loopback file OR modify your existing mount point mount options.
/mnt/cam1/cam1.img /mnt/cam1/mount ext4 usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 0

# mkdir /mnt/cam1/mount
# mount /mnt/cam1/mount
# mkdir /mnt/cam1/mount/data
# chown cam1: /mnt/cam1/mount/data

5.) create symlink if needed (depending on linux distro)
# mkdir /usr/local/samba
# ln -s /var/log/samba /usr/local/samba/var

6.) modify or create /etc/smb.conf

min protocol=NT1
max protocol=SMB3
workgroup = WORKGROUP
server string = NAS
server role = standalone server
hosts allow = 192.168.1.10 192.168.1.11 #client IPs here
log file = /usr/local/samba/var/log.%m
max log size = 50
dns proxy = no

[cam1]
path = /mnt/cam1/mount/data
available = yes
valid users = cam1
read only = no
browsable = yes
public = no
writable = yes
create mask = 0755
directory mask = 0755
force directory mode = 0755

7.) stop and start samba service (I have a feeling that restart didn't apply some changes, but it may be that I was just so frustrated after a hours of trying and testing)
# systemctl stop smb
# systemctl start smb

8.) enable quotas
# cd /mnt/cam1/mount
# touch aquota.user aquota.group
# chmod 600 aquota.*
# mount -o remount /mnt/cam1/mount
# quotacheck -acguvm
# quotacheck -avugm
# quotaon -avug

8.) set soft and hard quotas - make sure you are able to work with vi text editor (press "i" for entering text and ESC for commands: ":wq" = write+quit, ":q" = discanrd changes and quit, "dd" = delete line, "x"= delete character).
edquota cam1

9.) check quotas
# repquota -a

  • I lost a lot of time with testing with less than 1GB share and getting "Device Error". Camera probably needs bigger disk.
  • 1TB should last over 2-3 weeks for h265+ with permanent recording.
  • you may get an error that quota file is truncated or so, but you should be able to fix it with 3 commands provieded in step 8 - try different order...

- if you are lost, keep in mind these facts:
a.) camera use only SMB1 version
b.) shared directory must be empty and writable (even "lost+found" couldn't be there)
c.) quotas has to be set. it's not enough to limit space with disk size

output:
[root@nas]# repquota -a
*** Report for user quotas on device /dev/loop0
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
cam1 -- 16838108 1006592000 1007616000 3904 0 0

It may happen that some statement is incorrect, however this is like it works for me with latest cam FW and latest samba (4.15.3-2)

good luck!
 
Great addition to IPCT!

What flavor and version of Linux did you set this up on?