Alters Dev - Easier and Faster

No Space Left on the disk

What Causes the "No Space Left on the Disk" Error?

The "No space left on the disk" error occurs when your EC2 instance runs out of available disk space. This can happen for several reasons, including:

  • Stored too much data on the instance’s disk
  • Configured the instance’s disk partitions are not properly
  • Run resource-intensive tasks in the instance which require a lot of disk space, such as machine learning models or data processing jobs.
  • Cleaned up are not properly of temporary files or logs which stored in the instance’s operating system

Step 1: Check the partitions spacing

Executing the command `df -h` will display the complete root (/) partition, resembling the example shown in Fig. 1. In this illustration, the server usage of 64% is highlighted by a red line.

Command Sample Result
Fig.1 - Command Sample Result
bash
        
df -h
        
    

Step 2: Increase the EBS volume size

  • Login to your AWS Console and access to the EC2 service.
  • Find the volume identifier for your EC2 instance
  • Create a snapshot (backup) of the volume, select the EBS volume and create Snapshot
  • Select the EBS volume and modify Instance after Snapshot ready
  • Increase the volume size

Step 3: Increase the partition size without reboot

Although the volume size is increased, there is a final step to complete: extend the partition size by accessing the EC2 instance over SSH.

  • Login to the EC2 instance over SSH
  • Execute `df -h` to determine which partition is full
  • Confirm the partition size /dev/xvda1 and the new volume size using the `lsblk` command
  • Borrow space for partition growth using `sudo mount -o size=10M,rw,nodev,nosuid -t tmpfs tmpfs /tmp` command
  • Prepare the growth of the partition size using the `sudo growpart /dev/xvda 1` command
  • Use the `sudo resize2fs /dev/xvda1` command for a ext4 filesystem
  • Confirm the size of your partition using `df -h` command
  • Release the borrowed spacing `sudo umount /tmp` command

Conclusion

By following the methods outlined in this article and following best practices for managing disk space, you can avoid this error in the future and ensure that your tasks can be completed without interruption.