Amazon EC2 disk resize No space left on device

On an Amazon EC2 instamce disk usage was full.

root@ip-172-31-46-249:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           791M  8.9M  782M   2% /run
/dev/nvme0n1p1  9.7G  9.6G   65M 100% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0       97M   97M     0 100% /snap/core/9665
/dev/loop1       97M   97M     0 100% /snap/core/9436
/dev/loop2       18M   18M     0 100% /snap/amazon-ssm-agent/1566
/dev/loop3       29M   29M     0 100% /snap/amazon-ssm-agent/2012
tmpfs           791M     0  791M   0% /run/user/998
tmpfs           791M     0  791M   0% /run/user/1000
root@ip-172-31-46-249:/#

I increased disk size on Amazone AWS console. But disk did not get changed in EC2 instance.

root@ip-172-31-46-249:~# parted -l
Model: NVMe Device (nvme)
Disk /dev/nvme0n1: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.7GB  10.7GB  primary  ext4         boot


root@ip-172-31-46-249:~# 

The partition still shows 10 GB. When i try growpart, i get error

root@ip-172-31-46-249:/# growpart /dev/nvme0n1 1
mkdir: cannot create directory ‘/tmp/growpart.1889’: No space left on device
FAILED: failed to make temp dir
root@ip-172-31-46-249:/# 

This is because disk is full. I try delete some unwanted files. But was not able to free up much disk space. To fix the error, i mounted /tmp in memory with commands.

mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp

This ec2 instance had lot of free RAM, so it should handle /tmp folder with out any issue. Now growpart worked.

root@ip-172-31-46-249:/# growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2048 old: size=20969439 end=20971487 new: size=41940959,end=41943007
root@ip-172-31-46-249:/# 

parted -l shows the partition using all available disk space

root@ip-172-31-46-249:/# parted -l
Model: NVMe Device (nvme)
Disk /dev/nvme0n1: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  21.5GB  21.5GB  primary  ext4         boot


root@ip-172-31-46-249:/# 

still df -h won’t show increased disk space, this is because you need to increase filesystem size.

resize2fs /dev/nvme0n1p1

See Amazon EC2

Comments

One response to “Amazon EC2 disk resize No space left on device”

  1. Pan Avatar
    Pan

    great help thank you very much

Leave a Reply

Your email address will not be published. Required fields are marked *