4

As far as I know, a solid-state drive (SSD) stores data in different locations that the operating system cannot control. If I accidentally delete a partition, and then enter the exact start and end blocks of the previous partition when creating a new partition with fdisk, can I recover the files as I would on a regular hard drive (HDD)?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 2
    CAUTION: Before making *any* changes to the drive at all, image every single byte of the drive in raw form. That way, you can always restore the drive to where it is now and, if necessary, you can experiment with data recovery attempts on copies of that image. – David Schwartz Apr 30 '23 at 00:57

2 Answers2

10

Yes.

SSDs move blocks around internally, but the block numbers they present as the interface to whatever is talking to them remain consistent and point to the same stored data, wherever it happens to be; so restoring a partition with the same start and end sectors as it had previously will restore the partition as it was.

The only risk is if you trim the drive and the tool you use to trim discards the blocks which used to be in the deleted partition; if that happens you won’t be able to restore anything. (This isn’t specific to SSDs; some hard drives support block discard, and thin-provisioned storage supports block discard too.)

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Just make sure when you re-establish the partition boundaries that your tool does not make a new filesystem automatically for you – roaima Apr 29 '23 at 10:56
  • @Stephen Kitt: When writing data, SSD is willing to use the blocks which has fewer writes or just the one is zero or any rules? – auzyveyauzyvey Apr 29 '23 at 12:57
  • @auzyveyauzyvey that depends on the drive’s firmware. In any case it’s transparent to the operating system. – Stephen Kitt Apr 29 '23 at 12:59
  • @roaima: I did it myself...As that if I didn't, I thought I couldn't see whether the data is there. When I rebuilt the partition with the right number, `fdisk` didn't tell me the NTFS signature, it means my data has gone? – auzyveyauzyvey Apr 29 '23 at 13:08
  • @auzyveyauzyvey `fdisk` doesn’t know about file systems, just partition types, and it‘s up to you to set those. To check whether your data is still there, you need to try mounting the file system. If you care about your data but don’t have recent enough backups, make a copy of the drive first. – Stephen Kitt Apr 29 '23 at 14:28
  • 1
    The NTFS signature is from the PBR - partition boot sector. With NTFS, the PBR must match the partition, it has some info on start & size of partition as well as other Windows info. I would have tried testdisk first. http://www.cgsecurity.org/wiki/TestDisk_Step_By_Step Sometimes deeper search may show files & best to immediately back them up, as some never see them again. – oldfred Apr 29 '23 at 14:32
  • Can the OS tell the SSD to store or modify a data in a specific block? – auzyveyauzyvey May 01 '23 at 08:03
-1

I really don't think fdisk is the right tool for this, if you want to get data back from the SSD you need to avoid writing ANYTHING to the drive. I don't know this for sure but I would expect fdisk to create a new blank partition boot record when it creates the new partition.

A deleted partition requires a proper partition recovery tool. I don't have a recomendation but if it is a NTFS partition you might need a Windows based recovery tool?

If you have a big enough hard drive lying around then it might be worth cloning the SSD sector-for-sector?

  • 2
    fdisk does not do "partition boot records" (and I don't think I've seen _any_ partitioning tool that would), as those are dependent on what will be put in that partition later – there is no generic PBR that it could use anyway. – u1686_grawity Apr 30 '23 at 11:54
  • You got me there, the PBR is only set during formatting, right? Well if fdisk strictly only sets the partition table entry and doesn't touch the partition contents at all then OP's plan could work. – Oliver Broad May 22 '23 at 17:14