Archives

User and Group Disk Quota on UNIX / Linux

User and Group Disk Quota on UNIX / Linux

On Linux, you can setup disk quota using one of the following methods:

File system base disk quota allocation

User or group based disk quota allocation

disk-quota-300x213

On the user or group based quota, following are three important factors to consider:

Hard limit – For example, if you specify 2GB as hard limit, user will not be able to create new files after 2GB

Soft limit – For example, if you specify 1GB as soft limit, user will get a warning message “disk quota exceeded”, once they reach 1GB limit. But, they’ll still be able to create new files until they reach the hard limit

Grace Period – For example, if you specify 10 days as a grace period, after user reach their hard limit, they would be allowed additional 10 days to create new files. In that time period, they should try to get back to the quota limit.

Required Package:

quota-devel-3.17-20.el6.i686

quota-3.17-20.el6.i686

/etc/quotagrpadmins

/etc/quotatab

/etc/sysconfig/quota_nld

/etc/warnquota.confonfiguration

/etc/fstab

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)

Enter Single-User Mode

As you’ll need to remount the /home filesystem, you make sure that no other users or processes are using it by first entering single-user mode from the console. If you are certain that you’re the only user on the system, you might be able to skip this step. Entering single-user mode automatically logs off all users and stops cron jobs, so wait until after hours to do in a business environment. The procedure is quick:

1) Use the who command to see which users are logged in. If there are any, besides yourself, send a message stating that the system is about to shutdown with the wall command:

[root@bigboy tmp]# who

root     pts/0        Nov  6 14:46 (192-168-1-242.my-site.com)

bob      pts/0        Nov  6 12:01 (192-168-1-248.my-site.com)

bunny    pts/0        Nov  6 16:25 (192-168-1-250.my-site.com)

[root@bigboy tmp]# wall The system is shutting down now!

Broadcast message from root (pts/0) (Sun Nov  7 15:04:27 2004):

The system is shutting down now!

[root@bigboy tmp]#

2) Log into the VGA console and enter single user mode.

[root@bigboy tmp]# init 1

1. Enable quota check on filesystem

First, you should specify which filesystem are allowed for quota check.

Modify the /etc/fstab, and add the keyword usrquota and grpquota to the corresponding filesystem that you would like to monitor.

The following example indicates that both user and group quota check is enabled on /home filesystem

# cat /etc/fstab

LABEL=/home    /home   ext2   defaults,usrquota,grpquota  1 2

Reboot the server after the above change.

2. Initial quota check on Linux filesystem using quotacheck

Once you’ve enabled disk quota check on the filesystem, collect all quota information initially as shown below.

# quotacheck -avug

quotacheck: Scanning /dev/sda3 [/home] done

quotacheck: Checked 5182 directories and 31566 files

quotacheck: Old file not found.

quotacheck: Old file not found.

In the above command:

a: Check all quota-enabled filesystem

v: Verbose mode

u: Check for user disk quota

g: Check for group disk quota

The above command will create a aquota file for user and group under the filesystem directory as shown below.

# ls -l /home/

-rw——-    1 root     root        11264 Jun 21 14:49 aquota.user

-rw——-    1 root     root        11264 Jun 21 14:49 aquota.group

3. Assign disk quota to a user using edquota command

Use the edquota command as shown below, to edit the quota information for a specific user.

For example, to change the disk quota for user ‘ramesh’, use edquota command, which will open the soft, hard limit values in an editor as shown below.

# edquota ramesh

Disk quotas for user ramesh (uid 500):

Filesystem           blocks       soft       hard     inodes     soft     hard

/dev/sda3           1419352          0          0       1686        0        0

Once the edquota command opens the quota settings for the specific user in a editor, you can set the following limits:

soft and hard limit for disk quota size for the particular user.

soft and hard limit for the total number of inodes that are allowed for the particular user.

4. Report the disk quota usage for users and group using repquota

Use the repquota command as shown below to report the disk quota usage for the users and groups.

# repquota /home

*** Report for user quotas on device /dev/sda3

Block grace time: 7days; Inode grace time: 7days

Block limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace

———————————————————————-

root      —  566488       0       0           5401     0     0

nobody    —    1448       0       0             30     0     0

ramesh    — 1419352       0       0           1686     0     0

john      —   26604       0       0            172     0     0

5. Add quotacheck to daily cron job

Add the quotacheck to the daily cron job. Create a quotacheck file as shown below under the /etc/cron.daily directory, that will run the quotacheck command everyday. This will send the output of the quotacheck command to root email address.

# cat /etc/cron.daily/quotacheck

quotacheck –avug

How to scan new FC LUNS and SCSI disks in Linux ?

How to scan new FC LUNS and  SCSI disks in Redhat Linux without rebooting the server?  Most of the Linux beginners have wondering how to do this and this article will be for them.It may look like very simple as we perform this in daily operation to scan luns but system has many work to do in background when you execute storage scanning commands. Redhat says this type of scan can be distributive,since it can cause delays while I/O operation timeout and remove devices unexpectedly from OS.So perform this scan when really you want to scan the disks and LUNS.

Scanning FC-LUN’s in Redhat Linux

1.First find out how many disks are visible in “fdisk -l” .

# fdisk -l 2>/dev/null | egrep ‘^Disk’ | egrep -v ‘dm-‘ | wc -l

2.Find out how many host bus adapter configured in the Linux box.you can use “systool -fc_host -v” to verify available FC in the system.

# ls /sys/class/fc_host
host0  host1

In this case,you need to scan host0 & host1 HBA.

3.If the system virtual memory is too low ,then do not proceed further.If you have enough free virtual memory,then you can proceed with below command to scan new LUNS.

# echo “1” > /sys/class/fc_host/host0/issue_lip
# echo “1” > /sys/class/fc_host/host1/issue_lip

Note: You need to monitor the “issue_lip” in /var/log/messages to determine when the scan will complete.This operation is an asynchronous operation.

4.Verify if the new LUN is visible or not by counting the available disks.

# fdisk -l 2>/dev/null | egrep ‘^Disk’ | egrep -v ‘dm-‘ | wc -l

If any new LUNS added ,then you can see more count is more then before scanning the LUNS.

Scanning SCSI DISKS in Redhat Linux

1.Finding the existing disk from fdisk.

[root@mylinz1 ~]# fdisk -l |egrep ‘^Disk’ |egrep -v ‘dm-‘
Disk /dev/sda: 21.5 GB, 21474836480 bytes

2.Find out how many SCSI controller configured.

[root@mylinz1 ~]# ls /sys/class/scsi_host/host
host0 host1 host2

In this case,you need to scan host0,host1 & host2.

3.Scan the SCSI disks using below command.

[root@mylinz1 ~]# echo “- – -” > /sys/class/scsi_host/host0/scan
[root@mylinz1 ~]# echo “- – -” > /sys/class/scsi_host/host1/scan
[root@mylinz1 ~]# echo “- – -” > /sys/class/scsi_host/host2/scan

4.Verify if the new disks are visible or not.

[root@mylinz1 ~]# fdisk -l |egrep ‘^Disk’ |egrep -v ‘dm-‘
Disk /dev/sda: 21.5 GB, 21474836480 bytes
Disk /dev/sdb: 1073 MB, 1073741824 bytes
Disk /dev/sdc: 1073 MB, 1073741824 bytes

From Redhat Linux 5.4 onwards, redhat introduced ”/usr/bin/rescan-scsi-bus.sh” script to scan all the SCSI bus and update the SCSI layer to reflect new devices.

But most of the time,script will not be able to scan new disks and you need go with echo command.

 What does the echo “1” to the issue_lip file do? – SCAN SCSI in Linux?

Question 1:  What will happen if we issue the below command ?
 
# echo “1” > /sys/class/fc_host/host/issue_lip
 
 
Answer : 
 
    This operation performs a Loop Initialization Protocol (LIP) and then scans the interconnect and causes the SCSI layer to be updated to reflect the devices currently on the bus. A LIP is, essentially, a bus reset,  and will cause device addition and removal. This procedure is necessary to configure a new SCSI target on a Fibre Channel interconnect. Bear in mind that issue_lip is an asynchronous operation.
 
    The command may complete before the entire scan has completed. You must monitor /var/log/messages to determine when it is done. The lpfc and qla2xxx drivers support issue_lip
 
 
Question2 : 
 
What will happen if we issue the below command ? what does “- – -” mean in the command?
 
# echo “- – -” > /sys/class/scsi_host/host0/scan
 
 
Answer: 
 
It means that you are echoing a wildcard value of “channel target and lun”, and the operating system will rescan the device path.

SWAP Partition

Linux uses the SWAP space configured on one or more hard drive partitions to store in frequently used programs and data. SWAP space can extend the amount of effective RAM on your system.

Normally, Linux (on a 32bit Intel-style computer) can use a maximum 4GB of SWAP space in partitions no larger than 2GB. This 4GB cab be spread over a maximum of eight partitions. The typical rule of thumb suggests that SWAP space should be two times the amount of RAM.
Example
     1GB physical RAM = 2GB SWAP space
Two method of SWAP partition creating
1.  Fdisk utility
2.  File method
#fdisk –l
/dev/sda1  à boot
/dev/sda2  à /
/dev/sda3  à Linux SWAP
/dev/sda4  à Extended partition
#fdisk /dev/sda
n
+1024M
t
5
82
p
w
#partprobe /dev/sda        or         #partx –a /dev/sda
#reboot
#mkswap –L SWAP /dev/sda5
#swapon /dev/sda5          or         #swapon –a
#vim /etc/fstab
LABEL=SWAP-sda5 swap swap defaults   0 0
Or
/dev/sda5       swap swap defaults   0 0
#mount –a
#swapoff /dev/sda5
Remove entry form “/etc/fstab”
#reboot
Create SWAP space from file method
First create a blank file
#touch /swap
#dd if=/dev/zero of=/swap bs=1M count=100
#mkswap  –L  SWAP  /swap
#swapon /swap
#vim /etc/rc.local
Swapon /swap
Swap run time verify status
#cat /proc/swaps
/dev/sda3  partition  4194296    0    -1
/swap      file       102392                  0      -2