Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Last active March 7, 2024 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpejcic/cd2212f766b4637f19f59e29720a0a5c to your computer and use it in GitHub Desktop.
Save stefanpejcic/cd2212f766b4637f19f59e29720a0a5c to your computer and use it in GitHub Desktop.
overlay2_with_xfs_pquota.sh 90% of available du on /home
#!/bin/bash
# Stop the Docker service
systemctl stop docker.service
# Set the target file
target_file="/var/lib/docker.fs"
# Get available space in the home directory in kilobytes
available_space=$(df -k /home | awk 'NR==2 {print $4}')
# Calculate 90% of available space in gigabytes
seek_value=$((available_space * 9 / 10 / 1024 / 1024)) # Convert KB to GB
# Use dd to create a sparse file with 90% of available space in gigabytes
dd if=/dev/zero of="$target_file" bs=1G count=0 seek=$seek_value
# Set permissions to allow only root to read the file
chmod 600 /var/lib/docker.fs
# Force overwrite and format the sparse file with the XFS filesystem
mkfs.xfs -f /var/lib/docker.fs
# Move the existing Docker data directory out of the way
mv /var/lib/docker /var/lib/docker.backup
# Create the new Docker directory and set permissions
mkdir /var/lib/docker
chmod 710 /var/lib/docker
# Create an entry in /etc/fstab for the new filesystem
echo '/var/lib/docker.fs /var/lib/docker xfs loop,pquota 0 0' >> /etc/fstab
# Remount to apply the pquota option needed for disk size limits
#mount -o remount /var/lib/docker
umount /var/lib/docker
mount /var/lib/docker
# Reload systemd
systemctl daemon-reload
# Mount the new filesystem
mount /var/lib/docker
# Move all Docker data to the new filesystem
mv /var/lib/docker.backup/* /var/lib/docker/
rmdir /var/lib/docker.backup
# Start the Docker service
systemctl start docker.service
@stefanpejcic
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment