Lab 7b Implenting

Disk Quotas

Aims

1. To implement disk quotas for a Linux server

Setting up disk quotas using ext4 (/opt filesystem)

The basic steps are:

1. Edit /etc/fstab and add the option to turn on user quotas (usrquota) for the opt directory filesystem (/opt). Be very careful with this step, as a corrupted fstab file will prevent your system from booting normally. As a safeguard, make a copy of /etc/fstab, calling it, for example, /etc/fstab.bak. This will make recovery easier.

2. Remount the filesystem so that the new options from fstab take effect. A useful command to remount a filesystem when you have changes the options is below (for the /opt filesystem in this case):

mount –o remount /opt

3. Run the quotacheck command for the /opt filesystem.

4. Turn quotas on with the quotaon command (this command needs an argument – read the man entry if in doubt)

5. Use edquota to edit peter's disk quota. For block usage, set a soft limit (warning) at 400KB and a hard limit at 500KB. You do not need to set limits on inodes (which is a limit on the number of files a user can create).

Test that your disk quotas are working by logging in as the user peter, and trying to store more than 500KB in the /opt directory (copy a large file from somewhere else). You may need to create a directory under /opt and make it so that

peter can write to that directory (either make him the owner, or change the directory permission). Hint: an easy way to create a large file is to use the dd command, for example, dd if=/dev/zero of=junk bs=1024 count=600 You can also run the quota –v command while logged in as peter to show the quota values for peter.

As root, run repquota to generate a quota report for the /opt filesystem.

Carefully document the process you followed, including all of the options to the commands. Also document your testing procedure, and what messages the system showed when the user exceeded his soft limit and his hard limit.

Steps - disk quotas

Be very cautious with this configuration as any error to the config file will affect the login and won't be able to recover unless the file error is rectified from the single user interface mode.


Before we begin let's do a backup of the default config file, in case we will need it later.

# cp /etc/fstab / /etc/fstab_backup

Edit fstab file

# vim /etc/fstab

On the /opt directory line of the file add usrquota should look like this

/dev/sdb1 /opt ext4 defaults, usrquota 0 0

:wq

Then we use remount the filesystem for the new options from fstab to take effect.

# mount -o remount /opt

Check our current mount

# df -h

Quota check for opt filesystem

# quotacheck /opt //no error: everything is fine so far//

Now enable the quota option

# quotaon

# quotaon -auv

Edit peter’s disk quota

# edquota -u peter

In the file change the soft properties number to 400 and for hard 500 limit

:wq