2

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?

6

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.

  • Is that what @umeboshi is suggesting with their suggestion about using LVM? Would it slow things down significantly? – Btz Feb 4 '15 at 17:06
  • 1
    This answer is similar, but depends on a loopback mounted filesystem. IOW, you are emulating a block device on the filesystem and forcing the kernel to use two filesystem drivers (or the same one twice) to access a block on the disk. This would be slower than just using a block device. LVM is a wonderful tool. I never fill my drives completely and leave space for things like this that pop up from time to time. One can always use lvresize later. – umeboshi Feb 4 '15 at 17:08
  • 1
    I don't want to leave the impression that serving loopback filesystems over samba is a bad idea. I do this for windows 7 iso files (github.com/umeboshi2/paella/blob/master/vagrant/salt/roots/salt/…) for automated netboot win7 installs. However, for writable shares, I feel that going the loopback route is unnecessary unless you don't have lvm or access to the underlying block devices. – umeboshi Feb 4 '15 at 17:15
  • 1
    Well, I said it is not the best solution. The problem with LVM on remote servers is that you might need somebody to add a physical device. OP did not mention, but this might be a cloud system - good luck having the provider add a device for you. – thecarpy Feb 5 '15 at 7:27
2

There is another, cleaner option. It requires a kernel with disk quotas enabled, but no single user mode.

Basically, you edit your /etc/fstab and add usrquota to the mount options of the partition. Then you remount the partition:

$ sudo mount -o remount /dev/sd<x><y>

Where <x> is a letter of the disk and <y> the partition number on the disk (if you use uuid, see man mount to mount with uuid).

You then issue the following to create a quota file:

$ sudo quotacheck -avug

Once you have the quota file, it is time to add a quota for coworkerguy:

$ sudo edquota coworkerguy

Note that by default the editor is vi, set the EDITOR variable to nano or gedit or whichever editor you fancy and re-run above command.

$ export EDITOR=gedit

Now you can add quotacheck to cron

$ sudo echo 'quotacheck -avug' >/etc/cron.daily/quotacheck

See http://www.thegeekstuff.com/2010/07/disk-quota/ for exact steps and output.

Also, see http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html

  • Interesting - how can I check if my current kernel has disk quotas enabled? I did not install the system but it's very likely it's one of the stock ones that come with the distribution, not a custom compiled one. – Btz Feb 6 '15 at 16:28
  • 1
    We can not consider this is a "cleaner" option, because this require to configure the system and not samba itself. I'm also looking for samba-only option. – Loenix Dec 20 '15 at 8:11
  • Add a feature request to the samba team, I think it is best to use native functionality where possible because it is well tested. – thecarpy Sep 11 '18 at 8:22
1

I would use a block device mounted in that directory. LVM is useful here. Make a logical volume that is 2G and mount it at /samba/coworkerguy. This will bypass any need for quotas and meet the exact requirements by placing hard restriction on the size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.