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.
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.
/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:12mkswap
won’t have overwritten the whole partition, nor willswapon
, so there’s a possibility PhotoRec will recover some data (unless the partition was encrypted). – Stephen Kitt Nov 30 '17 at 16:13mkswap
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:10mkswap
does more than just overwrite the first bytes of the filesystem headers if it is built withlibblkid
support enabled. – fpmurphy Dec 01 '17 at 02:07