Troubleshoot cloud disk capacity discrepancy

Updated at:

On a Linux ECS instance, the capacity of a cloud disk reported by the df command may not match the capacity you purchased. This behavior is expected and does not indicate an error. The discrepancy is caused by space consumed by file system metadata, inodes, and system reserved space.

Problem description

A 200 GiB cloud disk is attached to a Linux ECS instance. After initializing the disk, you run the df -h command and observe that the reported capacity is only 197 GiB.

  1. The total capacity (Size) reported by the df -h command does not match the purchased capacity in the console.

  2. The sum of used space (Used) and available space (Avail) does not equal the total capacity (Size).

[root@xxx]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        916M     0  916M   0% /dev
tmpfs           936M   12K  936M   1% /dev/shm
tmpfs           936M  536K  936M   1% /run
tmpfs           936M     0  936M   0% /sys/fs/cgroup
/dev/vda3        40G  4.1G   34G  11% /
/dev/vda2       200M  5.8M  195M   3% /boot/efi
tmpfs           188M     0  188M   0% /run/user/0
/dev/vdb1       197G  118M  189G   1% /mnt
Note

The capacity of cloud disks purchased in the Alibaba Cloud console is measured in gibibytes (GiB). This article uses the df -h command as an example. If you use the df -H command, the reported partition usage is measured in gigabytes (GB).

  • The df -h command uses a base of 1024, displaying sizes in binary units such as KiB, MiB, and GiB.

  • The df -H command uses a base of 1000, displaying sizes in decimal units such as KB, MB, and GB.

For example, a partition that is exactly 40 GiB might be displayed as 40G by the df -h command. The same partition might be displayed as 43G by the df -H command, because 40 GiB (40 × 1024³ bytes) is equivalent to approximately 43 GB.

Causes

Question 1: The total capacity (Size) displayed by the df -h command does not match the purchased capacity in the console

File system overhead

When you format and mount a 200 GiB cloud disk in Linux, its reported capacity might be only 197 GiB. This occurs because the file system requires space for metadata, which reduces the capacity available for your data.

Issue 2: Used + Avail does not equal Size

This discrepancy is typically caused by two factors: space consumed by inodes and system reserved space. See Troubleshooting methods to learn how to calculate this consumed space.

Inode usage

A file system allocates an inode to each file and directory to store attributes, such as permissions and ownership. These inodes themselves consume disk space, which the df -h command does not include in the Used or Avail fields.

System reserved space

Linux file systems also reserve a portion of disk space for system use. This reserved space prevents the file system from becoming completely full, which ensures system stability and security. This space is not included in the Used or Avail fields reported by the df -h command.

Troubleshooting methods

View partition details

Run the following command to view the partition information for the cloud disk.

sudo tune2fs -l /dev/[$Partition] | grep -E "count|size:"
Note

In this case, /dev/[$Partition] is the partition name of the cloud disk, for example, /dev/vdb1. Replace the partition name based on your actual situation.

The output is similar to the following:

[root@xxx]# sudo tune2fs -l /dev/vdb1 | grep -E "count|size:"
Inode count:              13107200
Block count:              52428539
Reserved block count:     2199325
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Flex block group size:    16
Mount count:              1
Maximum mount count:      -1
Inode size:               256
Required extra isize:     32
Desired extra isize:      32

Calculate inode space

To calculate the total space that inodes consume, run the following command:

sudo tune2fs -l /dev/[$Partition] | awk '/Inode count:/{c=$3} /Inode size:/{split($0,a,":"); s=a[2]} END{if(c && s) printf "Inode space: %.2f GiB\n", c*strtonum(s)/(1024^3); else print "Error: Could not find Inode information."}'
Note

In this case, /dev/[$Partition] is the partition name of the cloud disk, for example, /dev/vdb1. Replace the partition name based on your actual situation.

Alternatively, you can use the following formula to calculate the space consumed by inodes:

Calculate reserved space

To calculate the total system reserved space, run the following command:

sudo tune2fs -l /dev/[$Partition] | awk '/Reserved block count:/{r=$4} /Block size:/{b=$3} END{if(r && b) printf "Reserved space: %.2f GiB\n", r*b/(1024^3); else print "Error: Could not find reserved block or block size information."}'
Note

In this case, /dev/[$Partition] is the partition name of the cloud disk, for example, /dev/vdb1. Replace the partition name based on your actual situation.

The command returns the following output:

[root@ixxxxxxxxxxxx]# sudo tune2fs -l /dev/vdb1 | awk '/Reserved block count:/{r=$4} /Block size:/{b=$3} END{if(r & b) printf "Reserved space: %.2f GiB\n", r*b/(1024^3); else print "Error: Could not find reserved block or block size information."}'
Reserved space: 8.39 GiB

Alternatively, you can use the following formula to calculate the system reserved space: