Friday 9 September 2011

Disk Quotas in Linux

1. Create 4 users as below

          a. Ravi with the default properties
          b. Sunil whose primary group is sales
          c. Tom whose primary group is sales
          d. Rani whose secondary group is sales
2. Create a partition and mount it with users and group quotas enabled.
3. Apply quotas to the user Ravi and the group sales and check.

Create a Group

Example:- To create a group called as sales

 [root@test119 ~]# groupadd sales

Create the Users

Example:- Create users and add some to sales group

[root@test119 ~]# useradd ravi
[root@test119 ~]# useradd -g sales sunil
[root@test119 ~]# useradd -g sales tom
[root@test119 ~]# useradd -G sales tom
[root@test119 ~]# useradd -G sales rani


Create Partition using fdisk

Command:-

[root@test119 ~]# fdisk /dev/sda

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): p

Disk /dev/sda: 40.0 GB, 40016019456 bytes
255 heads, 63 sectors/track, 4865 cylinders, total 78156288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xae04ae04

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    20678655     8241152   83  Linux
/dev/sda3        20678656    31016959     5169152   83  Linux
/dev/sda4        31016960    78155775    23569408    5  Extended
/dev/sda5        31021056    41357311     5168128   83  Linux
/dev/sda6        41359360    47798271     3219456   82  Linux swap / Solaris
/dev/sda7        47800320    54042623     3121152   83  Linux
/dev/sda8        54044672    58238975     2097152   83  Linux

Command (m for help): n
First sector (31019008-78155775, default 31019008): +100M
Value out of range.
First sector (31019008-78155775, default 31019008):
Using default value 31019008
Last sector, +sectors or +size{K,M,G} (31019008-31021055, default 31021055):
Using default value 31021055
 
Check if the new  Partition has been created

[root@test119 ~]# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 40.0 GB, 40016019456 bytes
255 heads, 63 sectors/track, 4865 cylinders, total 78156288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xae04ae04

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    20678655     8241152   83  Linux
/dev/sda3        20678656    31016959     5169152   83  Linux
/dev/sda4        31016960    78155775    23569408    5  Extended
/dev/sda5        31021056    41357311     5168128   83  Linux
/dev/sda6        41359360    47798271     3219456   82  Linux swap / Solaris
/dev/sda7        47800320    54042623     3121152   83  Linux
/dev/sda8        54044672    58238975     2097152   83  Linux
/dev/sda9        31019008    31021055        1024   83  Linux

Partition table entries are not in disk order

Note:- Here i dont have free space in My Hard Disk. So i was took default space.

Saving the Partitions

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource                                              busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)

To update the kernal without restarting the system

Command:

[root@test119 ~]# partprobe /dev/sda


Format the Partition in Linux

[root@test119 ~]# mkfs.ext3 /dev/sda9

Mounting the Partition with user and group quotas enabled

Syntax:

mount <option> <arguments> <partition name> <mount poin dir>

Example:- To Mount the 9th Partition on a directory /mntpoint with user and group quotas enabled

[root@test119 ~]# mkdir /mntpoint
[root@test119 ~]# mount -o usrquota,grpquota /dev/sda9 /mntpoint/

To view mounted partitions

command:-

[root@test119 ~]# mount
/dev/sda8 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /home type ext4 (rw)
/dev/sda5 on /opt type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda7 on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sda9 on /mntpoint type ext2 (rw,usrquota,grpquota)


Apply full permissions on the mount point


Example:-


[root@test119 ~]# chmod 777 /mntpoint


Create the quota database files


Syntax:-

[root@localhost~]# quotacheck <options> <mount point>


Options:
-c create                           -g -- group
-u -- user                          -v -- verbose

Example:-

[root@test119 ~]# quotacheck -cugv /mntpoint/

Check if the quota database file aquota.group and aquota.user has been created

[root@test119 ~]# ls /mntpoint/
aquota.group  aquota.user  lost+found

Check the quota status

Syntax:- 

[root@localhost~]# quotaon <options> <partition>

Example:

[root@test119 ~]# quotaon -p /dev/sda9
group quota on /mntpoint (/dev/sda9) is off
user quota on /mntpoint (/dev/sda9) is off

Turn on Quotas:

[root@test119 ~]# quotaon /dev/sda9

To check the status

[root@test119 ~]# quotaon -p /dev/sda9
group quota on /mntpoint (/dev/sda9) is on
user quota on /mntpoint (/dev/sda9) is on

Apply Quota for the users:

Example:- User ravi can create 5 files or directories after which he gets  a warning message and he should not be allowed to create more than 7 files or directories

[root@test119 ~]# edquota -u ravi

Disk quotas for user ravi (uid 502):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda9                         0           0          0          0              5        7

:wq!

To check

Example:

[root@test119 ~]# su - ravi
[ravi@test119 ~]$ cd /mntpoint/
[ravi@test119 mntpoint]$ touch file1 file2 file3 file4 file5
[ravi@test119 mntpoint]$ touch file6
[ravi@test119 mntpoint]$ touch file7
[ravi@test119 mntpoint]$ touch file8
touch: cannot touch `file8': Disk quota exceeded

[ravi@test119 mntpoint]$ ls
aquota.group  aquota.user  file1  file2  file3  file4  file5  file6  file7  lost+found





 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews