{"id":573,"date":"2024-12-18T18:15:42","date_gmt":"2024-12-18T12:45:42","guid":{"rendered":"https:\/\/swstech.sws-international.com\/?p=573"},"modified":"2024-12-18T18:15:42","modified_gmt":"2024-12-18T12:45:42","slug":"setting-up-user-quotas-on-ext4-file-system-in-centos-7-9","status":"publish","type":"post","link":"https:\/\/swstech.sws-international.com\/?p=573","title":{"rendered":"Setting Up User Quotas on Ext4 File System in CentOS 7.9"},"content":{"rendered":"\n<p>In this article, we will walk through the process of setting up and managing user quotas on an ext4 filesystem in CentOS 7.9. We&#8217;ll go from checking the filesystem to applying custom quotas for multiple users using a shell script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>Fstab Entry for Quota Configuration<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">First, ensure that the <strong>\/etc\/fstab<\/strong> file contains the necessary entry for enabling quotas. The entry for <code>\/home\/userfolder<\/code> in <strong>\/etc\/fstab<\/strong> should look something like this:<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>UUID=xxxxxxxxx-f5xx-43xx-xxbb-xxxxxxxxxxxxxx \/home\/userfolder auto defaults,rw,nofail,usrquota,grpquota 0 0<\/code><\/pre>\n\n\n\n<p>This entry enables user quotas (<code>usrquota<\/code>), group quotas (<code>grpquota<\/code>), and ensures that the filesystem is mounted with the correct options to support quota management.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Verify Mount and File System Type<\/strong><\/h3>\n\n\n\n<p>To verify that the filesystem is mounted correctly, check the mount point and its filesystem type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@prac1 ~]# mount | grep \/home\/userfolder\n\/dev\/mapper\/centos-7.9 on \/home\/userfolder type ext4 (rw,relatime,seclabel,data=ordered)\n<\/code><\/pre>\n\n\n\n<p>This confirms that the <code>\/home\/userfolder<\/code> directory is mounted with <strong>ext4<\/strong>, and it is ready to have quotas enabled.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Install Quota Package<\/strong><\/h3>\n\n\n\n<p>Before proceeding, ensure the quota package is installed on your system. This can be done using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install quota -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Remount to Enable Quota<\/strong><\/h3>\n\n\n\n<p>To enable quotas on the filesystem, remount the partition with the appropriate options. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mount -o remount \/home\/userfolder<\/code><\/pre>\n\n\n\n<p>You should see the filesystem mounted with the <code>usrquota<\/code> and <code>grpquota<\/code> options, as shown:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/dev\/mapper\/centos-7.9 on \/home\/userfolder type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>Run Quota Check<\/strong><\/h3>\n\n\n\n<p>Next, run the <code>quotacheck<\/code> command to check and create the necessary quota files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo quotacheck -um \/home<\/code><\/pre>\n\n\n\n<p>This command checks the <code>\/ve<\/code> filesystem for existing quotas and creates the necessary quota files (<code>aquota.user<\/code> and <code>aquota.group<\/code>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>Enable Quotas<\/strong><\/h3>\n\n\n\n<p>Once the quota check is complete, enable user quotas on the <code>\/ve<\/code> filesystem:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo quotaon -uv \/home\/userfolder<\/code><\/pre>\n\n\n\n<p>This will turn on the user quotas for <code>\/home\/userfolder<\/code>, and you should see output similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/dev\/mapper\/centos-7.9 [\/home\/userfolder]: user quotas turned on<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>Verify Quotas Are Active<\/strong><\/h3>\n\n\n\n<p>You can verify that quotas are enabled by using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>quotaon -ap<\/code><\/pre>\n\n\n\n<p>This will display the status of quotas for all mounted filesystems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>Set Quotas for Users<\/strong><\/h3>\n\n\n\n<p>To set quotas for individual users, use the <code>setquota<\/code> command for ext4. For example, to set a soft limit of 1.8GB and a hard limit of 2GB for the user <code>username<\/code>, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo setquota -u &lt;username> 1800M 2048M 0 0 \/home\/userfolder<\/code><\/pre>\n\n\n\n<p>This will apply the quota limits to the specified user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. <strong>Verify Quotas for Users<\/strong><\/h3>\n\n\n\n<p>After applying the quotas, verify them using the <code>repquota<\/code> command. This will show a summary of disk usage and quotas for all users:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo repquota \/home\/userfolder<\/code><\/pre>\n\n\n\n<p>The output will display the current quota usage and limits for users on the <code>\/home\/userfolder<\/code> filesystem.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. <strong>Automate Quota Setup for Multiple Users<\/strong><\/h3>\n\n\n\n<p>If you have multiple users for whom you need to apply quotas, you can automate the process using a shell script. Below is an example shell script <code>setupquota_ext4.sh<\/code> that applies the same quota settings for all users in the <code>\/<\/code>home\/userfolder directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nmntpnt=\/home\/userfolder\nusers=\"$( ls $mntpnt )\"\n\nfor user in $users\ndo\n    echo \"Setting quota for user: $user\"\n    sudo setquota -u $user 1800M 2048M 0 0 \/home\/userfolder\ndone<\/code><\/pre>\n\n\n\n<p>This script:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Lists all users in <code>\/home\/userfolder<\/code>.<\/li><li>Sets a <strong>soft limit of 1.8GB and a hard limit of 2GB <\/strong>for each user using <code>setquota<\/code>.<\/li><li>Automates the quota setup process for all users in the directory.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">11. <strong>Final Check<\/strong><\/h3>\n\n\n\n<p>After running the script, you can perform a final check to ensure the quotas were set correctly for all users:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo repquota \/home\/userfolder<\/code><\/pre>\n\n\n\n<p>This will show a report of quota usage and limits for each user in the <code>\/ve<\/code> filesystem.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>By following these steps, you can successfully enable and manage user quotas on an ext4 filesystem in CentOS 7.9. The process involves configuring the filesystem, installing necessary tools, and applying quotas either manually or through a shell script for automation. This ensures that users are limited in their disk usage according to the policies set by the system administrator.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will walk through the process of setting up and managing user quotas on an ext4 filesystem [&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":"","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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[3,7],"tags":[14,16,21,28,29],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-automotive","category-linux","tag-ext4","tag-grpquota","tag-quota","tag-usrquota","tag-xfsquota"],"_links":{"self":[{"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=573"}],"version-history":[{"count":0,"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=\/wp\/v2\/posts\/573\/revisions"}],"wp:attachment":[{"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swstech.sws-international.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}