Samba – How to Set a Size Limit to SAMBA Shared Directory Remotely

administrationcifssamba

I have been asked to set up a shared directory for a colleague on a server I manage. I created an account for him on that server, set up a Samba password with smbpasswd, created a directory and set it up in the smb.conf file, which I copy below:

[global]
workgroup = OURWORKGROUP
server string = Samba Server %v
netbios name = server_i_run
security = user
map to guest = bad user
name resolve order = bcast lmhosts host wins 
dns proxy = no
[coworkerguy]
path = /samba/coworkerguy
valid users = coworkerguy
guest ok = no
writable = yes
browsable = yes

Now I have been asked to limit this space to 2Gb. I have looked online for ideas but I can't find anything recent and setting up disk quotas is apparently one of the most popular solutions. I admit I'm not that confident doing that, and furthermore it often comes up that I have to reboot in single user mode – unless I misunderstood something. That is not possible, as I can only ssh remotely to that server. Are there are techniques I could use? If not, could someone point me to an idiot-proof guide?

Best Answer

My solution is not the best, I know, but it works ;-). EDIT: Please read my other answer as well, this answer is an evil hack!

Create a 2Gb file with dd, format the file e.g. ext3, mount it, add it to fstab and use that as a share.

$ dd if=/dev/zero of=filename bs=1024 count=2M
$ sudo mkfs.ext4 filename
$ cat /etc/fstab
/path/to/filename /mount/point ext4 defaults,users

Now you point the share to /mount/point (or wherever you chose to mount it), so

path = /samba/coworkerguy becomes path = /mount/point

In UNIX, everything is a file.

Related Question