recover-disk-space

2024-10-05 714 words 4 mins read

Recovering Disk Space by Reducing Reserved Block Count on Linux

Introduction

In Linux systems, disk space management is crucial, especially when storage is running low. One often-overlooked aspect is the space reserved by the filesystem, known as reserved blocks. These blocks can consume a significant amount of disk space. In this post, we’ll explore what reserved blocks are, why they’re important, and how you can reduce the reserved block count to free up space.

What Are Reserved Blocks?

Reserved blocks are sections of a filesystem set aside by the operating system, typically when using the ext2/ext3/ext4 filesystems. By default, 5% of the total disk space is reserved for administrative tasks and to avoid full-disk scenarios.

Purpose of Reserved Blocks:

  1. Preventing Full-Disk Issues: If a disk becomes full, important system processes could fail. Reserved blocks ensure that critical system operations like logging, and root-level processes, still have some space to operate even when user-level disk space is exhausted. But now a days, this is not required or such a huge size is not required for these reasons:
  2. If you have the partition which is not used for one of the system partitions like ‘/’ or /var or anything like that, even if the disk is full, it will not obstruct the SO.
  3. If you have a disk of 1TB , you don’t necessarily need 50GB reserverd. You can always decrease this to 1GB or 5GB or whatever.
  4. Improved Performance: Filesystems perform better when they are not completely full. Reserving space helps maintain performance by allowing critical operations to proceed without interruption.
  5. System Recovery: If the filesystem gets corrupted, having a portion of it reserved for root can make recovery easier, giving the administrator a bit of “breathing room.”

When Should You Reduce Reserved Blocks?

In most desktop environments or in storage partitions that are not used by root or system-critical tasks, this reserved space can feel excessive. For large storage partitions, 5% reserved space can mean several gigabytes of unusable space.

For example:
On a 1TB disk, 5% reserved space equals around 50GB—space that most home users won’t need.

How to Check Reserved Block Count

You can check the amount of reserved space for a specific partition using the tune2fs command:

1
sudo tune2fs -l /dev/sdX | grep 'Reserved block count'

Replace /dev/sdX with your actual partition identifier.

And to check how much space is actually reserved, you can check the total size by

1
sudo tune2fs -l /dev/sdb2 |egrep -i block\ size

This will give you the size of the blocks. Now you can divide the product of this with reserved blocks by 1024*1024*1024 to get total in GB. For example:

1
2
3
sudo tune2fs -l /dev/sdb2 |egrep -i 'block size|Reserved block count'
Reserved block count:     18837000
Block size:               4096

So, now you can do:

1
echo '(18837000*4096)/(1024*1024*1024)' | bc

and this is the amount of disk space that is in reserved.

Reducing the Reserved Block Count

You can reduce or even remove the reserved blocks depending on your needs. For non-root or non-critical partitions, reducing this value to 1% or 0% can free up a significant amount of disk space.

Command to Reduce Reserved Blocks:

1
sudo tune2fs -m <percentage> /dev/sdX

Where <percentage> is the percentage of the filesystem to reserve. For example:

1
sudo tune2fs -m 1 /dev/sdX

This reduces the reserved space to 1% of the partition size.

Command Example:

If you want to completely remove the reserved blocks, set the percentage to 0:

1
sudo tune2fs -m 0 /dev/sdX

Verifying Changes

You can verify the changes with the following command:

1
sudo tune2fs -l /dev/sdX | grep 'Reserved block count'

Considerations and Best Practices

  • System Partitions: Do not reduce the reserved block count for critical partitions, like / (root), /var, or /tmp, as system processes might need this reserved space.
  • User Partitions: For partitions dedicated to user files or backups, reducing the reserved block count is generally safe.
  • Large Disks: On large disks, even 1% reserved space can be significant. Adjust this value based on your usage scenario.

Conclusion

Reducing reserved block count is a useful way to reclaim unused disk space, particularly on large partitions that don’t require system-critical functionality. By managing your filesystem’s reserved space, you can optimize your disk usage without sacrificing system performance or stability.


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it