While I was switching distros, I accidentally broke a partition. I’m almost certain that all the data is there, but it doesn’t have a filesystem (I used ext4). Is there anything I can do to fix it, similar to changing the file extension without changing the contents. PS: It’s a data partition. I was trying to resize it, accidentally also moved it to the left, found out that it was taking forever to move it, so I cancelled it. Finished the move to the left operation (I think), but it threw up an error about the filesystem. I don’t remember what it was, though.

Thanks to everyone who suggested Testdisk. It worked almost perfectly.

  • namingthingsiseasy@programming.dev
    link
    fedilink
    arrow-up
    20
    ·
    1 year ago

    First thing is to not mount it at all. Any writes to the overwritten partition will corrupt your data.

    Second thing: install system rescue cd to a live usb and boot it. Look into testdisk and photorec. It’s been a while since I’ve had to use these tools, but I believe testdisk can restore the partition and photorec can find files in a file system that has been deleted. I would try running photorec first to save the recovered files to an external hard disk, and then testdisk to try restoring them. But disclaimer: it’s been a while since I’ve had to do this, so my memory is foggy here.

    Good luck!

  • bizdelnick@lemmy.ml
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    1 year ago

    Try testdisk. It can find a filesystem, copy files from it or restore the partition that contained it.

  • Illecors@lemmy.cafe
    link
    fedilink
    English
    arrow-up
    12
    ·
    1 year ago

    You can try fdisk.

    If the partition table is there - create a new partition at the exact same location, of the exact same size.

    If the partition table is not there - create *the exact same type (mbr vs gpt) partition table, then do the first if.

    Fdisk should tell you that it found a filesystem signature. Do not wipe it.

    • NeoNachtwaechter@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      1 year ago

      there - create a new partition at the exact same location, of the exact same size.

      … exact same starting block, size and geometry.

    • mvirts@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Seconded. This is one of the things testdisk is built for, searching for lost filesystems and adding partition table entries to recover them.

  • TheFriendlyArtificer@beehaw.org
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    1 year ago

    Depends on how you “broke” it.

    First step is to back up whatever data is there. Boot into a rescue distro like GRML dd the block device to an external hard drive.

    If you nuked the partition table, there may be additional work to rebuild it if you used GPT rather than MBR. But gdisk should also tell you if there are backups, which would make your life way easier.

    If you still have a partition (like /dev/sda1) but the mount command claims that it cannot find a valid ext signature, you might be able to simply use mkfs.ext4. It’s counterintuitive, but this isn’t destructive and will recreate the filesystem leaving the data alone. And if it does turn out to be destructive, that’s why you have your backup.

    To recover from the backup, you can use scalpel or photorec from the testdisk package. Photorec holds your hand and can be run in read-only mode. Caveat: These tools work by looking for specific file headers and makes a best guess as to where it’ll end (if the format doesn’t have a defined footer).

    In the car now, but I can respond with more detailed steps if your other options don’t pan out.

  • Vqhm@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    Two tools worth using:

    DMDE

    Photorec

    If the data is extremely important make a back up first.

  • MalReynolds@slrpnk.net
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    5
    ·
    1 year ago

    Now learn 3:2:1 backup principles, this problem will recede, the lessons learned are for a lifetime, or more…