How to grow XFS → xfs_growfs

How to Grow XFS Filesystems Using xfs_growfs Command Table of Contents - [Introduction](#introduction) - [Prerequisites and Requirements](#prerequisites-and-requirements) - [Understanding XFS Filesystem Growth](#understanding-xfs-filesystem-growth) - [Basic xfs_growfs Syntax and Options](#basic-xfs_growfs-syntax-and-options) - [Step-by-Step Guide to Growing XFS Filesystems](#step-by-step-guide-to-growing-xfs-filesystems) - [Practical Examples and Use Cases](#practical-examples-and-use-cases) - [Advanced Configuration Options](#advanced-configuration-options) - [Common Issues and Troubleshooting](#common-issues-and-troubleshooting) - [Best Practices and Professional Tips](#best-practices-and-professional-tips) - [Performance Considerations](#performance-considerations) - [Monitoring and Verification](#monitoring-and-verification) - [Conclusion](#conclusion) Introduction XFS is a high-performance, scalable filesystem that supports online growth, meaning you can expand the filesystem while it remains mounted and in active use. The `xfs_growfs` command is the primary tool for expanding XFS filesystems, allowing administrators to increase storage capacity without downtime or data loss. This comprehensive guide will teach you everything you need to know about using `xfs_growfs` to grow XFS filesystems. Whether you're managing a small server or large-scale enterprise storage systems, understanding how to properly expand XFS filesystems is crucial for maintaining adequate storage capacity and optimal system performance. By the end of this article, you'll understand how to safely expand XFS filesystems, troubleshoot common issues, implement best practices, and optimize performance during and after filesystem growth operations. Prerequisites and Requirements System Requirements Before attempting to grow an XFS filesystem, ensure your system meets these requirements: - Operating System: Linux distribution with XFS support (most modern distributions) - XFS Utilities: xfsprogs package installed (`xfs_growfs`, `xfs_info`, `xfs_repair`) - Kernel Support: Linux kernel 2.6 or later with XFS module loaded - Root Privileges: Administrative access to execute filesystem operations Storage Prerequisites - Available Space: Additional storage space must be available on the underlying block device - Partition or LVM: The underlying partition or logical volume must be expanded first - Mounted Filesystem: The XFS filesystem must be mounted (online growth) Verification Commands Check if XFS utilities are installed: ```bash Verify xfs_growfs is available which xfs_growfs Check XFS utilities version xfs_growfs -V Verify XFS kernel support cat /proc/filesystems | grep xfs ``` Understanding XFS Filesystem Growth How XFS Growth Works XFS filesystems can only be grown, never shrunk. The growth process involves: 1. Block Device Expansion: First expand the underlying storage (partition/LVM) 2. Filesystem Detection: XFS detects the additional space automatically 3. Metadata Updates: Allocation group structures are updated 4. Space Integration: New space becomes available for file storage XFS Allocation Groups XFS organizes storage into allocation groups (AGs), which are: - Independent Units: Each AG manages its own free space and inodes - Scalable Design: Multiple AGs enable parallel operations - Growth Mechanism: New AGs are created when expanding the filesystem Online vs Offline Growth XFS supports only online growth: - Online Growth: Filesystem remains mounted and accessible during expansion - No Downtime: Applications continue running during the growth process - Atomic Operation: Growth either completes successfully or fails without corruption Basic xfs_growfs Syntax and Options Command Syntax ```bash xfs_growfs [options] ``` Essential Options | Option | Description | Example | |--------|-------------|---------| | `-d` | Grow data section to maximum available space | `xfs_growfs -d /mnt/data` | | `-D size` | Grow data section to specific size (filesystem blocks) | `xfs_growfs -D 1000000 /mnt/data` | | `-l` | Grow log section to maximum available space | `xfs_growfs -l /mnt/data` | | `-L size` | Grow log section to specific size (filesystem blocks) | `xfs_growfs -L 10000 /mnt/data` | | `-r` | Grow realtime section to maximum available space | `xfs_growfs -r /mnt/data` | | `-R size` | Grow realtime section to specific size (realtime blocks) | `xfs_growfs -R 50000 /mnt/data` | | `-n` | Dry run - show what would be done without making changes | `xfs_growfs -n -d /mnt/data` | | `-v` | Verbose output showing detailed information | `xfs_growfs -v -d /mnt/data` | Understanding Size Units XFS uses filesystem blocks as the primary unit: - Filesystem Blocks: Default block size is typically 4KB - Size Calculation: Total size = blocks × block size - Block Size: Check with `xfs_info ` Step-by-Step Guide to Growing XFS Filesystems Step 1: Assess Current Filesystem Status Before growing the filesystem, gather information about its current state: ```bash Check current filesystem information xfs_info /mnt/data Check available disk space df -h /mnt/data Verify underlying block device lsblk | grep -A5 -B5 sdb1 Check partition table fdisk -l /dev/sdb ``` Step 2: Expand Underlying Storage For Standard Partitions ```bash Use fdisk to expand partition fdisk /dev/sdb Delete and recreate partition with larger size Warning: This is risky - backup data first Inform kernel of partition changes partprobe /dev/sdb ``` For LVM Logical Volumes ```bash Extend physical volume (if needed) pvresize /dev/sdb1 Extend volume group (if adding new PV) vgextend vg_data /dev/sdc1 Extend logical volume lvextend -l +100%FREE /dev/vg_data/lv_data Or specify exact size lvextend -L +10G /dev/vg_data/lv_data ``` Step 3: Verify Additional Space is Available ```bash Check that block device is larger than filesystem blockdev --getsize64 /dev/vg_data/lv_data Compare with current filesystem size xfs_info /mnt/data | grep "data.*blocks" ``` Step 4: Perform Dry Run Always perform a dry run first to verify the operation: ```bash Dry run to see what would happen xfs_growfs -n -d /mnt/data ``` Example output: ``` meta-data=/dev/mapper/vg_data-lv_data isize=512 agcount=8, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 data = bsize=4096 blocks=1048576, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 realtime =none extsz=4096 blocks=0, rtextents=0 Would grow filesystem to 2097152 blocks ``` Step 5: Execute the Growth Operation ```bash Grow filesystem to use all available space xfs_growfs -d /mnt/data ``` Step 6: Verify Growth Completion ```bash Check new filesystem size df -h /mnt/data Verify filesystem integrity xfs_info /mnt/data Optional: Run filesystem check xfs_repair -n /dev/vg_data/lv_data ``` Practical Examples and Use Cases Example 1: Growing a Root Filesystem on LVM This example demonstrates growing a root filesystem using LVM: ```bash Step 1: Check current status df -h / xfs_info / Step 2: Extend logical volume lvextend -L +5G /dev/mapper/rhel-root Step 3: Grow XFS filesystem xfs_growfs / Step 4: Verify results df -h / ``` Example 2: Growing Data Partition to Specific Size Growing a data filesystem to a specific size: ```bash Current filesystem info xfs_info /mnt/data | grep "data.*blocks" Output: data = bsize=4096 blocks=1048576, imaxpct=25 Calculate target blocks (for 8GB total: 8GB / 4KB = 2097152 blocks) xfs_growfs -D 2097152 /mnt/data Verify specific size achieved xfs_info /mnt/data | grep "data.*blocks" ``` Example 3: Growing Multiple Filesystem Sections Growing both data and log sections: ```bash Grow data section to maximum xfs_growfs -d /mnt/data Then grow log section if needed xfs_growfs -l /mnt/data Or combine operations (data growth first, then log) xfs_growfs -d -l /mnt/data ``` Example 4: Scripted Growth with Error Handling Automated script for safe filesystem growth: ```bash #!/bin/bash MOUNTPOINT="/mnt/data" DEVICE="/dev/vg_data/lv_data" Function to check prerequisites check_prerequisites() { if ! mountpoint -q "$MOUNTPOINT"; then echo "Error: $MOUNTPOINT is not mounted" exit 1 fi if ! which xfs_growfs > /dev/null; then echo "Error: xfs_growfs not found" exit 1 fi } Function to grow filesystem safely grow_filesystem() { echo "Current filesystem size:" df -h "$MOUNTPOINT" echo "Performing dry run..." if xfs_growfs -n -d "$MOUNTPOINT"; then echo "Dry run successful. Proceeding with growth..." if xfs_growfs -d "$MOUNTPOINT"; then echo "Filesystem growth completed successfully" echo "New filesystem size:" df -h "$MOUNTPOINT" else echo "Error: Filesystem growth failed" exit 1 fi else echo "Error: Dry run failed" exit 1 fi } Main execution check_prerequisites grow_filesystem ``` Advanced Configuration Options Growing Specific Filesystem Sections Data Section Growth ```bash Grow data section only xfs_growfs -d /mnt/data Grow to specific data size (in filesystem blocks) xfs_growfs -D 4194304 /mnt/data ``` Log Section Growth ```bash Grow internal log to maximum size xfs_growfs -l /mnt/data Grow to specific log size xfs_growfs -L 32768 /mnt/data ``` Realtime Section Growth ```bash Grow realtime section (if configured) xfs_growfs -r /mnt/data Grow to specific realtime size xfs_growfs -R 1048576 /mnt/data ``` Calculating Optimal Sizes Block Size Considerations ```bash Get current block size xfs_info /mnt/data | grep bsize Calculate blocks needed for specific size Formula: target_size_bytes / block_size = blocks_needed Example: 10GB with 4KB blocks = 10737418240 / 4096 = 2621440 blocks ``` Allocation Group Optimization ```bash Check current AG configuration xfs_info /mnt/data | grep agcount Optimal AG size is typically 1GB to 1TB Growth may create new AGs automatically ``` Performance Tuning During Growth I/O Priority Settings ```bash Run growth with lower I/O priority to reduce system impact ionice -c 3 xfs_growfs -d /mnt/data Or use nice for CPU priority nice -n 19 xfs_growfs -d /mnt/data ``` Concurrent Operations ```bash Monitor system load during growth watch -n 1 'uptime; iostat -x 1 1' Consider maintenance window for large filesystems ``` Common Issues and Troubleshooting Issue 1: "No Space Left on Device" Error Symptoms: ```bash xfs_growfs: /mnt/data is not a mounted XFS filesystem ``` Causes and Solutions: ```bash Verify filesystem type mount | grep /mnt/data df -T /mnt/data Check if actually XFS xfs_info /mnt/data Solution: Ensure correct filesystem type and mount point ``` Issue 2: Underlying Device Not Expanded Symptoms: ```bash xfs_growfs: cannot find device for /mnt/data ``` Diagnosis: ```bash Check block device size vs filesystem size blockdev --getsize64 /dev/vg_data/lv_data xfs_info /mnt/data | grep blocks Solution: Expand underlying storage first lvextend -L +5G /dev/vg_data/lv_data ``` Issue 3: Insufficient Permissions Symptoms: ```bash xfs_growfs: Operation not permitted ``` Solution: ```bash Run as root or with sudo sudo xfs_growfs -d /mnt/data Check file permissions on device ls -l /dev/vg_data/lv_data ``` Issue 4: Filesystem Corruption Concerns Prevention: ```bash Always run filesystem check before growth xfs_repair -n /dev/vg_data/lv_data Ensure clean unmount history xfs_info /mnt/data | grep log Solution for corruption: umount /mnt/data xfs_repair /dev/vg_data/lv_data mount /mnt/data ``` Issue 5: Growth Operation Hangs Diagnosis: ```bash Check system resources top iostat -x 1 dmesg | tail Monitor filesystem operations lsof +D /mnt/data Solution: Wait for completion or identify blocking processes ``` Issue 6: Unexpected Growth Results Verification Steps: ```bash Compare before and after sizes df -h /mnt/data Check allocation group changes xfs_info /mnt/data Verify block counts match expectations xfs_db -r /dev/vg_data/lv_data -c "sb 0" -c "print dblocks" ``` Best Practices and Professional Tips Pre-Growth Planning Capacity Planning - Monitor Growth Trends: Track filesystem usage patterns over time - Plan Ahead: Expand before reaching 80% capacity - Size Appropriately: Avoid frequent small expansions Backup Strategy ```bash Always backup critical data before growth operations tar -czf /backup/data_backup.tar.gz /mnt/data For databases, use proper backup tools mysqldump --all-databases > /backup/mysql_backup.sql Verify backup integrity tar -tzf /backup/data_backup.tar.gz > /dev/null ``` Growth Execution Best Practices Timing Considerations - Maintenance Windows: Schedule growth during low-usage periods - Business Hours: Avoid peak operational times - System Load: Monitor overall system performance Safety Measures ```bash Always perform dry run first xfs_growfs -n -d /mnt/data Document current state xfs_info /mnt/data > /tmp/xfs_before_growth.txt df -h > /tmp/disk_usage_before.txt Monitor during growth watch -n 5 'df -h /mnt/data; echo "---"; iostat -x 1 1' ``` Post-Growth Verification Comprehensive Checks ```bash Verify filesystem integrity xfs_repair -n /dev/vg_data/lv_data Check allocation group distribution xfs_info /mnt/data Test write operations dd if=/dev/zero of=/mnt/data/testfile bs=1M count=100 rm /mnt/data/testfile Monitor for any errors dmesg | grep -i xfs | tail -20 ``` Documentation - Record Changes: Document growth operations and results - Update Monitoring: Adjust capacity monitoring thresholds - Capacity Planning: Update future growth projections Performance Optimization Post-Growth Optimization ```bash Check for fragmentation after growth xfs_db -r /dev/vg_data/lv_data -c "frag -f" Consider defragmentation if needed xfs_fsr /mnt/data Monitor performance metrics iostat -x 1 10 ``` Allocation Group Management - AG Size: Optimal AG size is 1GB to 1TB - AG Count: More AGs can improve parallel performance - Balance: Avoid too many small AGs Performance Considerations Growth Impact on System Performance I/O Impact During growth operations, expect: - Increased Disk I/O: Metadata updates require disk writes - CPU Usage: Filesystem structure calculations - Memory Usage: Kernel buffers for metadata operations Monitoring Commands ```bash Monitor I/O during growth iostat -x 1 Watch memory usage free -m cat /proc/meminfo | grep -E "(Cached|Buffers|MemFree)" Check CPU utilization top -p $(pgrep xfs_growfs) ``` Optimization Strategies Large Filesystem Growth ```bash For filesystems > 100GB, consider: 1. Schedule during maintenance windows 2. Monitor system resources closely 3. Ensure adequate free memory Example monitoring script during growth #!/bin/bash while pgrep xfs_growfs > /dev/null; do echo "$(date): Growth in progress" iostat -x 1 1 | grep -E "(Device|$DEVICE)" free -m | grep Mem sleep 10 done echo "$(date): Growth completed" ``` Network-Attached Storage For NFS or other network storage: - Network Bandwidth: Growth may impact network I/O - Client Caching: Clear client-side caches after growth - Mount Options: Consider remounting with updated parameters Monitoring and Verification Real-Time Monitoring Growth Progress Tracking ```bash Monitor filesystem size changes watch -n 2 'df -h /mnt/data' Track allocation group changes watch -n 5 'xfs_info /mnt/data | grep agcount' Monitor system performance htop ``` Log Monitoring ```bash Watch system logs for XFS messages tail -f /var/log/messages | grep -i xfs Monitor kernel messages dmesg -w | grep -i xfs Check for any error conditions journalctl -f -u xfs* ``` Post-Growth Verification Scripts Comprehensive Verification Script ```bash #!/bin/bash MOUNTPOINT="/mnt/data" DEVICE="/dev/vg_data/lv_data" LOGFILE="/var/log/xfs_growth_verification.log" log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S'): $1" | tee -a "$LOGFILE" } verify_growth() { log_message "Starting post-growth verification" # Check filesystem is still mounted if ! mountpoint -q "$MOUNTPOINT"; then log_message "ERROR: Filesystem not mounted at $MOUNTPOINT" return 1 fi # Check filesystem integrity log_message "Checking filesystem integrity..." if xfs_repair -n "$DEVICE" > /dev/null 2>&1; then log_message "Filesystem integrity check: PASSED" else log_message "ERROR: Filesystem integrity check failed" return 1 fi # Test write operations log_message "Testing write operations..." if echo "test" > "$MOUNTPOINT/growth_test.tmp" 2>/dev/null; then rm -f "$MOUNTPOINT/growth_test.tmp" log_message "Write test: PASSED" else log_message "ERROR: Write test failed" return 1 fi # Display new filesystem information log_message "New filesystem information:" df -h "$MOUNTPOINT" | tee -a "$LOGFILE" xfs_info "$MOUNTPOINT" | tee -a "$LOGFILE" log_message "Post-growth verification completed successfully" return 0 } verify_growth ``` Long-Term Monitoring Automated Monitoring Setup ```bash Add to cron for regular monitoring /etc/cron.d/xfs-monitoring 0 /6 root df -h | grep xfs >> /var/log/xfs-usage.log Monitor for fragmentation 0 2 0 root xfs_db -r /dev/vg_data/lv_data -c "frag -f" >> /var/log/xfs-frag.log ``` Alert Thresholds - Capacity: Alert at 80% usage - Fragmentation: Monitor fragmentation levels - Performance: Track I/O response times Conclusion Growing XFS filesystems with `xfs_growfs` is a powerful capability that enables administrators to expand storage capacity without downtime or data loss. This comprehensive guide has covered all aspects of XFS filesystem growth, from basic operations to advanced troubleshooting and optimization techniques. Key Takeaways 1. Safety First: Always perform dry runs and backups before growth operations 2. Proper Planning: Expand underlying storage before growing the filesystem 3. Online Operations: XFS growth occurs while the filesystem remains mounted and accessible 4. Verification is Critical: Always verify growth completion and filesystem integrity 5. Performance Awareness: Monitor system resources during growth operations Best Practices Summary - Pre-Growth: Backup data, expand underlying storage, perform dry runs - During Growth: Monitor system performance and log files - Post-Growth: Verify integrity, test operations, update documentation - Ongoing: Implement monitoring and capacity planning Next Steps After successfully growing your XFS filesystems, consider: 1. Implementing Monitoring: Set up automated capacity and performance monitoring 2. Capacity Planning: Develop long-term storage growth strategies 3. Performance Tuning: Optimize filesystem parameters for your workload 4. Backup Strategy: Update backup procedures to account for larger filesystems 5. Documentation: Maintain detailed records of growth operations and configurations The `xfs_growfs` command is an essential tool for modern system administration, enabling dynamic storage management in production environments. By following the practices and procedures outlined in this guide, you can safely and effectively manage XFS filesystem growth while maintaining optimal performance and data integrity. Remember that filesystem growth is a one-way operation with XFS – careful planning and proper execution are essential for successful storage management. Regular monitoring and proactive capacity planning will help ensure your systems have adequate storage space while maintaining optimal performance.