5

Without creating a file can I use any inode which is free? I want to write a script that will use all free inodes in the system. is it possible?

8

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
  • 1
    Perhaps some test condition needs to find that it can't create a file. I know I've hit full-disk conditions in production and discovered that the code didn't handle them correctly. Situations like that are really hard to test. – Bruce Ediger Oct 30 '14 at 17:16
  • 1
    BTRFS and JFS (and probably others) dynamically create inodes. I think BTRFS is technically limited to 2^64 inodes and since I am pretty sure you cannot currently create a a 2^74 byte disk, even with RAID, inodes on BTRFS are not a limited resource. – StrongBad Oct 30 '14 at 18:21
  • thank u sir actually my friend challenged me to use inodes without creating file so i asked u. – ashok Oct 30 '14 at 18:27
  • 1
    @ashok what would "using an inode" mean if you don't create a file? How else could an inode be used? Inodes are data structures used to represent filesystem objects, since on *nix "Everything is a file", the only way to use them is to create a new file. – terdon Oct 30 '14 at 18:31
  • 2
    You can create symlinks. Those technically are not files, but do consume inodes. – wurtel Oct 31 '14 at 9:07
8

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.

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.