Posts Tagged ‘disk’

Managing Disk Quota

Posted: 08/06/2011 in Ubuntu Linux
Tags: , , ,

Quotas are used to enforce a disk space limit or an inode maximum on individual user or group. Setting a quota limit to a disk eliminates system inaccessibility. There are cases; when a disk is full, a user can’t login or use the system. There are five types of quota limits:
user hard: the maximum size for a user
user soft: a user’s warning threshold
group hard: the maximum size for a group
group soft: the group’s warning threshold
grace period: a soft limit time restriction

To set quota limits, add an entry in in /etc/fstab
e.g.:

No Quota: /dev/hda2 /home ext2 default 1 1
User Quota Set: /dev/hda2 /home ext2 default,usrquota 1 1
Group Quota Set: /dev/hda2 /home ext2 default,grpquota 1 1

After adding an entry, create a quota record in the user’s home directory. (Use sudo mount -a to reload all mounted devices.)
e.g:

sudo touch /home/quota.user
sudo touch /home/quota.group

Then, manage user privileges on the created quota record.
e.g:

chmod 600 /home/quota.user
chmod 600 /home/quota.group

Reboot the system or remount the partition for the changes to take effect.

Assigning quota for users and groups

Setup quota for a user/group: edquota -u user
Setup a grace period: edquota -t time_units


QUOTA COMMANDS

quotacheck – scan the disk usage and update the ”quota.user”.
Options:
-v produce some useful information about what it is doing
-d debug (very detail -v)
-u user (all files with uid)
-g group (all fule with gid)
-a all
-R except root (when used with -a)

repquota – produces a summarized report on the quotas on the system.
Options:
-a all file system indicated in /etc/fstab
-v report all quotas, even if there is no usage
-g report group quotas
-u report user quotas (default)

quotaon/quotaoff – turn quota on.
-a all (as in /etc/fstab).
-v display message for each ?le system.
-g manipulate user quotas.
-u manipulate group quotas

Here’s another summary of commands used in Linux. These commands are related to filesystem maintenance. It is important to monitor disk space and check Linux file system.

du – shows disk usage
syntax:

du [options] directory

Options:
-a Show counts for all files & directories
-b Display size in bytes
-c Print total for all arguments after processing
-h Print in human readable form
-k Show size in Kilobytes
-m Display size in Megabytes
-s Display a summary for each argument
-x Skip directories containing other filesystems

df – show used and available disk space
syntax:

df [options] directory

Options:
-a Show counts for all filesystems
-t fs type Limit listing to fs type
-h Print in human readable form
-k Show size in Kilobytes
-m Display size in Megabytes
-i Display inode information
-l Limit listing to local filesystems
-x fs type Exclude fs type from listing

fsck – check and optionally repair one or more Linux file systems.
Syntax:

fsck [options] device

Options:
-p Automatically repair without prompting
-n Don’t make changes to filesystem
-y Assume yes to all questions
-f Force check even if fs is clean
-r Interactively prompt for changes
-v Be verbose
-A Check all filesystems in /etc/fstab
-C Display a progress bar
-N Don’t execute, show what would be done

When fsck completes, it will return a value:
Code and Meaning
0 No errors
1 Errors found & corrected
2 System should be rebooted
4 Filesystem error left uncorrected
8 Operational error
16 Usage or syntax error
128 Shared library error

e2fsck – check Linux second extended file system (e2fs).
mke2fs – create an ext2 filesystem or make an ext3 filesystem with the -j option.
syntax:

mke2fs [options] device

Options:
-V Be verbose
-b blocksize Make blocks blocksize bytes
-c Check for bad blocks on device
-i bytes per inode Create an inode for each bytes per inode
-j Create a journal (ext3)
-L label Set the volume label
-N inodes Create the fs with specified number of inodes
-n Show what would be done (don’t actually create fs)

debugfs – a file system debugger
syntax:

debugfs [options] device

commands:
cat filespec –dump contents of the inode filespec to stdout.
cd filespec –change current working directory to filespec.
chroot filespec –change root directory to be the directory file spec.
close –close currently open file system
quit –exit debugfs

dumpe2fs – print super block and blocks group information for the filesystem present on device
syntax:

dumpe2fs [options] device

Options:
-b Display badblocks on device
-h Display superblock information

tune2fs – adjust tunable filesystem parameters on a Linux ext2 filesystem.
Syntax:

tune2fs [options] device

Options:
-c max-mounts Set no of mounts before fsck is forced
-g group Set the group who can use reserved blocks
-j Add a journal to the filesystem
-L label Set the volume label
-r blocks Set the number of reserved blocks