Wednesday, January 9, 2013

Freeing up disk space reserved for root user in Linux


In Linux ext filesystem, by default, five percent of the file system blocks are reserved for use by the root user.  As per man page of mkfs.ext4, this helps in avoiding fragmentation, and allows root-owned daemons, such as  syslogd,  to  continue  to function correctly after non-privileged processes are prevented from writing to the filesystem.

So while creating filesystem for partitions, the filesystem blocks reserved for use by the superuser(root), can be changed from default value of 5% to a minimum value, such as 1%, as follows

mkfs.ext4 -m 1 /dev/sda2

However, we can adjust the reserved blocks for superuser(root), even after partition is created and data is loaded on the partition, using the tune2fs command. This comes in handy when we are running short of disk space and try to free up unused blocks reserved for use of root user.

Let us demonstate with following

[root@dhcppc5 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             20160844   8950240  10186604  47% /

Let us see if we can free up some blocks reserved for superuser(root), by reducing the reserved value from 5% to 1%.

[root@dhcppc5 ~]# tune2fs -m 1 /dev/sda2
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 1% (51200 blocks)

[root@dhcppc5 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             20160844   8950224  11005820  45% /

So we can observe that disk usage % has dropped from 47% to 45%, thus freeing up more blocks for use.

No comments:

Post a Comment