1

How do I accomplish setting up project quota for my live root folder being ext4 on Ubuntu 18.04?

Documentation specific to project quota on the ext4 filesystem is basically non-existent and I tried this:

  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.
  5. Putting rootflags=quota into GRUB_CMDLINE_LINUX="... rootflags=quota" running update-grub and restarting did show quota and usrquota being enabled on root, but it does not work with prjquota or pquota or project being set as an rootflag

I need this for the DIR storage backend of LXD to be able to limit container storage size. What else can I try?

2
  • 1
    tried several things already What, specifically, was tried, and what was the response for each? Web links to the sources of what you tried would also be welcome. – K7AAY Apr 6 '20 at 22:00
  • 1
    I put the 2 major steps I took and the responses into the question – michacassola Apr 7 '20 at 11:24
0

I was told running tune2fs -O project -Q prjquota /dev/sdaX is absolutely essential to enable Project Quota on a device. So I searched for a solution that does not require switching off or using a live-cd as this requires too much time and does not always work well in my experience with my VPS provider. And I also hoped that I can turn the steps into a script, which did not work out so far.

Thanks to another questions I was able to put together a solution that worked for me on Ubuntu 18.04. You do need ca. 4GB of RAM to do this (and of course a kernel after version 4.4).

Sources:

1. Make a RAMdisk filesystem

mkdir /tmp/tmproot
mount none /tmp/tmproot -t tmpfs -o rw
mkdir /tmp/tmproot/{proc,oldroot,sys}
cp -a /dev /tmp/tmproot/dev
cp -ax /{bin,etc,opt,run,usr,home,mnt,sbin,lib,lib64,var,root,srv} /tmp/tmproot/

2. Switch root to the new RAMdisk filesystem

cd /tmp/tmproot
unshare -m
pivot_root /tmp/tmproot/ /tmp/tmproot/oldroot
mount none /proc -t proc
mount none /sys -t sysfs
mount none /dev/pts -t devpts

3. Restart SSH on another port than 22 and reconnect with another session

nano /etc/ssh/sshd_config
  • Change the port to 2211

  • Restart SSH with /usr/sbin/sshd -D &

  • Connect again from 2211

4. Kill processes using /oldroot or /dev/sdaX

fuser -km /oldroot
fuser -km /dev/sdaX

5. Unmount /dev/sdaX and apply the project quota feature

umount -l /dev/sdaX
tune2fs -O project -Q prjquota /dev/sdaX

6. Mount with Project Quota

mount /dev/sda2 -o prjquota /oldroot

7. Putting things back

pivot_root /oldroot /oldroot/tmp/tmproot
umount /tmp/tmproot/proc
mount none /proc -t proc
cp -ax /tmp/tmproot/dev/* /dev/
mount /dev/sda1 /boot  ### This might be different for you
reboot -f

8. Turn quota on after reboot

apt install quota -y
quotaon -Pv -F vfsv1 /

9. Check if quota is on on root

repquota -Ps /

10. Make it persistent

  • Put prjquota into the options of root in /etc/fstab

Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.