{"id":725,"date":"2011-10-07T07:31:38","date_gmt":"2011-10-07T07:31:38","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=725"},"modified":"2011-10-07T13:41:10","modified_gmt":"2011-10-07T13:41:10","slug":"quota-support-on-mac-os-x","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=725","title":{"rendered":"Quota support on Mac OS X"},"content":{"rendered":"<p>Various quota systems exist for Unix operating systems. These record disk usage on a per-user (and per-group) basis, and optionally impose disk usage limits. Mac OS X version 10.2 ships with the Berkeley Software Distribution (BSD) quota system. These notes cover manual setup of quota support on a Mac OS X 10.2.6 system, along with uses of disk quotas. Those in a hurry should consider the following article: an easy method of creating disk quotas for users.<\/p>\n<p>Quota setup works under Mac OS X Tiger (10.4.2). Soft limits do not issue any warning, while hard limits should display some sort of error message. To handle soft limit violations, create a script that checks for users above the soft limit and notify them.<\/p>\n<h2>Setup<\/h2>\n<p>The\u00a0<a title=\"FreeBSD man page search for quotacheck, section 8 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=quotacheck&amp;sektion=8&amp;manpath=Darwin\"><tt>quotacheck(8)<\/tt><\/a>\u00a0command reports estimates of disk usage. This poses a problem, as the<a title=\"FreeBSD man page search for man, section 1\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=man&amp;sektion=1\"><tt>man(1)<\/tt><\/a>\u00a0pages on Mac OS X 10.2 incorrectly state the quota file locations. Now, a digression into<a href=\"http:\/\/72.14.189.113\/howto\/debug\/unix\/\">Unix debugging<\/a>. To determine what file the\u00a0<tt>quotacheck<\/tt>\u00a0command needs, use the kernel tracing facility via the\u00a0<a title=\"FreeBSD man page search for ktrace, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=ktrace&amp;sektion=1&amp;manpath=Darwin\"><tt>ktrace(1)<\/tt><\/a>\u00a0command. The results of\u00a0<tt>ktrace<\/tt>\u00a0can be read from\u00a0<tt>ktrace.out<\/tt>\u00a0with the\u00a0<a title=\"FreeBSD man page search for kdump, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=kdump&amp;sektion=1&amp;manpath=Darwin\"><tt>kdump(1)<\/tt><\/a>\u00a0command.<\/p>\n<pre>$ <kbd>sudo ktrace quotacheck -a<\/kbd>\r\n$ <kbd>sudo kdump -f ktrace.out | fgrep .quota<\/kbd>\r\n 7870 quotacheck NAMI \"\/\/.quota.ops.group\"\r\n 7870 quotacheck NAMI \"\/\/.quota.ops.user\"\r\n 7870 quotacheck NAMI \"\/Volumes\/Spider\/.quota.ops.group\"\r\n 7870 quotacheck NAMI \"\/Volumes\/Spider\/.quota.ops.user\"<\/pre>\n<p>The trace output shows\u00a0<tt>quotacheck<\/tt>\u00a0looking on the startup disk and an external firewire disk for the user and group quota setting files,\u00a0<tt>.quota.ops.user<\/tt>\u00a0and\u00a0<tt>.quota.ops.group<\/tt>. These files must be created on each filesystem quota support will be enabled on, which can be done from the\u00a0<tt>ktrace.out<\/tt>\u00a0file with\u00a0<a href=\"http:\/\/72.14.189.113\/howto\/shell\/\">shell scripting<\/a>.<\/p>\n<pre>$ <kbd>sudo kdump -f ktrace.out | fgrep quota.ops | \\ perl -nle 'print \/\"([^\"]+)\"\/' | xargs sudo touch<\/kbd>\r\n$ <kbd>sudo rm ktrace.out<\/kbd>\r\n$ <kbd>ls \/.quota* \/Volumes\/Spider\/.quota*<\/kbd>\r\n\/.quota.ops.group \/Volumes\/Spider\/.quota.ops.group\r\n\/.quota.ops.user \/Volumes\/Spider\/.quota.ops.user<\/pre>\n<p>Now\u00a0<tt>quotacheck<\/tt>\u00a0provides disk usage on all currently mounted filesystems; the results of the run will be saved to the\u00a0<tt>.quota.{user,group}<\/tt>\u00a0index files:<\/p>\n<pre>$ <kbd>sudo quotacheck -a<\/kbd>\r\nquotacheck: creating quota file \/\/.quota.user\r\nquotacheck: creating quota file \/\/.quota.group\r\nquotacheck: creating quota file \/Volumes\/Spider\/.quota.user\r\nquotacheck: creating quota file \/Volumes\/Spider\/.quota.group<\/pre>\n<p>One way to view the resulting disk usage data is via the\u00a0<a title=\"FreeBSD man page search for repquota, section 8 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=repquota&amp;sektion=8&amp;manpath=Darwin\"><tt>repquota(8)<\/tt><\/a>\u00a0command.<\/p>\n<pre>$ <kbd>sudo repquota -a -v<\/kbd><\/pre>\n<p><kbd><\/kbd>With empty\u00a0<tt>.quota.ops.*<\/tt>\u00a0quota configuration files, there should be no user or group disk space limitations. Current limitations can be viewed with the\u00a0<a title=\"FreeBSD man page search for quota, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=quota&amp;sektion=1&amp;manpath=Darwin\"><tt>quota(1)<\/tt><\/a>\u00a0command.<\/p>\n<pre>$ <kbd>sudo quota<\/kbd>\r\nDisk quotas for user root (uid 0): none<\/pre>\n<p>To enable automatic quota index updates without rebooting the system, use the\u00a0<a title=\"FreeBSD man page search for quotaon, section 8 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=quotaon&amp;sektion=8&amp;manpath=Darwin\"><tt>quotaon(8)<\/tt><\/a>command. The\u00a0<tt>quotaon<\/tt>\u00a0manual indicates quota support will be automatically enabled at filesystem mount time for volumes with the proper\u00a0<tt>.quota.*<\/tt>\u00a0files.<\/p>\n<pre>$ <kbd>sudo quotaon -a<\/kbd>\r\n$ <kbd>ls -lt \/.quota.*<\/kbd>\r\n-rw-r----- 1 root operator 131136 Aug 7 14:01 \/.quota.group\r\n-rw-r----- 1 root operator 524352 Aug 7 14:01 \/.quota.user\r\n-rw-r--r-- 1 root admin 0 Aug 6 19:45 \/.quota.ops.group\r\n-rw-r--r-- 1 root admin 0 Aug 6 19:45 \/.quota.ops.user<\/pre>\n<h2>Summary of Setup Tasks<\/h2>\n<p>1. Create .quota.ops.user and .quota.ops.group.<\/p>\n<p>Create these empty files as root at the top level of each filesystem to track disk usage on.<br \/>\n2. Run quotacheck -a.<br \/>\nThe quotacheck command creates (or updates) the .quota.user and .quota.group index files recording current usage.<\/p>\n<p>3. Run quotaon -a.<br \/>\nThis command enables automatic tracking of disk usage for filesystems the above steps have been performed on.<\/p>\n<h2>Setup Commands<\/h2>\n<p>Quick example of a quota reset and setup from scratch.<\/p>\n<pre>$ <kbd>sudo rm -f \/.quota.*<\/kbd>\r\n$ <kbd>sudo ktrace quotacheck -a<\/kbd>\r\n$ <kbd>sudo kdump -f ktrace.out | fgrep quota.ops | \\ perl -nle 'print \/\"([^\"]+)\"\/' | xargs sudo touch<\/kbd>\r\n$ <kbd>sudo rm ktrace.out<\/kbd>\r\n$ <kbd>sudo quotacheck -a<\/kbd>\r\n$ <kbd>sudo quotaon -a<\/kbd>\r\n$ <kbd>sudo edquota www<\/kbd><\/pre>\n<h2>Recording Usage<\/h2>\n<p>To maintain historical logs of disk usage, the typical approach is to run repquota from cron(8), and to parse the resulting output into plaintext files, spreadsheet, or database. One tool of note is RRDTool, which can facilitate the generation of graphs on webpages, among other things.<\/p>\n<p>The pquotarep script may help parsing the output of repquota into a format more suitable for conversion into other utilities.<\/p>\n<pre>$ <kbd>sudo repquota -av | pquotarep | head -1<\/kbd>\r\nfs=\/ type=group blocks=6264 blocks-hard=0 blocks-soft=0 files=785 files-hard=0 \u21b5\r\nfiles-soft=0 name=500<\/pre>\n<h2>Imposing Limits<\/h2>\n<p>To impose limits, additional information on the totals for the filesystem in question can be obtained from the\u00a0<a title=\"FreeBSD man page search for df, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=df&amp;sektion=1&amp;manpath=Darwin\"><tt>df(1)<\/tt><\/a>\u00a0command. Both disk space usage and inode counts will need to be considered. The following commands show how to list that data for physical disk filesystems.<\/p>\n<pre>$ <kbd>df -k | egrep '(^Filesystem|disk)'<\/kbd>\r\nFilesystem 1K-blocks Used Avail Capacity Mounted on\r\n\/dev\/disk0s2 19533300 9578416 9759552 49% \/\r\n\/dev\/disk1s4 39064200 32956248 6107952 84% \/Volumes\/Spider\r\n$ <kbd>df -i | egrep '(^Filesystem|disk)'<\/kbd>\r\nFilesystem 512-blocks Used Avail Capacity iused ifree \u21b5\r\n%iused Mounted on\r\n\/dev\/disk0s2 39066600 19156832 19519104 49% 2443435 2439888 \u21b5\r\n 50% \/\r\n\/dev\/disk1s4 78128400 65912496 12215904 84% 8239060 1526988 \u21b5\r\n 84% \/Volumes\/Spider<\/pre>\n<p>To edit quota limits, use the\u00a0<a title=\"FreeBSD man page search for edquota, section 8 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=edquota&amp;sektion=8&amp;manpath=Darwin\"><tt>edquota(8)<\/tt><\/a>\u00a0command. This will launch\u00a0<a title=\"FreeBSD man page search for vi, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=vi&amp;sektion=1&amp;manpath=Darwin\"><tt>vi(1)<\/tt><\/a>\u00a0by default to edit the quota data, which will confound those of you not versed in Unix editors.\u00a0<a href=\"http:\/\/www.webmin.com\/\">An alternative is to use Webmin to setup and manage quotas<\/a>.<\/p>\n<pre>$ sudo edquota $USER<\/pre>\n<p>The best way to test quotas is to create a new user account and subject it to various limits, rather than locking your main user account out or running the risk of preferences files being corrupted if hard limits are exceeded.<\/p>\n<p>To replace\u00a0<a title=\"FreeBSD man page search for vi, section 1 on Darwin\" href=\"http:\/\/www.FreeBSD.org\/cgi\/man.cgi?query=vi&amp;sektion=1&amp;manpath=Darwin\"><tt>vi(1)<\/tt><\/a>\u00a0with another editor, set the\u00a0<tt>EDITOR<\/tt>\u00a0environment variable to point at a different text editor, such as\u00a0<tt>pico<\/tt>.<\/p>\n<pre>$ <kbd>which pico<\/kbd>\r\n\/sw\/bin\/pico\r\n$ <kbd>sudo env EDITOR=pico edquota www<\/kbd><\/pre>\n<p><kbd>Example quota limitations for the user\u00a0<tt>www<\/tt>:<\/kbd><\/p>\n<div>\n<pre>Quotas for user www:\r\n\/: 1K blocks in use: 14120, limits (soft = 99999, hard = 999999)\r\n inodes in use: 1225, limits (soft = 9999, hard = 99999)<\/pre>\n<p>To remove a users quota then set there limitations to Zero<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Various quota systems exist for Unix operating systems. These record disk usage on a per-user (and per-group) basis, and optionally impose disk [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-725","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=725"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/725\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}