OS X: configure disk quotas for local users

    Introduction

    The HFS + file system (FS) on OS X supports quoting users and groups by ID at the volume level. The corresponding .quota.user and .quota.group files are located in the root directory. Each of them contains a header, followed by a hash table with the definition of limits, as well as the consumed values ​​on the user or group ID.

    Turn on disk quotas

    In order to enable quotas support in the root directory, you need to create a .quota.ops.user or .quota.ops.group file .
    1. We get root privileges in the terminal:
      sudo su
    2. Create an empty options file:
      touch /.quota.ops.user
    3. After that, it will become possible to run the command:
      repquoata -a
      and measure the current disk consumption by users by name. If the command does not start, type:
      checkquota -a
      To filter service users, you can use grep:
      repquota -a | grep -v -E "^ \ _"
    4. We enable quotas with the quotaon command (you can turn them off using quotaoff ):
      quotaon /
      The parameter points to a mounted file system point. In this example, there is only one root partition on the computer. If it is necessary to set quotas for several volumes, repeat the command for each of the mounted FS.
    From this moment, disk quotas are turned on, and it’s time to set up limit rules.

    We set consumption limits

    Quotas are set; we will set consumption limits for our users. We will configure quotas using the example of the blondie user. Custom quotas can be edited using the edquota command . A full description of the options can be found in man edquota, but we will use the -u (user) switch:
    edquota -u blondie
    The vi editor will open for editing (a paste; ESC,: wq, ENTER save and exit). In our example, the result looks like this:
    Quotas for user blondie:
    /: 1K blocks in use: 85963652, limits (soft = 0, hard = 0)
            inodes in use: 35294, limits (soft = 0, hard = 0)
    Limits can be set in hard and soft modes. Hard limit cannot be bypassed. As soon as the user reaches the limit, he receives a message about the inaccessibility of disk space. Soft limit can be bypassed for a while. Users are allowed to exceed their “soft” limit for the grace period. As soon as this time comes to an end, the “soft” limit is replaced by “hard”. You can use the edquota -t command to change the grace period . By default, in OS X, this period is one week.
    Let's set our user 100G (hard) and 30G (soft) limits on disk space without restrictions on the number of files:
    Quotas for user blondie:
    /: 1K blocks in use: 85963652, limits (soft = 31457280, hard = 104857600)
            inodes in use: 35294, limits (soft = 0, hard = 0)
    Mistress note
    Inodes are files in the file system. Each file gets its inode (including symbolic links).

    Tricks

    The set limit on the number of files used is easily bypassed using disk images (DMG). A disk image takes only one inode on the file system, no matter how many files it contains or grows to what size. Limit on files m. useful for service users, so that some daemon does not accidentally clog the file system with logs or core dumps.

    useful links

    1. HFS + Disk Quotas / www.secure-computing.net
    2. Creating and using disk quotas / hints.macworld.com

    Also popular now: