You are on page 1of 8

Hands-on Lab

Managing
Disk Quotas
Contents Related Courses

Create a Partition 1
LPIC-1: System
Create Filesystem 1 Administrator -
Exam 101
Mount the Partition 1

Make the Mount Persistent 2


Related Videos
Creating User Quotas 3

Quota Reporting 5 Manage Disk


Quotas
Grace Period 5

Turning Quotas On 6
Video
Review 6

Need Help?

Linux Academy
Community

... and you can


always send in a
support ticket on
our website to talk
Lab Connection Information to an instructor!

• Labs may take up to five minutes to build


• The IP address of your server is located on the Live!
Lab page
• Username: linuxacademy
• Password: 123456
• Root Password: 123456
Managing Disk Quotas Linux Academy

In this lab, we’ll learn how to create partitions and filesystems to which we can apply user and group usage
quotas.

To get started, log in to one of the servers using the credentials provided on the Hands-on Lab page. Many
of the commands in this lab require elevated privileges, so be sure to switch to the root user.

Create a Partition
Let’s start by listing all of our partition tables:

[root@linuxacademy] fdisk -l

Here we’ll see a list of our available disks and their partitions. We’ll be focusing on the three ~20GB disks
that don’t have partitions created yet. We’ll choose one of these and create a partition:

[root@linuxacademy] fdisk /dev/xvdf

At the command prompt, enter n for new. Enter p to create a primary partition, and use partition number 1.
Press enter when prompted for First cylinder to accept the default value of 1. Finally, enter +2G for the Last
cylinder to specify a 2GB partition.

When the command prompt is shown again, enter w for write to save the changes to the partition table.

We can check that the partition was created by listing the partition table for the disk we chose above:

[root@linuxacademy] fdisk -l /dev/xvdf

Create Filesystem
Next, we’ll format the disk partition we just created, using the ext4 filesystem type:

[root@linuxacademy] mkfs -t ext4 /dev/xvdf1

Mount the Partition


Before we can mount the partition, we need to create a mount point:

[root@linuxacademy] mkdir /mnt/part1

-1-
Managing Disk Quotas Linux Academy

Next, we’ll mount it:

[root@linuxacademy] mount -t ext4 /dev/xvdf1 /mnt/part1

We can list the contents of the mount point directory to ensure the lost+found directory has been created
within it:

[root@linuxacademy] ls -al /mnt/part1


total 24
drwxr-xr-x 3 root root 4096 May 18 15:30 .
drwxr-xr-x 3 root root 4096 May 18 15:33 ..
drwx------ 2 root root 16384 May 18 15:30 lost+found

We can also use df to check that it’s been properly mounted:

[root@linuxacademy] df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 5.8G 1.4G 4.1G 26% /
tmpfs 299M 0 299M 0% /dev/shm
/dev/xvdf1 2.0G 68M 1.9G 4% /mnt/part1

Make the Mount Persistent


Now that the disk is mounted, we can make it a persistent mount. First, we’ll want to grab it’s UUID. We
can use either of the following two commands to do so:

[root@linuxacademy] ls -al /dev/disk/by-uuid


[root@linuxacademy] blkid

Copy the partition’s UUID to the clipboard, and open the fstab file:

[root@linuxacademy] vim /etc/fstab

Add the following configuration for the disk:

# mount the quota disk


UUID=98862d6b-a6c8-44eb-9b20-59a38937a420 /mnt/part1 ext4
defaults,usrquota,grpquota 1 2

Save and exit the file once this has been added. To enable the option to create quotas, however, we’ll need
to unmount and remount the partition:

[root@linuxacademy] umount /mnt/part1

-2-
Managing Disk Quotas Linux Academy

[root@linuxacademy] mount -a

Creating User Quotas


We can set disk quotas for our new partition on a per-user basis. To do this, let’s first create a new user:

[root@linuxacademy] adduser myuser


[root@linuxacademy] passwd myuser

Exit the root shell and check that the new user was created successfully:

[root@linuxacademy] exit
[linuxacademy@linuxacademy] su myuser -

Switch back to the root user:

[myuser@linuxacademy] exit

[linuxacademy@linuxacademy] sudo su -

In order to provide access to all users, we’ll need to change the permissions on our mount point directory:

[root@linuxacademy] cd /mnt
[root@linuxacademy] chmod 777 part1
[root@linuxacademy] ll
total 4
drwxrwxrwx 3 root root 4096 May 19 11:06 part1

Next, we’ll create quota files so we can enforce usage quotas of our own:

[root@linuxacademy] quotacheck -avugc

We can see that the quota files were created by listing the contents of the directory:

[root@linuxacademy] ls -al /mnt/part1


total 40
drwxrwxrwx 3 root root 4096 May 19 11:19 .
drwxr-xr-x 3 root root 4096 May 19 11:06 ..
-rw------- 1 root root 6144 May 19 11:19 aquota.group
-rw------- 1 root root 6144 May 19 11:19 aquota.user
drwx------ 2 root root 16384 May 19 11:06 lost+found

-3-
Managing Disk Quotas Linux Academy

We can now edit the quota files for a particular user:

[root@linuxacademy] edquota -u myuser

In this file, make the following changes:

Filesystem blocks soft hard inodes


soft hard
/dev/xvdf1 0 10000 11000 0
0 0

Save and exit the file. The quota now needs to be turned on for the filesystem we configured. We can check
the status to confirm this:

[root@linuxacademy] quotaon -p /mnt/part1


group quota on /mnt/part1 (/dev/xvdf1) is off
user quota on /mnt/part1 (/dev/xvdf1) is off

We can use the quotaon command with different options to turn the quota on:

[root@linuxacademy] quotaon -uagv


/dev/xvdf1 [/mnt/part1]: group quotas turned on
/dev/xvdf1 [/mnt/part1]: user quotas turned on

If we check the user’s quota, we’ll see none because the user hasn’t created any files yet:

[root@linuxacademy] quota myuser


Disk quotas for user myuser (uid 503): none

Let’s change to the myuser account to create some files and test the quota:

[root@linuxacademy] exit
[linuxacademy@linuxacademy] su myuser -
[myuser@linuxacademy] cd /mnt/part1
[myuser@linuxacademy] echo “hi” > test.txt

Now when we use the quota command as the user, we can see information about quotas and usage:

[myuser@linuxacademy] quota
Disk quotas for user myuser (uid 503):
Filesystem blocks quota limit grace files quota limit
grace
/dev/xvdf1 4 10000 11000 1 0 0

We can test that the quota is being enforced by creating a backup of the /etc directory, which should
-4-
Managing Disk Quotas Linux Academy

exceed the allowed size:

[root@linuxacademy] mkdir bkup


[root@linuxacademy] cd bkup
[root@linuxacademy] cp -rf /etc/* .

In the output, we’ll see that some directories are not created due to the quota being exceeded. We can check
the disk usage to see why:

[root@linuxacademy] du -sh .
11M .

If we try to create another file, we’ll be unable to do so since the quota has been exceeded:

[root@linuxacademy] echo “hello” > hello.txt


bash: echo: write error: Disk quota exceeded

However, we can delete some of our directories to free up space, taking our disk usage back within the
quota:

[root@linuxacademy] rm -rf rpm


[root@linuxacademy] rm -rf rsyslog.d
[root@linuxacademy] rm -rf security
[root@linuxacademy] rm -rf selinux
[root@linuxacademy] du -sh .
6.1M .
[root@linuxacademy] quota
Disk quotas for user myuser (uid 503):
Filesystem blocks quota limit grace files quota limit
grace
/dev/xvdf1 6164 10000 11000 854 0 0

Quota Reporting
Sometimes we may need to provide a report on quota usage for all users. We can do so with the following:

[root@linuxacademy] repquota -a

Grace Period
The soft limits we’ve seen in quota configurations can be controlled by a grace period. To edit the grace
period:

-5-
Managing Disk Quotas Linux Academy

[root@linuxacademy] edquota -t

Turning Quotas On
Remember that quotas must be turned on upon boot. Rather than scripting this manually, we can edit our
rc.local file to enable this behavior:

[root@linuxacademy] vim /etc/rc.d/rc.local

Add the folling line:

quotaon -uagv

This will be the final process to run before the login prompt is shown on boot. By this point in the boot, our
disks will be mounted, and the quotas will be turned on before users are able to access the system.

Review
In this lab, you learned how to create a new disk partition, format it, and mount it to the system. You also
learned to create quotas and check disk usage for system users.

Congratulations! You’ve completed the lab on managing disk quotas!

-6-

You might also like