Skip to content

Per-App storage limit

This guide explains how one can set-up disk storage limits for singular or multiple apps

Working with disks can lead to data loss - always have a backup ready

Example

The app lamp1.cloudron.dev should have a 10GB disk storage limitation.

For simplicity the external disk will always be named /dev/sdc.

External EXT4 block storage

Disk that has 10 GB storage

Creating the filesystem

Create the EXT4 file system on the disk:

mkfs.ext4 /dev/sdc

Mounting the disk

Mount the disk to /mnt/lamp1:

# Create the directory for mounting first
mkdir -p /mnt/lamp1
# Mount the device to the directory
mount /dev/sdc /mnt/lamp1

Backup your fstab file

Editing the fstab can be dangerous, always create a backup first!

cp /etc/fstab /etc/fstab_backup_$(date +%d.%m.%Y-%H:%M:%S)

For more details for fstab please read the Arch Wiki - Fstab

Add a fstab entry for /dev/sdc so the disk gets mounted when the server boots:

/dev/sdc /mnt/lamp1 ext4 defaults,noatime,nofail 0 2

Configuring Cloudron and the app

Now we add this disk as a Cloudron Volume - Filesystem Mountpoint.

Filling the fields:

  • Name: lamp1
  • Mount Type: Filesystem Mountpoint
  • Local Directory: /mnt/lamp1

Press "Save".

Now configure the lamp1 apps Storage Data Directory to use the created volume lamp1 and set "Subdirectory" to data and press Move Data.

Cloudron will now move the app data from /home/yellowtent/appsdata/$APPID to /mnt/lamp1/data. After the process is done you can confirm the data is present in /mnt/lamp1/data with ls -lah /mnt/lamp1/data/

ls -lah /mnt/lamp1/data/
total 40K
drwxr-xr-x 4 www-data www-data 4.0K Nov  7 10:34 .
drwxr-xr-x 4 root     root     4.0K Nov  7 10:34 ..
drwxr-xr-x 2 www-data www-data 4.0K Nov  7 10:04 apache
-rw-r--r-- 1 www-data www-data 2.3K Nov  7 10:34 credentials.txt
-rw-r--r-- 1 www-data www-data  157 Nov  7 10:04 php.ini
-rw-r--r-- 1 www-data www-data   44 Nov  7 10:04 .phpmyadminauth
-rw-r--r-- 1 www-data www-data  343 Nov  7 10:04 phpmyadmin_login.txt
-rw-r--r-- 1 www-data www-data  100 Nov  7 10:04 PHP_VERSION
drwxr-xr-x 2 www-data www-data 4.0K Nov  7 10:04 public
-rw-r--r-- 1 www-data www-data   50 Nov  7 10:04 run.sh

Now the lamp1 app uses the lamp1 Volume and is limited to 10GB disk storage.

Disk that has 50 GB storage

If you have a disk with 50 GB storage or more and you want a 10 GB storage limit for lamp1 you will need to create partitions.

Formatting the disk an creating the first partition

Explanation:

  • -s silent (non-interactive) mode
  • mklabel gpt create a new GPT partition table
  • mkpart primary ext4 0% 10GB make one primary partition from the start to the 10 GB mark
This will erase all data from /dev/sdc => Click this box if you are sure you want to do this
wipefs -a /dev/sdc
# this will create /dev/sdc1
parted -s /dev/sdc mklabel gpt mkpart primary ext4 0% 10GB

We can add more 10GB partitions with the following command:

Explanation:

mkpart primary ext4 10GB 20GB:

  • primary partition type
  • ext4 intended filesystem
  • 10GB start of the partition (immediately after the first 10 GB)
  • 20GB end of the partition (10 GB size)
# partiton two - will be /dev/sdc2
parted -s /dev/sdc mkpart primary ext4 10GB 20GB
# partiton three - will be /dev/sdc3
parted -s /dev/sdc mkpart primary ext4 20GB 30GB
# partiton four - will be /dev/sdc4
parted -s /dev/sdc mkpart primary ext4 30GB 40GB
# partition five - will be /dev/sdc5
parted -s /dev/sdc mkpart primary ext4 40GB 50GB

We can inspect the result with fdisk -l /dev/sdc:

fdisk -l /dev/sdc
Disk /dev/sdc: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Volume          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CAD6AF11-8089-4609-8246-9041B047D4D4

Device        Start      End  Sectors  Size Type
/dev/sdc1      2048 19531775 19529728  9.3G Linux filesystem
/dev/sdc2  19531776 39061503 19529728  9.3G Linux filesystem
/dev/sdc3  39061504 58593279 19531776  9.3G Linux filesystem
/dev/sdc4  58593280 78125055 19531776  9.3G Linux filesystem
/dev/sdc5  78125056 97656831 19531776  9.3G Linux filesystem

Now we do the same steps as above for mounting and configuring Cloudron and the app.

Creating directories for the mounts:

mkdir -p /mnt/lamp{1,2,3,4,5}

Creating the ext4 filesystem for the partitions:

for i in {1..5}; do
    mkfs.ext4 /dev/sdc$i
done

Mounting the partitions:

for i in {1..5}; do
    mount /dev/sdc$i /mnt/lamp$i
done

Backup your fstab file

Editing the fstab can be dangerous, always create a backup first!

cp /etc/fstab /etc/fstab_backup_$(date +%d.%m.%Y-%H:%M:%S)

For more details for fstab please read the Arch Wiki - Fstab

Create fstab records for the mounts:

for i in {1..5}; do
    echo "/dev/sdc$i /mnt/lamp$i ext4 defaults,noatime,nofail 0 2" >> /etc/fstab
done

External XFS block storage with project quotas

Creating the filesystem

This will delete all data on /dev/sdc => Click this box if you are sure you want to do this
wipefs -a /dev/sdc
mkfs.xfs -f /dev/sdc

Configure Cloudron and the app

  • 1️⃣ Configure a Cloudron Volume - XFS, select the device /dev/sdc and give the Volume a name.
  • 2️⃣ Configure the app that you would like to have a quota to use the created XFS Volume and use an identifying name e.g. the APP ID from the URL fa43ff2b-c511-4bd8-8c94-79f6910f2aee as the Subdirectory name.

The data will be moved to /mnt/volumes/$VOLUMEID/fa43ff2b-c511-4bd8-8c94-79f6910f2aee/:

ls -lah /mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/fa43ff2b-c511-4bd8-8c94-79f6910f2aee/
total 24K
drwxr-xr-x 5 www-data www-data  167 Nov  7 23:23 .
drwxrwxrwx 3 root     root       50 Nov  7 23:23 ..
drwxr-xr-x 2 www-data www-data   46 Nov  7 23:12 apache
-rw-r--r-- 1 www-data www-data 2.3K Nov  7 23:23 credentials.txt
drwxr-xr-x 3 www-data www-data   17 Nov  7 12:06 mnt
-rw-r--r-- 1 www-data www-data  157 Nov  7 23:12 php.ini
-rw-r--r-- 1 www-data www-data   44 Nov  7 23:12 .phpmyadminauth
-rw-r--r-- 1 www-data www-data  343 Nov  7 23:12 phpmyadmin_login.txt
-rw-r--r-- 1 www-data www-data  100 Nov  7 23:12 PHP_VERSION
drwxr-xr-x 2 www-data www-data   40 Nov  7 23:12 public
-rw-r--r-- 1 www-data www-data   50 Nov  7 23:12 run.sh
  • 3️⃣ Create the /etc/projects and /etc/projid files:
touch /etc/projects /etc/projid
  • 4️⃣ Add the project-controlled directories to /etc/projects:

Info

In the following code block the number 1 is the ID, the character : separates and after that comes the path to the folder.

You can chose the ID freely, but be sure to also edit the following code accordingly.

1:/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/fa43ff2b-c511-4bd8-8c94-79f6910f2aee
  • 5️⃣ Add project names to /etc/projid to map project IDs to project names:

Info

In the following code block the string lamp1 is a project name, the character : separates and after that comes the project ID from the /etc/projects file.

The lamp1 string can be changed freely, but be sure to also edit the following code accordingly.

lamp1:1
  • 6️⃣ Initialize the project directory:
xfs_quota -x -c "project -s lamp1" "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"
  • 7️⃣ Configure quotas for projects with initialized directories:
xfs_quota -x -c "limit -p bsoft=10G bhard=10G lamp1" "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"
  • 8️⃣ Verify quotas:
xfs_quota -x -c 'report -h' "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"

Output should look something like this:

Project quota on /mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7 (/dev/sdc)
                        Blocks              
Project ID   Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
#0              0      0      0  00 [------]
lamp1        108K    10G    10G  00 [------]

Changing the project quota

You can change projects quotas like you did configure them above.

Reduce the project quota of lamp1 to 5M:

xfs_quota -x -c "limit -p bsoft=5M bhard=5M lamp1" "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"

Confirm with:

xfs_quota -x -c 'report -h' "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"

The output should look something like this:

Project quota on /mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7 (/dev/sdc)
                        Blocks              
Project ID   Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
#0              0      0      0  00 [------]
lamp1        108K     5M     5M  00 [------]

Confirming the quota works

Assuming we have set the quota to 5M.

Open the Web Terminal of your app.

Create a 4M big file in /app/data:

fallocate -l 4M /app/data/4M

Check the quota report with:

xfs_quota -x -c 'report -h' "/mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7/"

We can see that not much space is left:

Project quota on /mnt/volumes/af0b5df5b3254d6db4c3018885cb45d7 (/dev/sdc)
                        Blocks              
Project ID   Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
#0              0      0      0  00 [------]
lamp1        4.1M     5M     5M  00 [------]

Try to create another 1M file with:

fallocate -l 1M /app/data/1M

We will get an error:

fallocate: fallocate failed: No space left on device

Success

The quota works.