Increasing inode count on ext4
- Nico Hiort af Ornäs
- Tech
- September 1, 2024
A Symfony codebase deployment usually requires a quite significant amount of files, and thus it’s quite common to run out of inodes on your filesystem.
I deploy my apps on DigitalOcean. To increase the inode count on your ext4 block storage in DigitalOcean, you’ll need to recreate the filesystem with a higher inode ratio. The inode count is determined when the filesystem is created, and it is based on the -i
parameter, which specifies the bytes-per-inode ratio. To increase the inode count, you need to reduce the bytes-per-inode ratio.
Here’s how to do it:
1. Backup Data (Optional but Recommended)
If you have important data on the block storage, it’s crucial to back it up. You can use rsync
or another backup tool.
sudo rsync -av /mnt/your_mount_point/ /path/to/backup/
2. Unmount the Block Storage
Before making any changes, you must unmount the block storage.
sudo umount /mnt/your_mount_point
3. Reformat the Block Storage with Increased Inodes
Now, you can reformat the block storage with a higher inode count by adjusting the -i
parameter.
To achieve at least 2 million inodes on a 10GB volume, you can set the -i
parameter to around 5,000 bytes per inode (10GB * 1,000,000,000 bytes / 5,000 = 2,000,000 inodes).
sudo mkfs.ext4 -i 5000 /dev/disk/by-id/scsi-0DO_Volume_your_volume_name
- Replace
/dev/disk/by-id/scsi-0DO_Volume_your_volume_name
with your actual block storage device name.
4. Remount the Block Storage
After formatting, remount the block storage.
sudo mount /dev/disk/by-id/scsi-0DO_Volume_your_volume_name /mnt/your_mount_point
5. Restore Data (If Backed Up)
If you backed up your data earlier, restore it to the block storage.
sudo rsync -av /path/to/backup/ /mnt/your_mount_point/
6. Verify the Inode Count
Finally, check the inode count to confirm it meets your expectations.
df -i /mnt/your_mount_point
This should give you at least 2 million inodes on your 10GB ext4 block storage.