{"id":200,"date":"2013-04-19T10:00:35","date_gmt":"2013-04-19T10:00:35","guid":{"rendered":"http:\/\/www.nicovs.be\/?p=200"},"modified":"2013-08-06T10:34:48","modified_gmt":"2013-08-06T10:34:48","slug":"ubuntu_quota","status":"publish","type":"post","link":"https:\/\/www.nicovs.be\/?p=200","title":{"rendered":"Installing and configuring Quota on Ubuntu"},"content":{"rendered":"<p>Writing this article because I had some weird stuff installing en enabling quota on my Ubuntu virtual server:<\/p>\n<p>When using a shared webserver, it is always nice to know which site is using what amount of disk space. This is of course, when each site runs under its own user.\u00a0Of course you can use df or other tools to find out, but using quota on Ubuntu is the way to go.<\/p>\n<p>First we start by installing quota itself:<\/p>\n<pre class=\"lang:default decode:true\">apt-get install quota<\/pre>\n<p>After installing this, you need to enable quota (usrquota and grpquota) on the disk which contains the websites.<\/p>\n<pre class=\"lang:default decode:true\">vim \/etc\/fstab<\/pre>\n<p>and change the \/ partition by adding usrquota,grpquota to the mount option<\/p>\n<p>In my case, on my Xen virtual machine:<\/p>\n<pre>\/dev\/xvda1      \/               ext3    errors=remount-ro,usrquota,grpquota 0       1<\/pre>\n<p>Prepare quota to be enabled by creating the quota files:<\/p>\n<pre class=\"lang:default decode:true\">touch \/quota.user \/quota.group\r\nchmod 600 \/quota.*\r\nmount -o remount \/<\/pre>\n<p>You will also need to load the\u00a0<tt>quota<\/tt>\u00a0kernel module, and cause that to be loaded at boot time. You can do that by running:<\/p>\n<pre>modprobe quota_v2\r\necho 'quota_v2' &gt;&gt; \/etc\/modules<\/pre>\n<p>Then run the quotacheck command:<\/p>\n<pre class=\"lang:default decode:true\">quotacheck -avugm\u00a0-F vfsv0<\/pre>\n<address>\u00a0the quotacheck parameters above explained:<\/address>\n<blockquote>\n<h6>-a: checks all filesystems<\/h6>\n<h6>-v: verbose check<\/h6>\n<h6><span style=\"font-size: 14px;\">-u:\u00a0Only user quotas listed in \/etc\/mtab or on the filesystems specified are to be checked. \u00a0This is the default action.<\/span><\/h6>\n<h6><span style=\"font-size: 14px;\">-g:\u00a0\u00a0Only group quotas listed in \/etc\/mtab or on the filesystems specified are to be checked<\/span><\/h6>\n<h6><span style=\"font-size: 14px;\">-m: same as &#8211;no-remount and thus forces quotacheck to run while the filesystem is mounted read\/write, this way you don&#8217;t have to stop any services in order to perform the quotacheck.<\/span><\/h6>\n<h6><span style=\"font-size: 14px;\">-F vfsv0: to specify the quotaformat<\/span><\/h6>\n<\/blockquote>\n<p>This might take a while to complete&#8230; So grab a coffee.When the quotacheck has finished, enable quota itself by:<\/p>\n<pre>quotaon -avug<\/pre>\n<address class=\"lang:default decode:true\">When I did this, I got the following errors:&nbsp;<\/p>\n<pre class=\"lang:default decode:true\"><span style=\"font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 12px; font-style: normal; line-height: 1.5;\">quotaon: cannot find \/\/aquota.group on \/dev\/xvda1 [\/]<\/span>\r\nquotaon: cannot find \/\/aquota.user on \/dev\/xvda1 [\/]<\/pre>\n<p>Fix this by:<\/p>\n<pre class=\"lang:default decode:true \">touch \/aquota.group \/aquota.user<\/pre>\n<p>Now, when you check the quota.user and quota.group file sizes, this might seem odd:<\/p>\n<pre class=\"lang:default decode:true\">nico@xenvm:~# ls -lha \/ | grep quota\r\n-rw-------   1 root root  29G Apr 19 10:38 quota.group\r\n-rw-------   1 root root  31G Apr 19 10:38 quota.user<\/pre>\n<p>Wow, huge files! Now, don&#8217;t worry about this, as df show up as:<\/p>\n<pre class=\"lang:default decode:true\">nico@xenvm:~# df -h\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/xvda1       40G   12G   26G  32% \/<\/pre>\n<p>Also as explained on: <a title=\"HP SA Forum\" href=\"http:\/\/h30499.www3.hp.com\/t5\/System-Administration\/HUGE-quota-user-file\/td-p\/4365361\" target=\"_blank\">HP SystemAdmin Forums<\/a><a title=\"HP SysAdmin Forums\" href=\"http:\/\/h30499.www3.hp.com\/t5\/System-Administration\/HUGE-quota-user-file\/td-p\/4365361\" target=\"_blank\"><br \/>\n<\/a><\/p>\n<blockquote><p>This is not a problem. The quota files are sparse files, i.e., they have &#8220;holes&#8221; of empty space that don&#8217;t actually take up any disk space. If you do an ls -ls on the file, the first field is the ACTUAL disk space used in KB. You&#8217;ll see that the file really occupies much less disk space than the length field would suggest. This is because the quota files are indexed based on the UID (for quota.user) or GID (for quota.group). If you have very large UIDs or GIDs (or negative ones, which translate to very very large unsigned integers) it will make the files appear very large.<\/p>\n<p>You can&#8217;t change this, short of removing the large UIDs\/GIDs and changing ownership of any files belonging to them, and you can&#8217;t remove the quota files. But it&#8217;s really not a problem. The Tru64 backup utilities, and most third-party ones as well, handle the quota files properly. They either don&#8217;t back them up at all, or back up them up as sparse files.<\/p><\/blockquote>\n<pre>Tip: to automatically enable quota on boot, add quotaon -a &gt;\/dev\/null 2&gt;&amp;1 to \/etc\/rc.local.<\/pre>\n<p>Show all userquota&#8217;s with this command:<\/p>\n<\/address>\n<pre class=\"lang:default decode:true\">repquota -vas<\/pre>\n<p>&nbsp;<\/p>\n<p>If you want to enable Hard and Soft Quota&#8217;s limits for your users and websites, you can implement this with quotatool. For now this is out of the scope of this article, as I&#8217;m not (yet) interested in this. \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing this article because I had some weird stuff installing en enabling quota on my Ubuntu virtual server: When using a shared webserver, it is always nice to know which site is using what amount of disk space. This is of course, when each site runs under its own user.\u00a0Of course you can use df [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4,6],"tags":[66,64,63,65],"class_list":["post-200","post","type-post","status-publish","format-standard","hentry","category-debian","category-ubuntu","tag-disk-space-used","tag-disk-usage","tag-quota","tag-user-quota"],"_links":{"self":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200"}],"version-history":[{"count":20,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":236,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions\/236"}],"wp:attachment":[{"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nicovs.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}