How do I set up the project quota needed for limiting container storage size for the dir backend on Ubuntu 18.04?

How do I set up the project quota needed for limiting container storage size for the dir backend on Ubuntu 18.04? I also asked the question at Stack Exchange:

  • tune2fs -O project -Q prjquota /dev/sdaX
  • Update /etc/fstab to add the prjquota mount option

The tune2fs must be done when the filesystem isn’t mounted.
If doing the /etc/fstab change live, either reboot or manually add the mount option to your current mount.

1 Like

Thanks! Here the things I tried so far:

  1. Installed Quota with apt install quota -y
  2. Put prjquota into /etc/fstab for the root / and rebooted, filesystem got booted as read-only, no project quota (from here only with prjquota instead of the user and group quotas)
  3. Also find /lib/modules/uname -r -type f -name '*quota_v*.ko*' was run and both kernel modules /lib/modules/4.15.0-96-generic/kernel/fs/quota/quota_v2.ko and /lib/modules/4.15.0-96-generic/kernel/fs/quota/quota_v1.ko were found (from this tutorial)
  4. Put GRUB_CMDLINE_LINUX_DEFAULT="rootflags=prjquota" into /etc/default/grub , ran update-grub and rebooted, machine does not come up anymore

What else can I try?

Did you do the tune2fs part?

No, I can’t as / root is mounted. How do I do this?

root@vps:~# tune2fs -O project -Q prjquota /dev/sda2
tune2fs 1.44.1 (24-Mar-2018)
The quota feature may only be changed when the filesystem is unmounted.

Mount also does not work:

root@vps:~# mount /dev/sda2 -o prjquota,remount /
mount: /: mount point not mounted or bad option.

root@vps:~# mount /dev/sda2 -o prjquota /
mount: /: /dev/sda2 already mounted on /.

You need to do it when it’s not mounted, so either from the initramfs or by booting from an CDROM or USB stick and then enabling the feature from there.

1 Like

You cannot use prjquota as a mount option until you’ve enabled the feature with tune2fs.

1 Like

Researching about initramfs brought me back to GRUB as it is supposed to be connected if I didn’t misunderstand. And doing some more testing did bring results:

rootflags=quota was added to /etc/default/grub

GRUB_CMDLINE_LINUX="... rootflags=quota"

Then update-grub was run.

And after the reboot root@vps:~# cat /proc/mounts | grep ' / ' shows that there is now quota
/dev/sda2 / ext4 rw,relatime,quota,usrquota,errors=remount-ro,data=ordered 0 0

But trying it with pquota or prjquota does not work…

Think it might be a bug in grub2, reported it here.

quota and usrquota have nothing to do with prjquota.

Again, you NEED to run that tune2fs command, there’s just no way around it.
All the other bits you’ve been messing with are for AFTER the tune2fs has been done.

1 Like

Ok, I went the temporary ramdisk way and managed to unmount /dev/sda2.

  • I ran tune2fs -O project -Q prjquota /dev/sda2 which didn’t throw any errors, just the version of the program, so I am quessing it worked.

  • Then I mounted it with the according option mount /dev/sda2 -o prjquota /oldroot. Pivoted back to the real root.

  • Finally I was able to turn on the project quota on /dev/sda2 (installed quota of course)

    root@vps:~# quotaon -Pv -F vfsv1 /
    /dev/sda2 [/]: project quotas turned on
    

    Also repquota is showing the quota is on on /

    root@vps:~# repquota -Ps /
    *** Report for project quotas on device /dev/sda2
    Block grace time: 7days; Inode grace time: 7days
                            Space limits                File limits
    Project         used    soft    hard  grace    used  soft  hard  grace
    ----------------------------------------------------------------------
    #0        --   3670M      0K      0K          66228     0     0  
    

Then we have to specify a profile like this:

sudo lxc profile device add profile-name root disk pool=default path=/ size=5GB

And add it to a container by running:

sudo lxc launch ubuntu:18.04 c2 -p default -p profile-name

And it worked!!! :smiley:

One question though, I get

root@c1:~# df
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sda2        4882812 751956   4130856  16% /
root@c1:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       4.7G  735M  4.0G  16% /

How do I get it to actually 5GB?

Also, can I switch the size on a running container? Can I switch the default profile’s root size?
How to best do that sort of thing?

Use 5GiB instead of 5GB. It’s the old 1000 vs 1024 thing.

1 Like

Hey @stgraber, I answered my question here: https://unix.stackexchange.com/questions/578349/project-quota-on-a-live-root-ext4-filesystem-on-ubuntu-18-04

Would you like me to post a tutorial here as well?

That would be great thanks. I can move it in to the tutorials section.

1 Like

Done. :slight_smile:

Thank you guys @tomp @stgraber for all the guidance!