Enable EXT4 quotas on root partition

Enabling quota handled by EXT4 on a root partition is not doable as it needs the device to be unmounted and can only be done if booted from a live disk or alike… Yeah whoever took that decision needs to be punished. I found a script which tunes the FS before it is getting mounted at boot time. Here the script:

#!/bin/bash


cat > /etc/initramfs-tools/scripts/init-premount/ext4_quota <<"EOF"
#!/bin/sh

PREREQ=""

prereqs() {
    echo "$PREREQ"
}

case "$1" in
    prereqs)
        prereqs
        exit 0
        ;;
esac


/sbin/tune2fs -l "${ROOT}" | grep -q features || (echo "no ext4 found in ${ROOT}"; exit 0)
echo "Enabling ext4 quota on ${ROOT} "
/sbin/tune2fs -O quota "$ROOT" || echo "tune2fs: $?"
EOF

chmod 0755 /etc/initramfs-tools/scripts/init-premount/ext4_quota

cat >/etc/initramfs-tools/hooks/tune2fs <<"EOF"
#!/bin/sh

PREREQ=""

prereqs() {
    echo "$PREREQ"
}

case "$1" in
    prereqs)
        prereqs
        exit 0
        ;;
esac

. /usr/share/initramfs-tools/hook-functions
copy_exec /sbin/tune2fs /sbin
EOF

chmod 0755 /etc/initramfs-tools/hooks/tune2fs

update-initramfs -k all -u
rm -v /etc/initramfs-tools/scripts/init-premount/ext4_quota /etc/initramfs-tools/hooks/tune2fs

I found the script over here:

https://anton.dollmaier.name/2024/10/enable-native-filesystem-quotas-in-ext4

Thank you a ton dear Anton!

Enable XFS quota on Rocky Linux 9

First check the quotas are not enabled by command.

# mount | grep xfs

You should see “noquota” in the output

Also check with following command, it will give empty result means that quota is disabled.

# xfs_quota -x -c state

Please add rootflags=uquota in “GRUB_CMDLINE_LINUX” in /etc/sysconfig/grub:

GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet rootflags=uquota"

Then generate grub.cfg in /boot:

# grub2-mkconfig -o /boot/grub2/grub.cfg

Final step update all current kernels:

# grubby --args="rootflags=uquota" --update-kernel=ALL

Check if the quota option is used in /etc/fstab:

UUID=df5462ce-cd8a-417d-a454-7688139cf2228 / xfs defaults,uquota 0 0

Finally reboot your machine. Afterward your mount command should show usrquota.

Source: https://webuzo.com/docs/admin/enable-xfs-quotas/