Format a Drive in EXT4

To format a drive, using default options, in EXT4,

mkfs.ext4 /dev/xvdh

EXT4 also allows the number of inodes to be modified.

Each file requires its own inode and if you have lots of small files, you may run out of inodes before you run out of space. Alternatively, if you are only going to have a few large files, you can get more disk space by limiting the number of inodes.

To set the inode density, you can use the -i switch.

mkfs.ext4 -i 2048 /dev/xvdh

You can see how much disk space you are using with this command

df

and the number of iNodes you are using with this switch

df -i

As a comparison, taking a 200GB disk drive with different inode densities

iNode Density Disk Space Reported Disk Spaces Used by iNodes Number of iNodes Percentage of Disk Used by INodes
1,024 199GB 48GB 200M 24%
2,048 199GB 24GB 100M 12%
4,096 200GB 12GB 50M 6%
8,192 200GB 6GB 25M 3%
16,384 (default) 200GB 3GB 13M 2%

As you can see, with a high iNode density 25% of the disk is used up in preallocated spaces that you cannot use.

As a real world example, I have data being sent to a server that is processes. The data is small – less than 1KB per transaction. As well as processing the data, I also drop a copy into a file on a spare drive “just in case”.

  • The drive is 200GB in size of which I am using 161GB (86%).
  • The iNode density is 2048 Bytes/iNode, giving me 100M iNodes of which 35M are in use (35%)
  • With the normal/default iNode density (16,384), I ran out of iNodes when the disk was only partially full.

Leave a comment

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