1

I had my USB hard drive partitioned with ext4. Then I accidentally did

mkswap /dev/sda1
swapon /dev/sda1

Now I cannot mount my drive and it seems like my data is gone. Is there any way to recover?

Per comments below, I am trying qphotorec. However, I think I will have to go buy another drive and recover all files to it, since I'm running low on space; I'll report back later.

But I did run it a little bit, and it's finding a lot of stuff that wasn't there so it's a bit confusing. Like jpg, txt, and zip files that I'm pretty sure were never on that drive. But I'll have to recover all to really see what all it finds.

enter image description here Does it matter which partition I select here?

FYI: It was NTFS, then I reformatted to EXT4 (had backed up the NTFS drive then restored to the EXT4 after reformatting), then did the accidental mkswap, I didn't think photorec would find the NTFS partition but I guess it did.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • Presuming that /dev/sda was the device which you referred to as your 'USB hard drive', then no: your data have been overwritten by swap. – DopeGhoti Nov 30 '17 at 16:12
  • mkswap won’t have overwritten the whole partition, nor will swapon, so there’s a possibility PhotoRec will recover some data (unless the partition was encrypted). – Stephen Kitt Nov 30 '17 at 16:13
  • 2
  • 1
    @jasonwryan mkswap overwrites only the first bytes of the filesystem headers, unfortunately it is the most important part of the whole fs. The other question is about the recovery of deleted files. The questions are only a little bit similar (for example, e2fsck with a sparse superblock could likely help here, but not in the other case). These are not dupes. – peterh Nov 30 '17 at 22:10
  • 1
    @peterh. mkswap does more than just overwrite the first bytes of the filesystem headers if it is built with libblkid support enabled. – fpmurphy Dec 01 '17 at 02:07
  • im currently trying qphotorec since yesterday, its been running a while and seems like it still has a while to go. it has recovered some of my files so far, so thats good – owen gerig Dec 01 '17 at 13:56

0 Answers0