Try to use debugfs to restore the deleted file on the ext3 File System
Everyone knows that in Linux, it is difficult to restore deleted files! Recovery commands and tools may be different in different file systems. The following describes an attempt to restore the deleted file on the ext3 File System Using the debugfs command in Linux.
[Root] # mkdir/root/test // --> Create a test folder
[Root] # cd/root/test // --> enter the Directory
[Root] # touch test.txt // --> Create a test file name
[Root] # cat/proc/meminfo> test.txt // --> write to the Test File
[Root] # cat test.txt
MemTotal: 16432172 kB
MemFree: 7577528 kB
Buffers': 896832 kB
Cached: 5724212 kB
SwapCached: 0 kB
Active: 2737104 kB
Inactive: 4246932 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 16432172 kB
LowFree: 7577528 kB
SwapTotal: 16777208 kB
SwapFree: 16777208 kB
Dirty: 1944 kB
Writeback: 0 kB
AnonPages: 362976 kB
Mapped: 179000 kB
Slab: 1756168 kB
PageTables: 9432 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 24993292 kB
Committed_AS: 1469296 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 291068 kB
VmallocChunk: 34359447031 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
[Root] # rm test.txt // --> Delete this test file
[Root] # ls-lart // --> check whether to delete
Total 12
Drwxr-x --- 6 root 4096 Aug 6 ..
Drwxr-xr-x 2 root 4096 Aug 6.
[Root] # mount-r-n/dev/mapper/vg00-lvol1 // --> re-mount in the same way as only, to prevent other processes from using
[Root] # df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/rootVG-root
83G 7.4G 72G 10%/
/Dev/mapper/rootVG-tmp
3.9G 137 M 3.6G 4%/tmp
/Dev/mapper/rootVG-var
31G 5.0G 24G 18%/var
/Dev/cciss/c0d0p1 145 M 26 M 111 M 19%/boot
/Dev/mapper/vgglobal-lvol2
27G 291 M 25G 2%/home
/Dev/mapper/vgglobal-lvol1
105G 7.3G 93G 8%/d/oss/global
[Root @ nas2ds1 test] # df-T
Filesystem Type 1K-blocks Used Available Use % Mounted on
/Dev/mapper/rootVG-root
Ext3 86623180 7696528 74455460 10%/
/Dev/mapper/rootVG-tmp
Ext3 4062912 139456 3713744 4%/tmp
/Dev/mapper/rootVG-var
Ext3 31741856 5222564 24880892 18%/var
/Dev/cciss/c0d0p1
Ext3 147764 26611 113524 19%/boot
/Dev/mapper/vgglobal-lvol2
Ext3 27447508 297580 25755652 2%/home
/Dev/mapper/vgglobal-lvol1
Ext3 109806464 7579200 96649332 8%/d/oss/global
[Root] # debugfs // --> Use this command
Debugfs 1.39 (29-May-2006)
Debugfs: open/dev/mapper/rootVG-root // --> open the file system
Debugfs: ls-d/root/test // --> View the deleted file
16269861 (12). 16269793 (4084) .. <16269863> (4072) test.txt
Debugfs: logdump-I <16269861> // --> View the block where the node is located
Inode 16269861 is at group 497, block 16285700, offset 512
Journal starts at block 6182, transaction 1128695
FS block 16285700 logged at sequence 1128698, journal block 6330
(Inode block for inode 16269861 ):
Inode: 16269861 Type: bad type Mode: 0000 Flags: 0x0 Generation: 0
User: 0 Group: 0 Size: 0
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 0
Fragment: Address: 0 Number: 0 Size: 0
Ctime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Atime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Mtime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Blocks:
FS block 16285700 logged at sequence 1128704, journal block 6727
(Inode block for inode 16269861 ):
Inode: 16269861 Type: bad type Mode: 0000 Flags: 0x0 Generation: 0
User: 0 Group: 0 Size: 0
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 0
Fragment: Address: 0 Number: 0 Size: 0
Ctime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Atime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Mtime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Blocks:
FS block 16285700 logged at sequence 1128705, journal block 6819
(Inode block for inode 16269861 ):
Inode: 16269861 Type: bad type Mode: 0000 Flags: 0x0 Generation: 0
User: 0 Group: 0 Size: 0
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 0
Fragment: Address: 0 Number: 0 Size: 0
Ctime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Atime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Mtime: 0x00000000 -- Thu Jan 1 07:00:00 1970
Blocks:
FS block 16285700 logged at sequence 1128707, journal block 6860
(Inode block for inode 16269861 ):
Inode: 16269861 Type: directory Mode: 0755 Flags: 0x0 Generation: 285284165
User: 0 Group: 0 Size: 4096
File ACL: 0 Directory ACL: 0
Links: 2 Blockcount: 8
Fragment: Address: 0 Number: 0 Size: 0
Ctime: 0x53e18a66 -- Wed Aug 6 09:52:38 2014
Atime: 0x53e18a44 -- Wed Aug 6 09:52:04 2014
Mtime: 0x53e18a66 -- Wed Aug 6 09:52:38 2014
Blocks: (0 + 1): 16312328
Found sequence 1127169 (not 1128751) at block 9518: end of journal
Debugfs: quit // --> after exiting, run the dd command, set count to 1, and skip to the value you just viewed and put it in the/tmp directory.
[Root] # dd if =/dev/mapper/rootVG-root of =/tmp/test.txt. bak bs = 4096 count = 1 skip = 16312328
1 + 0 records in
1 + 0 records out
4096 bytes (4.1 kB) copied, 4.1e-05 seconds, 99.9 MB/s
[Root] # cat/tmp/test.txt // --> check content, consistent with the original!
MemTotal: 16432172 kB
MemFree: 7577528 kB
Buffers': 896832 kB
Cached: 5724212 kB
SwapCached: 0 kB
Active: 2737104 kB
Inactive: 4246932 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 16432172 kB
LowFree: 7577528 kB
SwapTotal: 16777208 kB
SwapFree: 16777208 kB
Dirty: 1944 kB
Writeback: 0 kB
AnonPages: 362976 kB
Mapped: 179000 kB
Slab: 1756168 kB
PageTables: 9432 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 24993292 kB
Committed_AS: 1469296 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 291068 kB
VmallocChunk: 34359447031 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
View gpio status using sharing software in Linux debugfs
Use debugfs for debugging in Linux
Introduction to debugfs in Linux driver debugging
In the ext2 File System on Linux, debugfs is used to restore deleted files.
This article permanently updates the link address: