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.

  • 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
    Possible duplicate of Can overwritten files be recovered? – jasonwryan Nov 30 '17 at 17:18
  • 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. – user259412 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 1 '17 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.