ext4 disk full, files are erased when you try to save them, data loss
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ubuntu |
New
|
Undecided
|
Unassigned |
Bug Description
I encountered this problem when I was backing up my data to an ext4 drive.
As I understand, the problem will happen with any editor and likely with any other program.
When disk is full, files are erased when you try to save them.
Scenario 1 (exactly as it happens in real life, slow because of copying gigabytes)
1. Take an ext4 drive. Fill it with data almost completely (like 10G free on a 500G grive)
2. Create a multi-line text file (like 10 lines of 10 characters each)
3. Start a terminal with a bash shell; run ``sudo mc'' (that is, run Midnight Commander as root)
4. navigate to a directory containing about 25G of data; use Midnight Commander to copy that directory to the almost full ext4 disk. Surprisingly, that operation will succeed: about 5% of disk space is reserved for root's needs. For some time you will be watching as mc copies gigabytes of data to a disk that, according to df, has no free space.
5. Open the file created on step 2 with vi, or gedit, or mcedit (not under root!) and delete one line. Press "Save". The editor (mcedit) shows the following warning: "The file has been modified in the meantime. Save anyway?" but it is already not important which button you press: your file is erased (truncated to zero length).
Expected result: the new contents replace the old contents of the file, finally, there must be enough room because the file already exists!
Actual result: the length of file becomes 0, all your data is lost (with any of: vi, gedit, mcedit).
In fact, if you have a full disk where the root's quote is partially used, you can repeat it without copying gigabytes of data. Just create a file testfile.txt under root and:
me@comp:
one
two
three
four
me@comp:
me@comp:
-rw-r--r-- 1 root root 19 Nov 7 21:05 mytestfile.txt
me@comp:
me@comp:
-rw-rw-rw- 1 root root 19 Nov 7 21:05 mytestfile.txt
me@comp:
one
two
three
four
me@comp:
F2 (Save)
Confirm save file: "/more/
[ Save ]
Enter file name:
/more/Documents
The file has been modified in the meantime. Save anyway?
[ Yes ] [ Cancel ]
me@comp:
-rw-rw-rw- 1 root root 0 Nov 7 21:09 mytestfile.txt
me@comp:
me@comp:
me@comp:
me@comp:
/dev/sda1 on /more type ext4 (rw,relatime,
me@comp:
/dev/sda1 480085744 471624064 0 100% /more
me@comp:
/dev/sda1 458G 450G 0 100% /more
Scenario 2 (less realistic, but faster)
1. Take an ext4 drive. Fill it with data almost completely (like 10G free on a 500G grive). Run df and see how much space is left.
2. From under root, write more data than df reported on the previous step to the drive. (Surprisingly, that operation will succeed: about 5% of disk space is reserved for root's needs.)
3. From under root, create a multi-line text file (like 10 lines of 10 characters each). Allow read-write access for anyone.
4. Open the file created on the previous step with vi, or gedit, or mcedit (not under root!) and delete one line. Press "Save". The editor (mcedit) shows the following warning: "The file has been modified in the meantime. Save anyway?" but it is already not important which button you press: your file is erased.
Expected result: the new contents replace the old contents of the file, finally, there must be enough room because the file already exists!
Actual result: the length of file becomes 0, all your data is lost (with any of: vi, gedit, mcedit).
I will not discuss here what component is to blame; it is possible to say that all editors are buggy, but IMO, if you ask me, it is the file system that behaves counterintuitively.
oops! Forgot to specify the exact release. But I think all releases are affected.
me@comp: /more/Documents $ lsb_release -a /more/Documents $ uname -a /more/Documents $
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
me@comp:
Linux comp 5.0.0-32-generic #34~18.04.2-Ubuntu SMP Thu Oct 10 10:36:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
me@comp: