Giter Site home page Giter Site logo

ekenberg / quotatool Goto Github PK

View Code? Open in Web Editor NEW
41.0 5.0 10.0 191 KB

Command-line utility for filesystem disk quotas on Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, Solaris, AIX

Home Page: http://quotatool.ekenberg.se

License: GNU General Public License v2.0

C 78.24% Makefile 4.73% M4 3.68% Shell 13.35%

quotatool's Introduction

quotatool

Quotatool Commandline utility for filesystem quotas on Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, Solaris and AIX

Set 50Gb soft and hard diskusage limits for user johan on filesystem /home

quotatool -u johan -b -q 50G -l 50G /home

See more examples below

Installation

Linux

quotatool is already in your package manager:

Mac OS X

  • MacPorts sudo port sync; sudo port install quotatool
  • Homebrew brew update; brew install quotatool

Install from source code

./configure
make
sudo make install
(use gmake on *BSD)

Usage

quotatool { -u uid | -g gid } [ options ... ] filesystem
quotatool { -u | -g } { -i | -b } -t time filesystem
quotatool { -u uid | -g gid } -r filesystem
quotatool { -u uid | -g gid } -d filesystem

The actual arguments accepted depends on your system. Solaris, for example, doesn't support group quotas, so the -g option is useless. If your getopt() doesn't support optional arguments, then you always need to pass an argument to -u and -g.

Arguments and Options

   -u uid  username or uid.
   -g gid  groupname or gid.
      	   See examples below how to handle non-existent uid/gid

   -b      set block limits
   -i      set inode limits

   -q n    set soft limit to n blocks/inodes
   -l n    set hard limit to n blocks/inodes

   quotatool accepts the units Kb, Mb, Gb, Tb, bytes and blocks
   to modify limit arguments. Units are base 2 for blocks (1k = 1024)
   and base 10 for inodes (1k = 1000).
   Use +/- to raise/lower quota by the specified amount.
   n can be integer or floating point
   See examples below.

   -R      Raise only - makes sure you don't accidentally lower quotas for a user/group

   -t      time set global grace period to time.
           The time parameter consists of an optional
           '+' or '-' modifier, a  number, and one of:
           'sec', 'min', 'hour', 'day', 'week', and
           'month'.  If a +/- modifier is present, the
           current quota will be increased/reduced by
           the amount specified

   -r      restart grace period for uid or gid

   -h      print a usage message

   -v      verbose mode -- print status messages during execution
           use this twice for even more information

   -n      do everything except set the quota.  useful with -v
           to see what is supposed to happen

   -V      show version

   filesystem is either device name (eg /dev/sda1) or mountpoint (eg /home)

Examples

Set soft block limit to 800Mb, hard block limit to 1.2 Gb for user mpg4 on /home:

quotatool -u mpg4 -b -q 800M -l 1.2G /home

Raise soft block limit by 100M for non-existent gid 12345 on /dev/loop3:

quotatool -g :12345 -b -q +100M /dev/loop3

Set soft inode limit to 1.8k (1800), hard inode limit to 2000 for user johan on /var:

quotatool -u johan -i -q 1.8K -l 2000 /var

Set the global block grace period to one week on /home:

quotatool -u -b -t "1 week" /home

Restart inode grace period for user johan on root filesystem:

quotatool -u johan -i -r /

Notes

  • Grace periods are set on a "global per quotatype and filesystem" basis only. Each quotatype (usrquota / grpquota) on each filesystem has two grace periods
  • one for block limits and one for inode limits. It is not possible to set different grace periods for users on the same filesystem.

BSD-note: According to 'man quotactl', global grace periods should be supported on BSD. quotatool on BSD does the right thing, which can be confirmed with 'edquota -t'. However, the value doesn't seem to be used by the system when usage passes a soft limit.

  • Using non-existent uids/gids like ":12345" can be useful when configuring quotas on a mounted filesystem which is a separate system in it self, like when preparing an install image or repairing a filesystem from another installation.

  • Limit arguments can be specified in several ways, these are all equivalent: 1M 1m 1Mb 1 "Mb"

  • Use +/- to raise/lower quotas relative to current limits

  • Use -v (or -v -v) to see verbose/debug info when running commands

Platforms and Filesystems

quotatool currently builds and works well on:

-- Linux -- Quota formats: old, vfsv0, vfsv1 and "generic" Filesystems: ext2, ext3, ext4, ReiserFS and XFS

-- Mac OS X --

-- BSD -- FreeBSD, OpenBSD, NetBSD (ufs, ffs)

-- Solaris --

-- AIX --

Missing your favorite *nix OS? Missing a feature, or found a bug? Feel free to add an Issue on https://github.com/ekenberg/quotatool

quotatool's People

Contributors

baszoetekouw avatar ekenberg avatar vapier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

quotatool's Issues

SSL cert expired for https://quotatool.ekenberg.se/

quotatool.ekenberg.se uses an invalid security certificate.
The certificate expired on January 19, 2018 3:59 PM. The current time is January 28, 2018 12:12 AM.
Error code: SEC_ERROR_EXPIRED_CERTIFICATE 

Setting Quotas for Users home directories

I have The Littlest JupyterHub instance running and I would like to set limits to how much space these users can use at each of their respective home directories

I have attempted to run the following command

sudo quotatool -u jupyter-david -b -q 5G -l 10G /home

But I get the following output

quotatool: Filesystem /home does not exist

What needs to be done so that I can limit the home directories of users?

4Tb limit issues

I get some very odd behaviours with the test script below.

  • Quota limits above 4Tb appear to be wrapping around to zero if expressed in certain ways
  • Giving a soft limit of 1Tb and a hard limit of 1.01Tb (a natural way to express it) gives a hard limit of 1block.
#!/bin/sh
#
# test 4Tb limit in quotatool. Give a mount point as the argument.
f=$1
[ -d "$1" ] || exit 1
uid=`id -u`

BINARY=/usr/sbin/quotatool
echo "Quotatool version:"
sudo $BINARY -V
echo ""

echo "Environment:"
env
uname -a
echo ""

echo Filesystem $f is of type:
mount |grep -w $f
echo ""

for unit in "" Kb Mb Tb
do
   echo "Unit: '$unit' -------------------------------------------------------"
   echo ""
   case X${unit} in
     X)   SIZES="1073741824 4294967294 4294967295 4294967296 4294967297" ;; 
     XKb) SIZES="1073741824 4294967294 4294967295 4294967296 4294967297" ;;
     XMb) SIZES="1048576 4194304 4194305 4194306 4194307" ;;
     XGb) SIZES="1024 4094 4095 4096 4097" ;;
     XTb) SIZES="1 2 3 4 5 1.01 4.01" ;;
   esac

   for i in $SIZES
   do
     j=`echo $i |awk '{printf "%12d",$i+1}'`
     echo "% $BINARY -u $uid -b -q ${i}${unit} -l ${j}${unit} -i -q 0 -l 0 -v -n
 $f"
     sudo $BINARY -u $uid -b -q ${i}${unit} -l ${j}${unit} -i -q 0 -l 0 -v -n $f
   done

   echo ""
done

Machine-readable format, bad format string

There is an error in printf() of "-d" format. Example:

 It is:
 1000 /home 13876788 0 0 0 101707 0 00

 It should be:
 1000 /home 13876788 0 0 0 101707 0 0 0

This code is executed if HAVE_INTTYPES_H was set.

It is caused by a typo in main.c. I'm attaching a patch.

diff --git a/src/main.c b/src/main.c
index aed922f..440b89c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -85,7 +85,7 @@ int main (int argc, char **argv) {
      display_blocks_used = quota->diskspace_used / 1024;
      if (quota->diskspace_used % 1024 != 0) display_blocks_used += 1;
 #ifdef HAVE_INTTYPES_H
-     printf("%d %s %" PRIu64 " %" PRIu64 " %" PRIu64 " %lu %" PRIu64 " %" PRIu64 " %" PRIu64 "%lu\n",
+     printf("%d %s %" PRIu64 " %" PRIu64 " %" PRIu64 " %lu %" PRIu64 " %" PRIu64 " %" PRIu64 " %lu\n",
 #else
      printf("%d %s %llu %llu %llu %d %llu %llu %llu %lu\n",
 #endif

Improve documentation

The README and man-page should provide more examples.

The README / USAGE / man-page could be clearer

Document : prefix for uid/gid

Document Gb and Tb size units

Error on setting quota

When called like this

quotatool -u username -b -q 10G -l 11G /some/partition

quotatool (version 1.4.12) fails for some users with the error message

quotatool: Failed setting quota (generic): No such process

and exit code 3.

Error while detecting kernel quota version: No such file or directory on debian wheezy

Got these error message:

Error while detecting kernel quota version: No such file or directory

Last part of strace when running quotatool:


poll([{fd=4, events=POLLIN|POLLPRI}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
read(4, "0\f\2\1\2e\7\n", 8) = 8
read(4, "\1\0\4\0\4\0", 6) = 6
time([1350478913]) = 1350478913
rt_sigaction(SIGPIPE, {SIG_DFL, [], SA_RESTORER, 0x7f172bff54f0}, NULL, 8) = 0
open("/etc/mtab", O_RDONLY) = 5
brk(0xb52000) = 0xb52000
futex(0x7f172c346f20, FUTEX_WAKE_PRIVATE, 2147483647) = 0
fstat(5, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f172c566000
read(5, "rootfs / rootfs rw 0 0\nsysfs /sy"..., 1024) = 680
close(5) = 0
munmap(0x7f172c566000, 4096) = 0
open("/proc/fs/quota", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/proc/sys/fs/quota", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
quotactl(Q_GETFMT|USRQUOTA, "rootfs", 0, 0x7fff71ea346c) = -1 ENOENT (No such file or directory)
write(2, "quotatool: ", 11quotatool: ) = 11
write(2, "Error while detecting kernel quo"..., 70Error while detecting kernel quota version: No such file or directory
) = 70
write(2, "\n", 1
) = 1
exit_group(3)


Command: # quotatool -u someuser -b -l 150MB /

ls -l /proc/sys/fs/quota/

insgesamt 0
-r--r--r-- 1 root root 0 Okt 17 14:41 allocated_dquots
-r--r--r-- 1 root root 0 Okt 17 14:41 cache_hits
-r--r--r-- 1 root root 0 Okt 17 14:41 drops
-r--r--r-- 1 root root 0 Okt 17 14:41 free_dquots
-r--r--r-- 1 root root 0 Okt 17 14:41 lookups
-r--r--r-- 1 root root 0 Okt 17 14:41 reads
-r--r--r-- 1 root root 0 Okt 17 14:41 syncs
-rw-r--r-- 1 root root 0 Okt 17 14:41 warnings
-r--r--r-- 1 root root 0 Okt 17 14:41 writes

uname -a

Linux EBBK-SRV 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012 x86_64 GNU/Linux

cat /proc/sys/fs/quota/*

20
312251
311663
0
312317
66
26
1
47009

mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=2056129,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=1646092k,mode=755)
/dev/disk/by-uuid/cfb767db-caae-47d3-9c87-9372c2f617c1 on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user,grpjquota=aquota.group)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=9998140k)

Implicit declaration error on MacOS Sonoma

When trying to build quotatool on MacOS Sonoma, I get this error within the make install step:

clang -g -O2  -I./src -I./src/darwin -DHAVE_CONFIG_H  -c -o src/darwin/quota.o src/darwin/quota.c
src/main.c:211:17: error: call to undeclared function 'quota_reset_grace'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
          if (! quota_reset_grace(quota, (argdata->block_reset ? GRACE_BLOCK : GRACE_INODE)))
                ^
src/main.c:211:17: note: did you mean 'xfs_reset_grace'?
./src/quota.h:113:13: note: 'xfs_reset_grace' declared here
int         xfs_reset_grace(quota_t *myquota, int grace_type);
            ^
1 error generated.
make: *** [src/main.o] Error 1

Adding -Wno-implicit-function-declaration to CFLAGS is a workaround for now.

quotatool: Failed Fetching quotas: No such file or Directory.

quotatool not working for AIX.
AIX Version:- 7200-04-01-1939 ( IBM Power PC )

quotatool Version - 1.6.2

Whenver i follow all the syntax and argument, quotatool reports following error all the time
quotatool-AIX

quotatool: Failed Fetching quotas: No such file or Directory.

I trying using different arguments as per quotatool Help, but all command output reports same thing:
quotatool: Failed Fetching quotas: No such file or Directory.

Support non-existent uid/gid

In some situations it can be useful to manipulate quotas for a uid/gid not present in the system, for instance when working on a loop-mounted filesystem image of some sort.

Idea: prefix uid/gid with ':' to indicate "Yes, use this uid/gid even if it's not present in the system"

quotatool -u :5000 ....

Usage on OSX?

Hello! Thank you for the time you have put into this library.

I've downloaded/installed via brew, and have read the README, but try as I might nothing seems to work. I'm trying to set a limit on /Users/foo

quotatool -u foo -b -q 10G -l 12G /System/Volumes/Data/Users/foo

and

quotatool -u foo -b -q 10G -l 12G /Users/foo

both yield:

quotatool: Filesystem /Users/foo does not exist.

Similarly, invoking on any device listed in diskutil list yields the same error. Have I overlooked a detail?

Am on Big Sur, 11.3

Thanks for your guidance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.