EXT4 Quota
Explore this Page
- Overview
- Requirements
- Enabling EXT4 Quota
- Managing and Modifying EXT4 Quota
- Modifying the EXT4 Quota Limits
- Limitations
Overview
To enforce storage limits on Local PV Hostpath volumes held on an ext4 filesystem, enable and configure EXT4 project quotas. This document outlines the prerequisites, filesystem configuration, and StorageClass setup required to enable EXT4 quotas.
Additionally, it describes how to create Persistent Volume Claims (PVCs), verify quota enforcement, adjust quota limits when necessary, and remove a project quota from a volume.
By following the steps in this document, you will be able to enable, configure, and manage EXT4 Quotas for deployments across various Linux distributions, including Ubuntu, Debian, RHEL, CentOS, and Fedora.
EXT4 project quotas and XFS project quotas serve the same purpose for different filesystems. Use the configuration that matches the filesystem holding your BasePath.
Requirements
To use EXT4 Quotas with Local PV Hostpath, ensure the following requirements are fulfilled:
- Install the
quotaande2fsprogspackages. - Confirm that the filesystem type is ext4. If no ext4 filesystem is available, refer to Creating an EXT4 Filesystem on a Loop Device.
- Enable the
projectandquotafeatures on the filesystem. - Configure the filesystem to use the
prjquotamount option.
Unlike XFS, an ext4 filesystem requires the project and quota features to be enabled before project quotas can be used. Filesystems created by older versions of mkfs.ext4 may not have them.
Installing the quota and e2fsprogs Packages
The quota package provides the repquota and setquota commands. The e2fsprogs package provides the tune2fs, chattr, and lsattr commands.
For Ubuntu/Debian Systems
sudo apt-get update
sudo apt-get install -y quota e2fsprogs
For RHEL/CentOS Systems
For Fedora Systems
Checking the Filesystem Type
Verify whether the filesystem of the hostPath directory is ext4. The default hostPath directory is /var/openebs/local. Run the following command to check the filesystem type and identify the device that holds the filesystem:
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme1n1 ext4 8.0G 959M 7.1G 12% /mnt/data
If the command fails because the path does not exist yet, run the following script to determine the filesystem type and device name of the closest existing parent directory:
BASEPATH="/var/openebs/local"
until OUTPUT=$(df -Th $BASEPATH 2> /dev/null)
do
BASEPATH=$(echo "$BASEPATH" | sed 's|\(.*\)/.*|\1|')
done
echo "PATH=${BASEPATH}"
echo "$OUTPUT"
Enabling the Project and Quota Features
Enable the project and quota features on the device that holds the filesystem.
-
Check the features that are currently enabled on the device.
CopyCheck the Enabled Filesystem Featuressudo tune2fs -l /dev/nvme1n1 | grep -i "filesystem features"CopySample OutputFilesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumIn the sample output above,
projectandquotaare not listed, so you must enable them. -
Unmount the filesystem. The features cannot be changed while the filesystem is mounted.
-
Check the filesystem for errors. Do this before you change the filesystem features.
-
Enable the
projectandquotafeatures. -
Verify that the features are enabled.
CopyVerify the Enabled Filesystem Featuressudo tune2fs -l /dev/nvme1n1 | grep -i "filesystem features"CopySample OutputFilesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum quota project
The project feature requires the filesystem to have an inode size of 256 bytes or more. This is the default for mkfs.ext4. A filesystem created with a smaller inode size cannot be converted and must be recreated. Check the inode size with sudo tune2fs -l /dev/nvme1n1 | grep -i "inode size".
Mounting the Filesystem with the prjquota Option
Checking Existing Mount Options
Verify whether the mount options for the device include prjquota.
If the mount options already include prjquota, proceed to Enabling EXT4 Quota. If not, continue with the steps for your filesystem.
Root Filesystem
If the filesystem is mounted as the root filesystem (/), enable prjquota through the GRUB configuration.
-
Edit the
/etc/default/grubfile. -
Locate the line that contains the
GRUB_CMDLINE_LINUXvariable.CopyLocate GRUB_CMDLINE_LINUX EntryGRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto net.ifnames=0 console=ttyS0" -
Add
rootflags=prjquotato the end of the string. If therootflagsoption is already present, appendprjquotato its list of options.CopyAdd rootflags=prjquotaGRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto net.ifnames=0 console=ttyS0 rootflags=prjquota" -
Locate the
grub.cfgfile. The path varies by operating system.CopyPossible Locations/boot/grub2/grub.cfg
/boot/efi/EFI/ubuntu/grub.cfg
/boot/efi/EFI/debian/grub.cfg
/boot/efi/EFI/redhat/grub.cfg
/boot/efi/EFI/centos/grub.cfg
/boot/efi/EFI/fedora/grub.cfg -
Create a backup copy of the existing
grub.cfgfile. The sample command uses the path/boot/grub2/grub.cfg. Replace it with the path for your system. -
Generate a new
grub.cfgfile that includes the change. -
Reboot the system.
-
After the system restarts, check the mount options to confirm the change.
Filesystem on a Data Disk
If the filesystem is on a data disk, follow these steps. Replace /dev/nvme1n1 and /mnt/data with your device and mount path.
-
Unmount the filesystem on the data disk.
-
Mount the disk with the
prjquotamount option. -
Verify the mount options.
-
Add the
prjquotaoption to the/etc/fstabfile so that the change persists across reboots.CopyAdd prjquota Option to /etc/fstab FileUUID=9cff3d69-3769-4ad9-8460-9c54050583f9 /mnt/data ext4 defaults,prjquota 0 0
Creating an EXT4 Filesystem on a Loop Device
If no existing device is formatted with an ext4 filesystem that has project quota enabled, you can create one on a loop device. This is useful when the root filesystem cannot be remounted with prjquota, as it allows you to evaluate project quota enforcement without repartitioning a disk.
The following steps create a sparse file, format it with the ext4 filesystem and the required features, and mount it as a loop device at /var/openebs/local.
-
Ensure that the
quotaande2fsprogspackages are installed, as described in Installing the quota and e2fsprogs Packages. -
Create the directory where the filesystem is mounted.
-
Create a sparse file with a maximum size of 1 GiB. Use a size that can accommodate the volumes you intend to provision.
-
Format the sparse file with the ext4 filesystem, enabling the
quotaandprojectfeatures that project quotas require. -
Mount the sparse file as a loop device with project quota enabled. The file is then accessible as the
/var/openebs/localdirectory.CopyMount the Sparse File as a Loop Devicesudo mount -o loop,rw,prjquota ext4.1G /var/openebs/local -
Verify the mount options.
A loop device backed by a sparse file is intended for evaluation and testing. Add the mount to /etc/fstab if it must persist across reboots.
Enabling EXT4 Quota
Complete the Requirements before you proceed. The filesystem that holds the BasePath must have the project and quota features enabled, and must be mounted with the prjquota option.
Creating a StorageClass
Create a hostpath StorageClass with the EXT4Quota configuration option. This enables EXT4 project quota for the specified base path and storage type.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: puls8-hostpath-ext4
annotations:
openebs.io/cas-type: local
cas.openebs.io/config: |
- name: StorageType
value: "hostpath"
- name: BasePath
value: "/var/openebs/local/"
- name: EXT4Quota
enabled: "true"
provisioner: openebs.io/local
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
Advanced EXT4 Quota Configuration
For advanced configuration, set the softLimitGrace and hardLimitGrace parameters. These define the storage capacity limits beyond the Persistent Volume (PV) storage request.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: puls8-hostpath-ext4
annotations:
openebs.io/cas-type: local
cas.openebs.io/config: |
- name: StorageType
value: "hostpath"
- name: BasePath
value: "/var/openebs/local/"
- name: EXT4Quota
enabled: "true"
data:
softLimitGrace: "0%"
hardLimitGrace: "0%"
provisioner: openebs.io/local
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
softLimitGraceandhardLimitGraceare used together with the PV storage request to determine the soft and hard limits of the quota.- Each limit is calculated as Size of PV storage request * (1 + LimitGrace%).
- If no values are specified, the default for both is
0%, which limits the storage capacity to the PV storage request value. - For example, for a PV of 100Gi capacity with
softLimitGrace: "90%"andhardLimitGrace: "100%", the soft limit is 190Gi and the hard limit is 200Gi. - You can use either
softLimitGraceorhardLimitGraceindependently, based on your requirements. Refer to the setquota documentation for more information about soft and hard limits.
To enable EXT4 Quota on the default hostpath StorageClass that the Helm chart creates, use the openebs.localpv-provisioner.hostpathClass.ext4Quota values, which accept enabled, softLimitGrace, and hardLimitGrace.
Creating a PVC
-
Create a PVC that uses the name of the StorageClass.
CopyPVC using EXT4 Quota StorageClasskind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-hostpath-ext4
spec:
storageClassName: puls8-hostpath-ext4
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5GiAt this stage, the PVC remains in the
Pendingstate until the volume is mounted. -
Verify the PVC status.
CopySample OutputNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
local-hostpath-ext4 Pending puls8-hostpath-ext4 21s
Mounting the Volume
-
Mount the volume to the application pod container. The following sample uses a BusyBox pod.
CopySample Pod Mounting the VolumeapiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
volumes:
- name: local-storage
persistentVolumeClaim:
claimName: local-hostpath-ext4
containers:
- name: busybox
image: busybox
command:
- sh
- -c
- 'while true; do echo "`date` [`hostname`] Hello from Local PV Hostpath." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done'
volumeMounts:
- mountPath: /mnt/store
name: local-storageThe PVC status changes to
Boundonce the volume is mounted, and the quota is applied. -
Verify that the EXT4 project quota is applied. Run the command on the node where the volume was provisioned.
CopySample Output*** Report for project quotas on device /dev/nvme1n1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Project used soft hard grace used soft hard grace
----------------------------------------------------------------------
#0 -- 20 0 0 2 0 0
#1 -- 0 5242880 5242880 1 0 0 -
Confirm the project ID that was assigned to the volume directory.
CopyCheck the Project ID of the Volume Directorysudo lsattr -pd /var/openebs/local/pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425CopySample Output1 --------------P------ /var/openebs/local/pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425
Managing and Modifying EXT4 Quota
Identifying the BasePath Directory
Make a note of the BasePath directory used for the hostpath volume. The default is /var/openebs/local. Retrieve the BasePath from the StorageClass with the following command:
Locating the Node
Log in to the node where the volume exists. Determine the node by describing the Persistent Volume (PV) resource.
-
Retrieve the PVC details.
CopySample OutputNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
demo-vol-demo-0 Bound pvc-0365904e-0add-45ec-9b4e-f4080929d6cd 2Gi RWO puls8-hostpath-ext4 21s -
Describe the PV to find the node and the volume path.
CopySample OutputName: pvc-0365904e-0add-45ec-9b4e-f4080929d6cd
Labels: openebs.io/cas-type=local-hostpath
Annotations: pv.kubernetes.io/provisioned-by: openebs.io/local
StorageClass: puls8-hostpath-ext4
Status: Bound
Claim: demo/demo-vol-demo-0
Reclaim Policy: Delete
Access Modes: RWO
VolumeMode: Filesystem
Capacity: 2Gi
Node Affinity:
Required Terms:
Term 0: kubernetes.io/hostname in [storage-node-2]
Source:
Type: LocalVolume (a persistent volume backed by local storage on a node)
Path: /var/openebs/local/pvc-0365904e-0add-45ec-9b4e-f4080929d6cd -
Identify the node name.
Modifying the EXT4 Quota Limits
You can change the soft limit, the hard limit, or both, for an existing hostpath volume that has EXT4 project quota enabled. To remove the project quota entirely, refer to Removing the Project Quota.
Changing Quota Limits
Run the following commands on the node where the hostpath volume exists.
-
Make a note of the project ID.
CopySample Output*** Report for project quotas on device /dev/nvme1n1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Project used soft hard grace used soft hard grace
----------------------------------------------------------------------
#0 -- 20 0 0 2 0 0
#1 -- 1048576 2097152 2097152 1 0 0You can also read the project ID directly from the volume directory.
CopyRead the Project ID from the Volume Directorysudo lsattr -pd /var/openebs/local/pvc-0365904e-0add-45ec-9b4e-f4080929d6cd -
Modify the quota limits. The arguments are the project ID, the block soft limit, the block hard limit, the inode soft limit, and the inode hard limit, followed by the filesystem. The block limits are expressed in kilobytes.
The command above sets a soft limit of 3 GiB (3145728 KB) and a hard limit of 5 GiB (5242880 KB) for project ID 1. The inode limits are set to 0, which means they are unlimited.
-
Verify the updated limits.
CopySample Output*** Report for project quotas on device /dev/nvme1n1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Project used soft hard grace used soft hard grace
----------------------------------------------------------------------
#0 -- 20 0 0 2 0 0
#1 -- 1048576 3145728 5242880 1 0 0
Removing the Project Quota
To remove the EXT4 project quota from a volume, follow these steps.
-
Make a note of the project ID.
-
Set the project limits to 0, which removes the quota limits.
The command above applies to project ID 1 at the directory path
/var/openebs/local. -
Clear the project ID and the project inheritance attribute from the volume directory.
CopyClear the Project ID and Inheritance Attributesudo chattr -P -p 0 /var/openebs/local/pvc-0365904e-0add-45ec-9b4e-f4080929d6cd -
Verify the changes.
CopySample Output*** Report for project quotas on device /dev/nvme1n1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Project used soft hard grace used soft hard grace
----------------------------------------------------------------------
#0 -- 1048596 0 0 3 0 0
Limitations
Quota resizing is not supported: If you need to adjust quotas, you must manually modify the soft and hard limits as shown above.
Learn More