In this video, Kevn Dankwardt describes the use of disk quotas for users. We setup user quotas and describe soft and hard limits for blocks and inodes.
- [Narrator] Linux provides a disk quota mechanism, that is you can limit how much disk space a user or a group can use. Both disk space and number of files or directories. So you do this to keep users from filling up your whole partition. And that means that your systems, you know, going to run a little more robustly so that if a user uses up all their space, there's still space available for system things and so forth.
XFS has it's own quota mechanism so the commands work with XFS are a little bit different. We'll use ext4 and we'll see how the quota stuff works. So what you'll want to do is mount your partition with the user quota or group quota options on. So that we're checking for quotas. For example, we could mount the sda2 partition on the home directory with the option user quota.
In fact, the home directory is where quotas are usually used because that's where users typically create files. The quotacheck command will do some accounting, look at how much is used by the users. So you run the quotacheck, if you do the c option there it's going to create the files that it uses for checking, and then the u and g there have to do with users and groups.
The quotacheck maybe is a little bit better when the file system is read only so that it's not changing while it's checking. But that's not required. So maybe what you'll do in a cron job is you turn quota off, you do the quotacheck, you do a report and then you turn quotachecking back on. And then that report you can see how things are looking. You can maybe send people messages saying "Hey, you're getting close." You set the quotas with the edquota command.
And there's both hard and soft limits. So the soft limit is a grace limit before they have to free up some stuff. A hard limit is they're not going to be able to use any more space, the system will prevent it right then. So there's a limit for blocks that is how much space, and a limit for inodes, which is the number of files or directories. The number of entries in the file system. You turn quota on for both options and a few other options.
And quota off, and then it would be which file system, like /home. We'll see how that works. So let's look at mounting, enabling, and editing and see what happens when quotas are exceeded. We are guest and we're in our home directory and we've got a few files there. But we'll do quotas on a separate file system. So let's become root, and let's mount with the user quota option a partition.
There we go. And then let's check stuff out and create the files that it needs. So it's created that aquota.user file there. And then let's edit quota for guest. And let's set a soft limit of just five blocks and a hard limit of ten, and for inodes we'll set a soft of 25.
We get 25 files on directories and a hard of 50. So they can temporarily have up to ten blocks used. But once they get the five, then they've got a certain amount of time before they've got to clean up. Similarly, they can have 25 files of directories until they start have a time limit. But they won't be able to do more than 50. Alright.
So we save that out. And we set that quota for guest. And now let's be guest again. And let's go to that directory. And let's try to use up some space. We'll create a file we'll do blocks of one k and we'll do eight of them. So we got a permission denied problem. So how do we fix that? There we go.
Guest didn't have right permission on that directory. So we created an eight k file, there's a couple other things there too. And now let's be rude again and let's do a quotacheck. Okay. And then let's do our repquota.
And what do we got? For guest, they've used nine. Their soft is five. Right. So, the amount of space is almost at the limit. And it says they've only used one inode, so they can create a bunch more. So, let's see. If we try to create more space, we should get an error because we're going to use up our limit. So let's try.
We'll try to make a two k file. And it says it let us. And if we check, oops, got to say where. It says we've exceeded the limit. What's the deal? The deal is we haven't turned on quotas.
So we didn't actually get the system to be checking when we're doing stuff. So let's try to create another file. Now we get the error. So you got to remember to turn on quotas. Alright. So you got to edit the quota, you got to mount with the user quota option, and you got to turn the quota checking on. There you go.
- Partitioning storage
- Creating, mounting, and unmounting file systems
- Formatting file systems
- Making volumes with LVM
- Adding storage security
- Managing swap spaces
- Backing up and recovering Linux storage systems
- Working with networked file systems like NFS and SSHFS