By default, Ext 3 & 4 filesystems reserve 5% of available disk space for special processes (root user, syslog, fragmentation avoidance, etc.). On big partitions, it amount to quite a lot of lost space. This howto describe how to get back this disk space.

This howto is tested on:

  • Debian 5.0 Lenny
  • Debian 6.0 Squeeze
  • Ubuntu 11.04 Natty Narwhal
  • Debian 10.0 Buster

Warning

This change can affect the system’s performances. Removing reserved disks space augment fragmentation risks and can result of system crash when no more disk space is available.

Apply this manipulation on non critical systems only.

Settings

Choose the partition for which reserved disk space will be removed.

partition='/dev/sda5'

Set the new reserved blocks percentage (here, 1% in stead of the default 5%):

reservedBlocksPercentage='1'

Installation

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

Detect the filesystem block size:

blockSize="$(${cmdProxy} dumpe2fs "${partition}" 2>'/dev/null' \
  | command grep "Block size" \
  | command sed -e 's/.* //')"

Detect the current number of reserved blocks:

currentReservedBlockCount="$(${cmdProxy} dumpe2fs "${partition}" 2>'/dev/null' \
  | command grep "Reserved block count" \
  | command sed -e 's/.* //')"

Free the reserved blocks:

${cmdProxy} tune2fs -m "${reservedBlocksPercentage}" "${partition}"

Detect the new number of reserved blocks:

newReservedBlockCount="$(${cmdProxy} dumpe2fs "${partition}" 2>'/dev/null' \
   | command grep "Reserved block count" \
   | command sed -e 's/.* //')"

Compute the freed disk space (in Mega bytes):

freedBlockCount="$(( ${currentReservedBlockCount} - ${newReservedBlockCount} ))"
echo "Freed block count: ${freedBlockCount}
Freed disk space:  $(( ( ${freedBlockCount} * ${blockSize} ) / 1000000)) Mb"

Thanks

  • Thanks to Termitor on #ubuntu-fr IRC channel for this trick.
Categories: Setup

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.