How to use "testdisk" for recovery "/home"?

Everything about X, Gnome, KDE, ... and everything running on it

How to use "testdisk" for recovery "/home"?

Postby hack3rcon » 2019-12-02 10:20

Hello,
Can I use "testdisk" tool to recover specific location? For example, in my PC the "/home" location mounted on:
Code: Select all
# mount
/dev/sda3 on /home type ext4 (rw,relatime)

And:
Code: Select all
Disk: /dev/sda
             Size: 465.8 GiB, 500107862016 bytes, 976773168 sectors
          Label: gpt, identifier: C40840DC-B308-4919-B387-E2BD0C61DD5F

    Device             Start        End    Sectors    Size Type
>>  /dev/sda1           2048    1368063    1366016    667M EFI System           
    /dev/sda2        1368064  177930239  176562176   84.2G Microsoft basic data
    /dev/sda3      177930240  959180799  781250560  372.5G Microsoft basic data
    /dev/sda4      959180800  976771071   17590272    8.4G Linux swap
    Free space     976771072  976773134       2063      1M

but when I use test disk like below show me an error:
Code: Select all
$ sudo testdisk /home/
TestDisk 7.0, Data Recovery Utility, April 2015
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Unable to open file or device /home/: Inappropriate ioctl for device

I don't like to recover all of "sda3".

Thank you.
hack3rcon
 
Posts: 312
Joined: 2015-02-16 09:54

Re: How to use "testdisk" for recovery "/home"?

Postby L_V » 2019-12-02 10:40

TestDisk: Partition scanner and disk recovery tool.
TestDisk checks the partition and boot sectors of your disks.

PhotoRec: file recovery tool (included in testdisk package).
Then try with
Code: Select all
photorec
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: How to use "testdisk" for recovery "/home"?

Postby hack3rcon » 2019-12-03 05:46

I got the same error:
Code: Select all
$ sudo photorec /home/
PhotoRec 7.0, Data Recovery Utility, April 2015
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Unable to open file or device /home/: Inappropriate ioctl for device
hack3rcon
 
Posts: 312
Joined: 2015-02-16 09:54

Re: How to use "testdisk" for recovery "/home"?

Postby L_V » 2019-12-03 08:08

The partition is /dev/sda3
'/home' is just a linux mountpoint or directory that testdisk or photorec do not understand as command parameter.
PhotoRec Step By Step

Code: Select all
/dev/sda3      177930240  959180799  781250560  372.5G Microsoft basic data

Not sure to understand what is " Microsoft basic data". You should clarify this first.
Code: Select all
lsblk -f
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: How to use "testdisk" for recovery "/home"?

Postby hack3rcon » 2019-12-03 11:56

I don't like to recover all of "/dev/sda3". Can I use block for recovery?
Code: Select all
~$ lsblk -f
NAME FSTYPE LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda                                                                   
├─sda1
│                                                                     
├─sda2
│    ext3         81f957de-2a93-4b9c-a07e-49f0fda0848b   59.7G    23% /
├─sda3
│    ext4         8530ffc3-a825-495c-80ec-2f5ed3d94c97  175.7G    47% /home
└─sda4
     swap         d012ba9c-e563-48ee-8d52-d41e21880479                [SWAP]
sdb                                                                   
├─sdb1
│    ntfs   New Volume
│                 B0689675689639D4                        3.3G    98% /mnt/Test1
└─sdb2
     ext4         ea13704a-d326-4414-9afd-d99ba129cc6f   11.2G    91% /mnt/test2
sr0                                                                   
hack3rcon
 
Posts: 312
Joined: 2015-02-16 09:54

Re: How to use "testdisk" for recovery "/home"?

Postby L_V » 2019-12-03 18:11

I've never used photorec (or may be once), but I think you can select recovery by file types.
https://www.cgsecurity.org/wiki/File_Fo ... y_PhotoRec

You can mount your home partition.
Then what happened exactly to your home partition ?
L_V
 
Posts: 1171
Joined: 2007-03-19 09:04

Re: How to use "testdisk" for recovery "/home"?

Postby v&n » 2019-12-04 03:13

Haven't done it myself, but I think you can create a partial image of your partition with ddrescue (gddrescue, telling it 'Bytes to SKIP' + 'Size to copy' - see 'man ddrescue'), then run photorec on that partial disk image.

This will work only if you are sure about the area on which your files needing recovery are located. If your are not sure about that, your files or parts of them may reside anywhere on the disk depending on the availability of free space at the the time of their creation, regardless of 'When' they were created/copied to the disk - thus the need to read entire disk to make sure no files/parts are missing during recovery.

And Yes, @L_V, photorec can recover files by their types, although it is not perfect in guessing the filetypes that are being recovered. I think it makes the guess based on the 'header' of the file-blocks that are being recovered, and can easily get confused, assigning wrong extension names to the recovered files/fragments.

Also, most of the recovered 'files' may be corrupt as they are only fragments. The job of finding/verifying the required files in this huge debris of recovered 'junk' is left to the user of course. Furthermore, it cannot restore their names/directory-structure. It just dumps the recovered data into folders named 'recup.####', naming them after the blocks they were found in (e.g. f001234.txt).
v&n
 
Posts: 624
Joined: 2015-02-04 02:57


Return to Desktop & Multimedia

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable