Ah, yes, demonstration time.
We're going to look at how to enable quotas,
enabling quotas on our root file system,
setting quotas, and reporting on quota utilization.
So come on, let's find that command line.
And here we are on the glorious command line.
Look at those wonderful pixels.
We're going to go through and take a look at our root file system,
and we're going to be editing our fstab file to put those mount options in.
So when we take a look as we open up the file,
we can see then the root file system.
It's the top line.
Just make sure you can identify your own root file system.
And we can see our mount options are currently set at the defaults.
It's this that we want to change.
We can go into our insert mode and just remove the word defaults,
and we're going to add in usrquota.
I can then comma separate my options and add in group quota,
grpquota, if I want, but I'm just going to be using usrquota.
With this done, I can go through and save my change,
and, of course, saving the changes won't have any effect other than well,
saving the changes to the file.
If we go through and look at our current mount options,
I can do this as a standard user, so mount ‑t ext4 and let's remove that stray x.
We can see that we've got the current mount options.
We don't see the new mount options.
Now to be able to establish the new options,
obviously, we could reboot, but we can also remount our file system,
so sudo mount ‑o, for an option because it's currently mounted,
and we're going to put in the option remount.
We're not putting in any other options.
The rest can be read from the fstab file,
and we've got then the file system root at the end.
Now when we go back and reexamine then our mount command,
we can see then that we've both got quota support and our usrquota support.
But don't forget, we could have that third option, grpquota.
So underlying, we need the quota system,
but then we have user and/or group quotas.
When I look at the root file system,
the root of that partition that we've enabled for quotas,
we don't see our quota databases.
We established them with quotacheck,
and we can then go through and specify ‑u and/or ‑g for groups,
and we're also using the option ‑m so we don't remount the file
system as read only to read what space is in use.
Again, for the root file system, and that will have created our databases.
And we can report and restrict usage from space shown in these databases.
We've got the aquota.user, but obviously,
there would be an aquota.group for our group restrictions.
Next up, we're going to list our kernel modules.
We probably won't have any modules supporting quotas at the moment.
We've only just installed them, but if I do an lsmod and grep for quota,
then the output is empty.
So as long as we spell quota right, then our search is coming back correct.
We don't have any of our modules loaded.
Now we could reboot,
and that would then detect that we've got quotas enabled on
our root file system or any file system.
But to save the reboot, we can go through and load them.
We've got two versions, v1 and v2.
We might as well load both, although probably we won't be needing the v1.
But with both of those loaded, if we go and take a look now at our lsmod,
when we go through and search for quota,
we can see now that we've got three modules loaded,
v1 and v2, and v2 also loaded the quota_tree module.
So you can just see then that we get a little bit more
complex as our version numbers increase.
The last thing that we need to do is to make sure
then that we enable our quotas.
Again, we wouldn't need to do this if we had done a reboot,
but sudo quotaon ‑v,
for verbose so we get a little bit of feedback for the root file system,
and the verbosity there is now showing me that sda1 is enabled for user quotas.
Obviously, we'd have group quotas if they were enabled as well.
Now we are doing a good job of this, but we're not quite finished yet.
We've got our quota databases,
and we can report then on the space used by our users.
And we do that with repquota.
We just use ‑u for our users.
We could use ‑g for groups, ‑a for all partitions.
We can see and I'm focusing mainly on the bottom element,
but that's listing our users and how much space.
By default though, we're seeing it in the number of blocks as being used,
so it doesn't really help me too much.
We can see later that I can use ‑s for human readable format,
so it's much easier to understand.
But we're able to implement our limits based on the size or
the number of files that are in place.
To set those limitations, we would use setquota or we could use edquota,
which would open up a file for us, but setquota ‑u for our user.
We've got a user account called ubuntu.
I'm going to use that user account.
And we can go through and specify, first of all, the soft limit.
The soft limit can be exceeded, but only for our grace period.
The default grace period is seven days.
If I go through then and put a hard limit,
the hard limit I'm setting to 200 M, cannot be exceeded.
And we can then go through and put the limits on the inodes,
the number of files.
I'm not limiting the number of files, only the space.
Now we set for the user and the space they're allowed,
but we also have to include, of course, the partition,
so it's a partition route.
And that quota now is set.
With our quotas in place, we're able to report on it now.
Again, just going back to our repquota that we saw before,
we can go through and put in our user, and we can go through and specify for all.
And we can see now when we take a look at our ubuntu user,
it's the only user with the restrictions.
But again, if we're not using the option ‑s,
we see it in the size of 1 K blocks.
So again, we've got to kind of do the calculations ourselves.
But as we'll see, another way of reporting,
if I use sudo and quota, I can put verbose on,
but the important option here is the s, so we see a human readable size.
I can do this with repquota as well.
But for my user ubuntu, we can see now the space being used is 20 K,
and we've got a quota limit of 150 M, which is my soft and 200 M,
which is my hard limit.
Remember, the soft limit I can exceed, but only for the grace period.
The grace period defaults to seven days.
But if we feel that's too much,
there's nothing stopping us changing the grace period.
Now it is a very simple matter to be able to set our grace period,
and we do that with our setquota command,
again elevated, so sudo and setquota.
We use the option ‑t for our time limit,
and we're going to specify 86,400, and that's the number of seconds.
Don't worry, it's not the number of days.
So 86,400 for our blog limit and 86,400 for our inode limit.
So this then allows us to exceed our soft limit for this amount of time.
Again, we have the root file system in as the last option.
With that in place,
if we go through and take a look at our sudo and we can
go through and look at our repquota, but this time,
if we use the option ‑s,
we're going to see our space in human readable format for our root file system.
And as we go through and take a look, our Block grace time is 24 hours,
our inode grace time is 24 hours.
We also see our ubuntu space as being 20 K in use with a soft
limit of 150 M and a hard limit of 200 M.
We don't see anything in the grace period because
we're not into the grace period.
The grace period in the table shows me how long I have left in my grace period.
To go through and see how we can see that, we need to log in as our ubuntu user.
So we're going to use a sudo and su‑ ubuntu.
We get a warning saying there are better ways to do this,
but don't worry so much.
But I can then go through and clear out my screen,
and I'm just going to use a simple fallocate command
to create relatively large files.
I'm going to set the length, so ‑l, to be 100 M.
And we'll give it a name, such as file1.
That's a great name for a file, isn't it?
Our ubuntu user also has sudo privileges,
so I can stay as my ubuntu account here.
And I can go back and take a look and report on our usage.
So we can use sudo and if we just want to look at it for a single user,
we can then go through into quota ‑v, verbose,
in human readable format for our ubuntu user.
And we can then go through and see now that we're 101 M in use,
but we haven't exceeded any of our limits.
So let's go through and add more space.
So if we go to file2 and we're about 101 M or so before, weren't we?
So let's put 60 M, so that's going to exceed my soft limit.
If I go back and report now, we see the * against my space,
or the ubuntu space, and we can see now the grace period has started to kick in.
So we can really see that I'm allowed to continue
adding data for another 24 hours, but if I get to 150 M,
it's going to stop me straight away.
So let's prove then that the grace period only applies to
our soft limit by adding more space.
So as I go through, we'll consume more space.
We can go to file3, and now we can see that our disk quota has been exceeded.
And it's these sort of queries from users that we've got to be
able to deal with and report on the quota and let them know they need to tidy up some of their space.