Thursday, February 19, 2004

Of bash colors, ls colors

The colors that you see when you type "ls" in bash come from an environment variable called LS_COLORS. The LS_COLORS variable can be set from a configuration file using the command called dircolors and the actual file is called dir_colors.

I dug around a bit in man and info pages for ls, dircolors and dir_colors, and the most useful information seems to be the man page for dir_colors. You can access this page by typing man dir_colors at the console, or, you can click man dir_colors

Tuesday, February 03, 2004

Defining Quota in Linux ... ... ...

List of Quota Commands

# quota - display disk usage and limits
# rquota - implement quotas on remote machines
# fstab - static information about the filesystems
# edquota - edit user quotas
# setquota - set disk quotas (Command line editor)
# quotacheck - scan a filesystem for disk usage, create, check and repair quota files
# quotaon - turn filesystem quotas on
# quotaoff - turn filesystem quotas off
# repquota - produce a summary of quota information for a file system
# convertquota - convert quota from old file format to new one. Convert quota.user to aquota.user
# quotactl - manipulate disk quotas (C programmer interface)

The default Red Hat/Fedora Core Linux kernel is shipped quota ready. If you have streamlined your kernel by rebuilding it with fewer options, make sure it has been configured with quotas support. When using the tools xconfig or menuconfig be sure to reply y to:
Quota support (CONFIG_QUOTA) [n] y

Configuration of disk usage quotas on Linux - Perform the following as root:

  1. Edit file /etc/fstab to add qualifier "usrquota" or "grpquota" to the partition. The following file system mounting options can be specified in /etc/fstab: grpquota, noquota, quota and usrquota. (These options are also accepted by the mount command but ignored.) The filesystem when mounted will show up in the file /etc/mtab, the list of all currently mounted filesystems.)

    • To enable user quota support on a file system, add "usrquota" to the fourth field containing the word "defaults".
      /dev/hda2 /home ext3 defaults,usrquota 1 1
    • Replace "usrquota" with "grpquota", should you need group quota support on a file system.
      /dev/hda2 /home ext3 defaults,grpquota 1 1
    • Need both user quota and group quota support on a file system?
      /dev/hda2 /home ext3 defaults,usrquota,grpquota 1 1
      This enables user and group quotas support on the /home file system.

  2. touch /partition/aquota.user
    where the partition might be /home or some partition defined in /etc/fstab.
    chmod 600 /partition/aquota.user

    The file should be owned by root. Quotas may also be set for groups by using the file

    Quota file names:

    • Quota Version 2 (Linux 2.4/2.6 kernel: Red Hat 7.1+/8/9,FC 1-3): aquota.user,
    • Quota Version 1 (Linux 2.2 kernel: Red Hat 6, 7.0): quota.user,
    The files can be converted/upgraded using the convertquota command.
  3. Re-boot or re-mount file partition with quotas.
    • Re-boot: shutdown -r now
    • Re-mount partition: mount -o remount /partition

    After re-booting or re-mounting the file system, the partition will show up in the list of mounted filesystems as having quotas. Check /etc/mtab:
    /dev/hda5 / ext3 rw,usrquota 0 0

  4. quotacheck -vgum /partition
    quotacheck -vguma
    • For example (Linux kernel 2.4+: Red Hat 7.1+, Fedora): quotacheck -vguma
      quotacheck: WARNING -  Quotafile //aquota.user was probably truncated. ...
      quotacheck: Scanning /dev/hda5 [/] done
      quotacheck: Checked 9998 directories and 179487 files

    • For example (Linux kernel 2.2: Red Hat 6/7.0): quotacheck -v /dev/hda6
      System response:
            Scanning /dev/hda6 [/home] done
      Checked 444 directories and 3136 files
      Using quotafile /home/quota.user

    Quotacheck is used to scan a file system for disk usages, and updates the quota record file "quota.user/aquota.user" to the most recent state. It is recommended thet quotacheck be run at bootup (part of Redhat default installation)

    Man page: quotacheck - scan a filesystem for disk usage, create, check and repair quota files

  5. quotaon -av
    System Response: /dev/hda6: user quotas turned on

    quotaon - enable disk quotas on a file system.
    quotaoff - turn off disk quotas for a file system.

    Man page: quotaon - turn filesystem quotas on and off

  6. edquota -u user_id
    Edit directly using vi editor commands. (See below for more info.)
    For example: edquota -u user1
    • System Response (RH 7+):
      Disk quotas for user user1 (uid 501):
      Filesystem blocks soft hard inodes soft hard
      /dev/hda5 1944 0 0 120 0 0
      • blocks: 1k blocks
      • inodes: Number of entries in directory file
      • soft: Max number of blocks/inodes user may have on partition before warning is issued and grace persiod countdown begins.
        If set to "0" (zero) then no limit is enforced.
      • hard: Max number of blocks/inodes user may have on partition.
        If set to "0" (zero) then no limit is enforced.

    • System Response (RH 6):
                 Quotas for user user1:
      /dev/sdb6: blocks in use: 56, limits (soft = 0, hard = 0)
      inodes in use: 50, limits (soft = 0, hard = 0)
      Something failed if you get the response:
                 /dev/sdb6: blocks in use: 0, limits (soft = 0, hard = 0)
      inodes in use: 0, limits (soft = 0, hard = 0)

      Edit limits:
                 Quotas for user user1:
      /dev/hda6: blocks in use: 992, limits (soft = 50000, hard = 55000)
      inodes in use: 71, limits (soft = 10000, hard = 11000)

    If editing group quotas: edquota -g group_name

    Man page: edquota - edit user quotas

  7. List quotas:
    quota -u user_id

    For example: quota -u user1
    System response:

    Disk quotas for user user1 (uid 501):
    Filesystem blocks quota limit grace files quota limit grace
    /dev/hda6 992 50000 55000 71 10000 11000
    If this does not respond similar to the above, then restart the computer: shutdown -r now

  • Report on all users over quota limits: quota -q
  • Quota summary report: repquota -a
    *** Report for user quotas on device /dev/hda5 Block grace time: 7days; Inode grace time: 7days                         Block limits                File limits User            used    soft    hard  grace    used  soft  hard  grace ---------------------------------------------------------------------- root      -- 4335200       0       0         181502     0     0 bin       --   15644       0       0            101     0     0 ... user1     --    1944       0       0            120     0     0     
    No limits shown with this user as limits are set to 0.

  • One more way to set quota

    setquota -g $group $blocks $blocks 0 0 -a
    setquota -u $username $blocks $blocks 0 0 -a

    Replace $group, $username and $blocks. Note: $blocks is the quota size in MB * 1024! To deactivate quotas for a user or group, run these commands and set $blocks to 0.