How to Manage Inode Quotas and Control Inode Usage

The CentOS operating system has several features that restrict users’ resource consumption. They help web hosts and server administrators to fairly distribute resources on shared servers and to create tiered account systems. Without quotas, rogue users can—accidentally or deliberately—use more than their fair share, hurting their neighbors’ web hosting performance.

Inode quotas limit the number of files a user can create. In this article, we explore what inodes are, how to display inode quotas in cPanel, how to create inode quotas on the command line, how to automate quotas with cPanel & WHM’s standard hooks system.

What Are Inodes?

Inode is short for index node, the filesystem metadata that stores information about each file and where it is. Every file and directory has an inode that contains ownership details, permissions, the file’s size, the filetype, and pointers to its data. The contents and structure differ by filesystem, but inodes play a similar role in all Unix filesystems.

Because every file has an inode, enforcing an inode quota is the same as enforcing a limit on the number of files. Inode quotas don’t control the amount of data a user can store in their home directory; they put an upper limit on the number of files, not the size.

In the past, inode quotas were essential because each filesystem had a fixed quantity determined when the disk volume was formatted. If users generated too many files, they could use all the inodes, making it impossible to create new files. This was a common occurrence on email servers with inboxes that contain many small files. However, beginning with CentOS 7’s release in 2014, the default filesystem is XFS, which allocates inodes dynamically—you can’t run out of inodes.

However, large numbers of files create other problems. They can degrade hard drive performance and increase memory consumption. Additionally, each inode consumes a small amount of disk space, by default 512 bytes on XFS. In rare circumstances, a user could generate so many files they fill the volume with inodes, leaving no space for data. This usually only happens when buggy scripts autogenerate billions of tiny or empty files, but it’s a risk that should be guarded against.

Displaying Inode Usage In cPanel

You can inform cPanel users of their inode limits with the Statistics sidebar’s File Usage feature. It displays both used inodes and available inodes, allowing users to manage file numbers when they approach their limit.

The File Usage feature isn’t displayed by default, but server administrators can activate it in WHM. Select Tweak Settings under Server Configuration in the WHM sidebar menu. Enter “inode” in the search box, and activate the Display File Usage information in the cPanel stats bar (inode count) tweak.

Reducing Inode Usage

cPanel users approaching their inode quota limit can free inodes by deleting files. There are two types of inode quota: soft and hard. If you exceed your soft quota, you will still be able to create files. If you exceed your hard quota, you will not. Many of your hosting account’s features need to generate files. If you hit the hard limit, you won’t be able to add new web pages, receive emails, install software, or many other common tasks.

It’s better to reduce inode usage by deleting files long before you hit the hard limit. You can remove files by:

  • Deleting unused files from your hard drive with the cPanel File Manager.
  • Deleting or archiving emails.
  • Removing old backups.
  • Clearing content management system and web server caches. Caches tend to create lots of small files.

Creating Inode Quotas for XFS Filesystems

cPanel & WHM does not include an inode management interface, but server administrators can use the operating system’s built-in tools to assign user quotas.

To use inode quotas, the filesystem must be mounted with the “userquota”, “uqouta”, or “quota” option. To verify quotas are activated and enforced, open the WHM Terminal interface and run the following command:

less /etc/fstab

This displays the filesystem configuration options. Find the XFS filesystem you want to apply quotas to, and verify that one of the options we listed above is present. Quotas are activated by default on cPanel servers, so they should already be configured.

Here we can see that the volume mounted on root has the uquota option, which means it’s ready to enforce inode quotas. If you don’t see a similar option, you will have to enable quotas with WHM’s Initial Quota Setup feature.

In WHM, navigate to Server Configuration -> Initial Quota Setup. Click the proceed button. Depending on the filesystem’s size, enabling quotas may take some time. Once they are enabled, you must reboot the server.

If you prefer to activate quotas on the command line, you can run the following commands as root:

/scripts/initquotas
/scripts/fixquotas
reboot

To verify that quotas are active, rerun the “less /etc/fstab” command and check that the relevant volumes now have the quota option as discussed above.

Next, we have to apply a quota to a user. To do so, we use the “xfs_quota” command as root:

xfs_quota -x -c 'limit -u isoft=100000 ihard=150000 cpanel1' /

This command gives the user “cpanel1” a soft limit of 100,000 inodes and a hard limit of 150,000 inodes on the filesystem mounted at “/”. In a real-world hosting scenario, you are unlikely to use the “/” partition for user data, so ensure that you exchange the “/” for the correct mount point of your filesystem.

Once the inode quotas are set, the cPanel user will now be able to see the limit in their Statistics sidebar’s File Usage section. It displays the soft limit and consumed inodes as a percentage.

Automating Inode Quotas

The manual method is fine for a handful of users, but it would soon get tiresome on a busy shared hosting server. That’s why cPanel provides standardized hooks that can trigger scripts when cPanel & WHM performs an action, such as creating a new hosting account. Using hooks and custom code, you can automatically apply inode and other quotas when accounts are created or when dozens of other events occur.

Hooks can trigger Perl modules and scripts, PHP scripts, and shell scripts. We describe the process of creating a simple shell script and registering it with a hook in How to Setup Standardized Hooks with BASH in cPanel & WHM. For more complex functionality, we recommend writing a Perl module, which will have access to variables in the cPanel environment. You can find more information in our Guide to Standardized Hooks.

As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You’ll find us on Discord, the cPanel forums, and Reddit. Be sure to also follow us on FacebookInstagram, and Twitter.

Source link

Archives
Scroll to Top