> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.5-jie-ufs-ci-pan-pei-e.md).

# 27.5 UFS Disk Quotas

Disk quotas can be used to limit the amount of disk space or number of files that a user or group can allocate on each UFS file system, thereby preventing any single user or group from consuming all available disk space.

## Verifying Kernel Support

The default FreeBSD kernel provides support for disk quotas. You can verify this by running the following command:

```sh
$ sysctl kern.features.ufs_quota
kern.features.ufs_quota: 1
```

If the output is 0, it indicates that you may be using a custom kernel that does not support the disk quota module. You should add the kernel option `options QUOTA` to your kernel configuration file and then recompile the kernel.

## Enabling Disk Quotas

Set disk quotas to enable at boot:

```sh
# service quota enable
```

Enable disk quotas immediately:

```sh
# service quota start
```

At startup, the system checks the quota integrity of each file system through quotacheck(8). This program ensures that the data in the quota database correctly reflects the data in the file system. This process takes a considerable amount of time and can significantly affect system startup time. To skip this step, add the following variable to **/etc/rc.conf**:

```ini
check_quotas="NO"
```

You must add quota options to **/etc/fstab** to enable per-user or per-group disk quotas. To enable per-user quotas, add `userquota` to the options field of the file system's **/etc/fstab** configuration line. For example:

```ini
/dev/nda0p2     /               ufs     rw,userquota      1       1
```

To enable group quotas, use `groupquota` instead. To enable both user and group quotas, separate the options with a comma:

```ini
/dev/nda0p2     /               ufs     rw,userquota,groupquota      1       1
```

After configuration, restart the system. **/etc/rc** will automatically run the appropriate commands to create initial quota files for all quotas enabled in **/etc/fstab**.

By default, quota files are stored in the root directory of the file system, named **quota.user** and **quota.group**.

```sh
-rw-r-----   1 root operator -                             64192 May  1 02:34 quota.group
-rw-r-----   1 root operator -                             64192 May  1 02:34 quota.user
```

## Setting Quota Limits

To verify that quotas are enabled, run the following command:

```sh
$ quota -v
Disk quotas for user ykla (uid 1001):
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/                    32        0       0              9       0      0
```

At this point, the system is ready to set quota limits using `edquota`.

Quota limits can be based on disk space (block quotas), file count (inode quotas), or a combination of both. Each type of limit is further divided into two categories: hard limits and soft limits.

A hard limit cannot be exceeded. When a user reaches a hard limit, they can no longer allocate any space on that file system. For example, if a user has a hard limit of 500 KB on a file system and is currently using 490 KB, the user can only allocate an additional 10 KB. Attempting to allocate an additional 11 KB will fail.

A soft limit can be exceeded for a certain period of time, known as the grace period, which defaults to one week. If a user exceeds the soft limit and the grace period has expired, the soft limit becomes a hard limit and no further space allocation is allowed. When the user drops below the soft limit, the grace period resets.

In the following example, edit the quota for the `ykla` account. When `edquota` is invoked, it opens the editor specified by the `EDITOR` environment variable to edit the quota limits. The default editor is vi(1).

```sh
# edquota -u ykla
Quotas for user ykla:
/: in use: 32k, limits (soft = 0k, hard = 0k)	# Block quota limit
        inodes in use: 9, limits (soft = 0, hard = 0)	# Inode quota limit
```

You can change the block quota and inode quota to configure quota limits. For example, to increase the block limit for **/** to a soft limit of `100` and a hard limit of `120`, change the values on that line to:

```sh
/: in use: 32k, limits (soft = 100k, hard = 120k)
```

After exiting the editor, the new quota limits take effect. Users can only check their own quotas and the quotas of groups they belong to. Only the superuser can view quotas for all users and groups.

```sh
# quota -v ykla
Disk quotas for user ykla (uid 1001):
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/                    32      100     120              9       0      0
```

Typically, if a user has not used any disk space on a file system, that file system will not appear in the output of quota(1), even if quotas are set for it.

In some scenarios, you may need to set the same quota limits for a batch of users. You can first assign the desired quota limits to one user, then use the `-p` option to copy those quotas to users within a specified UID range. The following command copies the quota limits to users with UIDs from `10000` to `19999`:

```sh
# edquota -p ykla 10000-19999
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.5-jie-ufs-ci-pan-pei-e.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
