4

I have the partition /dev/sdb1 with file-system ext3 mounted at /mnt/folder.

I touch a file in /mnt/folder and remove that file. Then I use debugfs /dev/sdb1 and then enter lsdel, but it says "0 deleted inodes found."

What is problem? How i recover my file with debugfs?

2 Answers 2

9

Not suitable for ext3/ext4.

From man:

list_deleted_inodes [limit]
    List  deleted inodes, optionally limited to those deleted within limit
    seconds ago.  Also available as lsdel.

    This command was useful for recovering from accidental file  deletions
    for  ext2 file systems.  Unfortunately, it is not useful for this pur‐
    pose if the files were deleted using ext3 or ext4, since  the  inode's
    data blocks are no longer available after the inode is released.

Example:

$ echo Hello > foo.txt
$ ls -ial
35692596 .
35692545 ..
35692597 foo.txt

$ sudo debugfs -R 'inode_dump <35692597>' /dev/sdc5

0000  b481 e803 0600 0000 82d0 d056 82d0 d056  ...........V...V
0020  82d0 d056 0000 0000 e803 0100 0800 0000  ...V............
0040  0000 0000 0100 0000 d36c 2f0b 0000 0000  .........l/.....
0060  0000 0000 0000 0000 0000 0000 0000 0000  ................
*
...

As this is a small file we only have one block i_block (offset 0x28).

The above can be laid out as:

b481      |      81b4 = i_mode        : 0100664 (octal)
e803      |      03e8 = i_uid         :    1000
0600 0000 | 0000 0006 = i_size_lo     :       6
dbd7 d056 | 56d0 d7db = i_atime       : Fri Feb 26 23:55:23 CET 2016
dbd7 d056 | 56d0 d7db = i_ctime       : Fri Feb 26 23:55:23 CET 2016
dbd7 d056 | 56d0 d7db = i_mtime       : Fri Feb 26 23:55:23 CET 2016
0000 0000 | 0000 0000 = i_dtime       :       0
e803      |      03e8 = i_gid         :    1000
0100      |      0001 = i_links_count :       1
0800 0000 | 0000 0008 = i_blocks_lo   :       8, 8 * 512 = 4096 b
0000 0000 | 0000 0000 = i_flags       :       0
0100 0000 | 0000 0001 = i_osd1        :       1

Direct Block Address:

d36c 2f0b | 0b2f 6cd3 = i_block[0]    : 187657427
0000 0000 | 0000 0000 = ... no more

We can calculate offset to data in partition by block size (here 4096):

0x0b2f6cd3 * 4096 = 768644820992

Then dump by direct read:

$ sudo dd if=/dev/sdc5 bs=1 skip=768644820992 count=6 | hd
00000000  48 65 6c 6c 6f 0a                                 |Hello.|

Now, if we rm foo.txt, one can fetch the data by same dd command as above. But it can at any moment be overwritten.

But if we do not know this offset we get short.

$ ls -ai1
35692596 .
35692545 ..

$ sudo debugfs -R 'ls -d <35692596>' /dev/sdc5
 35692596  (12) .    35692545  (4084) ..   <35692597> (4072) foo.txt

$ sudo debugfs -R 'inode_dump <35692597>' /dev/sdc5

The inode data is now:

b481      | 
e803      |
0000 0000 | 0000 0000 = i_size_o      : 0                            *changed
dbd7 d056 | 56d0 d7db = i_atime       : Fri Feb 26 23:55:23 CET 2016
e5d7 d056 | 56d0 d7e5 = i_ctime       : Fri Feb 26 23:55:33 CET 2016 *changed
e5d7 d056 | 56d0 d7e5 = i_mtime       : Fri Feb 26 23:55:33 CET 2016 *changed
e5d7 d056 | 56d0 d7e5 = i_dtime       : Fri Feb 26 23:55:33 CET 2016 *changed
e803      |
0000      |      0000 = i_links_count : 0                            *changed
0000 0000 | 0000 0000 = i_blocks_lo   : 0                            *changed
0000 0000 |
0100 0000 |

0000 0000 | 0000 0000 = i_block[0]    : Zeroed out.                  *changed
0000 0000 |
0000 0000 |

As you can see the block data is zeroed out.

1
  • what is mean the value in parenthesis ? 35692596 (12) . 35692545 (4084) .. <35692597> (4072) foo.txt
    – mug896
    Commented Mar 3, 2020 at 5:58
4

Debugfs is not a file recovery program. That it can sometimes recover deleted files if you are very lucky is an accident.

File recovery in real operating systems (as opposed to MS-DOS, for example) is spelled "backups".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .