I want to increase the size of my Amazon Elastic Block Store (Amazon EBS) volume. However, I received an error that there's no space left on my file system.
Short description
When you expand the root partition or root file system on your Amazon EBS volume, you might receive a "No space left on device" error. To avoid this error, use the tmpfs temporary file system that's in your virtual memory. Mount the tmpfs file system under the /tmp mount point, and then expand your root partition or root file system.
The following example shows that the /dev/nvme0n1 root EBS volume block device is 9 GiB, and the nvme0n1p1 root partition is already 8 GiB:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 9G 0 disk
├─nvme0n1p1 259:1 0 8G 0 part /
└─nvme0n1p128 259:2 0 1M 0 part
If you try to increase the nvme0n1p1 root partition, then you receive one of the following error messages in the command output:
$ sudo growpart /dev/nvme0n1 1
/bin/growpart: line 248: /tmp/growpart.fklt5u/dump.out: No space left on device
FAILED: failed to dump sfdisk info for /dev/nvme0n1
-or-
$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=4096 old: size=16773087 end=16777183 new: size=18870239 end=18874335
FAILED: failed: sfdisk --list /dev/nvme0n1
Resolution
Important: It's a best practice to create an Amazon Machine Image (AMI) backup of the instance. Or, create a snapshot of the root EBS volume that's attached to your instance. A backup allows you to recover your data in case you encounter issues.
To increase the size of your EBS volume, complete the following steps:
-
Use SSH to connect to your Amazon Elastic Compute Cloud (Amazon EC2) Linux instance.
-
To confirm that the root partition mounted under / is full, run the following command:
df -h
In the following example output, /dev/nvme0n1p1 is full because it uses 100% of its space:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 460M 0 475M 0% /dev
tmpfs 478M 0 492M 0% /dev/shm
tmpfs 478M 432K 492M 1% /run
tmpfs 478M 0 492M 0% /sys/fs/cgroup
/dev/nvme0n1p1 8.0G 8.0G 664K 100% /
tmpfs 96M 0 99M 0% /run/user/1000
-
To gather details about your attached block devices and the root / mount point, run the following commands:
lsblk
lsblk -f
Example output:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 9G 0 disk
├─nvme0n1p1 259:1 0 8G 0 part /
└─nvme0n1p128 259:2 0 1M 0 part
$ lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
nvme0n1
├─nvme0n1p1 xfs / afcf1342-1d40-41bd-bde9-e4ea5d87e3b6 /
└─nvme0n1p128
Note the file system size and type. In the preceding example output, the root EBS volume has 9 GiB of total space. However, the /dev/nvme0n1p1 root partition is only 8 GiB. The file system type is XFS.
-
To mount the tmpfs temporary file system to the /tmp mount point, run the following command:
sudo mount -o size=10M,rw,nodev,nosuid -t tmpfs tmpfs /tmp
Note: The preceding command creates a 10 MB tmpfs mounted to /tmp.
-
To grow the size of the root partition, run the following command:
sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=4096 old: size=16773087 end=16777183 new: size=18870239 end=18874335
Note: Replace /dev/nvme0n1 with your root partition.
-
To verify that you expanded the partition from 8 GiB to 9 GiB, run the following command:
lsblk
Example output:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 9G 0 disk
├─nvme0n1p1 259:1 0 9G 0 part /
└─nvme0n1p128 259:2 0 1M 0 part
-
To expand the file system, run the following commands based on your file system type.
XFS file system:
sudo xfs_growfs -d /
Example output:
$ sudo xfs_growfs -d /
data blocks changed from 2096635 to 2358779
= sectsz=512 sunit=0 blks, lazy-count=1
log =internal bsize=4096 blocks=2560, version=2
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
= sunit=0 swidth=0 blks
data = bsize=4096 blocks=2096635, imaxpct=25
= crc=1 finobt=1 spinodes=0
= sectsz=512 attr=2, projid32bit=1
realtime =none extsz=4096 blocks=0, rtextents=0
meta-data=/dev/nvme0n1p1 isize=512 agcount=4, agsize=524159 blks
EXT2, EXT3, or EXT4 file system:
sudo resize2fs /dev/nvme0n1p1
Note: Replace /dev/nvme0n1 with your root partition.
-
To verify that the operating system can view the additional space, run the following command:
df -h
Example output:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 960M 0 960M 0% /dev
tmpfs 978M 0 978M 0% /dev/shm
tmpfs 978M 392K 978M 1% /run
tmpfs 978M 0 978M 0% /sys/fs/cgroup
/dev/nvme0n1p1 9.0G 8.0G 1022M 89% /
tmpfs 196M 0 196M 0% /run/user/1000
tmpfs 10M 0 10M 0% /tmp
-
To unmount the tmpfs file system, run the following command:
sudo umount /tmp