Ruth is a mythical creature in the Linux ecosystem. It can do everything: go to any directory, delete any file, complete any process, open any port. In general, this is a superman, extremely powerful and very useful. But have you ever wondered what price we pay for the root? You did not think that it works for nothing.
Do you know the df
command? It shows all disks currently connected and statistics on them: how much space is occupied, how much is free. For example:
$ df -m Filesystem 1M-blocks Used Available Use% Mounted on udev 224 1 224 1% /dev tmpfs 48 1 47 2% /run /dev/dm-0 9204 7421 1294 86% /
Have you ever noticed that for local disks the sum of Used and Available is most often less than the total size of the disk? Not much, but less.
Let's try to occupy all the disk space for the sake of experiment:
$ dd if=/dev/zero of=test bs=1M count=10240 dd: error writing 'test': No space left on device 1365+0 records in 1364+0 records out 1431212032 bytes (1.4 GB) copied, 2.05683 s, 696 MB/s
Great, no space left on device. The place is over. Check:
$ df -m Filesystem 1M-blocks Used Available Use% Mounted on udev 224 1 224 1% /dev tmpfs 48 1 47 2% /run /dev/dm-0 9204 8714 0 100% /
Use 100% and we can no longer record anything. But does this mean that no one can. Remember that the possibilities of the root are endless? Let's try under the root, and suddenly.
$ sudo dd if=/dev/zero of=test1 bs=1M count=10240 dd: error writing 'test1': No space left on device 474+0 records in 473+0 records out 497000448 bytes (497 MB) copied, 0.783122 s, 635 MB/s $ ls -lh total 1.8G -rw-rw-r-- 1 homm homm 1.4G Oct 6 02:37 test -rw-r--r-- 1 root root 474M Oct 6 02:37 test1
Amazing Almost half a gigabyte climbed onto a completely clogged disk. And now df
shows that, really, everything, everything, for a tiny exception, is scored:
$ df -m Filesystem 1M-blocks Used Available Use% Mounted on udev 224 1 224 1% /dev tmpfs 48 1 47 2% /run /dev/dm-0 9204 9188 0 100% /
But how did that happen? There was no disk space, but the root was able to write more. Wait for google, I've already googled everything for you. It turns out that when creating the default file system, Linux reserves 5% for the undefined needs of the root. This can be useful for the system disk, which most of the time is not packed to capacity, and there really is something that may need root. In theory. But if you have a file server to which 10 screws of 2 terabytes are connected, you simply give up a whole terabyte of space to nowhere. After all, it is unlikely that the root writes at least something on these disks.
On this occasion, meetings and demonstrations were not arranged, the State Duma did not meet three times, but nevertheless almost every one of us donates 5% of its disk to the root. Under his vague needs.
Easy peasy.
$ sudo tune2fs -m 0 /dev/dm-0 tune2fs 1.42.9 (4-Feb-2014) Setting reserved blocks percentage to 0% (0 blocks)
Voila, now we ourselves, without difficulty and without a root, can fill our own disk to capacity.
$ dd if=/dev/zero of=test1 bs=1M count=10240 dd: error writing 'test1': No space left on device 474+0 records in 473+0 records out 496992256 bytes (497 MB) copied, 0.835994 s, 594 MB/s
This method is completely safe, can be used on the go and does not require unmounting the disk. True, think carefully whether you need it on the system disk.
An important clarification: as correctly noted in the comments, such a reserve is by default only on the ext3 and ext4 file systems.
Source: https://habr.com/ru/post/339470/
All Articles