7

I have a Ubuntu 14.04 server that is failing to create a new directory beyond the 65,000 directory. I have run a tune2fs -l and can see that the dir_nlink flag is set. Does anyone know what else can be checked to allow this to occur? I have many other clones of this servers configuration that are all past the 65,000 mark and working as expected. I have compared the tune2fs -l outputs and they seem the same. I still have several million free inodes and blocks. I have unmounted and remounted the file system and nothing changed.

Bill Weiss
  • 10,782
  • 3
  • 37
  • 65
gregjkm
  • 71
  • 2
  • 1
    Did you try something like remount your partition? – Khaled Jan 19 '17 at 14:19
  • Not running out of inodes? – HBruijn Jan 19 '17 at 14:25
  • I'm having the same problem. I've yet been unable to reproduce the issue. (E.g. by upgrading a ext3 to a ext4 partition.) I've looked at the ext4 code which suggests that the `dir_nlink` flag is non-functional anyway. Have you found out in the meantime what the problem was? – Georg Schölly Dec 03 '17 at 19:26

1 Answers1

8

Ext4 directory limit

Ext4 supports two kinds of directories:

  • traditional almost-linear directories
  • hash-based directories

Linear directories have a limit of 65000 links, i.e. around that many subdirectories are possible. Hash-based directories do not have a limit.

When creating a new file system, the default is hash directories. If your directories are still linear, it's probably because you upgraded an old ext3 partition. (Ext3 got the hash-based directories feature later.)

Test whether a directory is almost-linear or hash-based

$ sudo debugfs /dev/partition
$ htree /
htree: Not a hash-indexed directory

Conversion

  1. Unmount the partition
  2. Enable the dir_index (hash-based dirs) and dir_nlink (unlimited links) features.

    sudo tune2fs -O dir_index,dir_nlink /dev/partition
    

All newly created directories are now capable of holding unlimited subdirectories.

If you want to convert existing directories, do the following:

  1. Unmount the partition (important to guard against data loss)
  2. Tell fsck to rebuild the directory indices:

    sudo e2fsck -f -D /dev/partition
    

-f forces fsck to check the disk even if it's in the clean state

-D tells e2fsck to rebuild the indices:

This option causes e2fsck to try to optimize all directories, either by reindexing them if the filesystem supports directory indexing, or by sorting and compressing directories for smaller directories, or for filesystems using traditional linear directories.

Georg Schölly
  • 260
  • 3
  • 13