Ubuntu server ext4 hitting 65000 subdirectory limit
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.
Solution 1:
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
- Unmount the partition
-
Enable the
dir_index
(hash-based dirs) anddir_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:
- Unmount the partition (important to guard against data loss)
-
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.