How to use all the inodes

This script will create as many files as you have inodes available on your / filesystem:

while [ $(df --output=iavail / | tail -n1) -gt 0 ]; do 
    touch $((i++)); 
done

As far as I know, there is no way to take up inodes without using files or directories, that's what they're for after all. Node that the inodes will remain in use after the script is finished. You will have to delete the created files to free them.


Yes you can consume all the inodes of a system. They are a limited resource just like diskspace is, and they're pre-allocated when you perform a mkfs.ext4, for example.

You can use tools such as tune2fs -l <device> or df -i <path> to see how many are allocated and used.

Example

$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355850 2920950   11% /

So this filesystem has 2920950 inodes free. If I started making files, directories, or links on the filesystem, that would be all I needed to do to consume them all. Realize that I could consume all these inodes with small files or links, and still have roughly all the diskspace still available to me.

Consuming inodes without files?

I'm not sure what you're getting at here, but the only way I'm aware of, where you can consume inodes is to create files, directories, or links. I'm not familiar with any other way to consume them.

Example

Here you can see I'm consuming 1 inodes when I create a empty directory.

$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355850 2920950   11% /

$ sudo mkdir /somedir

$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355851 2920949   11% /

The easiest way to consume the inodes is likely to make a directory tree of directories.

$ sudo mkdir /somedir/1
$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355852 2920948   11% /

$ sudo mkdir /somedir/2
$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355853 2920947   11% /

$ sudo mkdir /somedir/3
$ df -i /
Filesystem               Inodes  IUsed   IFree IUse% Mounted on
/dev/mapper/fedora-root 3276800 355854 2920946   11% /

Here's another example where I'm consuming inodes by creating several links using ln tothe same file.

$ ln -s afile ln1
$ df -i .
Filesystem                          Inodes   IUsed    IFree IUse% Mounted on
/dev/mapper/fedora_greeneggs-home 26722304 1153662 25568642    5% /home

$ ln -s afile ln2
$ df -i .
Filesystem                          Inodes   IUsed    IFree IUse% Mounted on
/dev/mapper/fedora_greeneggs-home 26722304 1153663 25568641    5% /home

$ ln -s afile ln3
$ df -i .
Filesystem                          Inodes   IUsed    IFree IUse% Mounted on
/dev/mapper/fedora_greeneggs-home 26722304 1153664 25568640    5% /home

Files are inodes.

However, you can create files that are not linked to any directory and still use an inode. For instance:

zsh -c 'repeat 1000 ((repeat 1000 {exec {fd}> file; rm file}
          exec sleep 1000 >&-) | cat)'

would (eventually) use up 1,000,000 inodes. Those inodes would be of deleted files that have not been reclaimed yet since those sleep processes have them opened.

The number of files you can create that way is limited by the number of processes you can spawn and the maximum number of files you can open per process.