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.

  • @lurch
    link
    44
    edit-2
    7 months ago

    before you change anything it would be good to use dd and save the whole drive to a bigger drive or maybe compress it with gzip while using dd to save it to a slightly smaller one. That takes a very long time, but gives you the ability to start over with your recovery. Only do that if it’s worth to wait several hours.

    photorec can also recover some files by looking at the raw data still there, if all else fails.

    • @[email protected]
      cake
      link
      fedilink
      26
      edit-2
      7 months ago

      That’s what people always underestimate about data recovery jobs: you need lots of space. One copy for safekeeping. One to work on. One disk of the same size you store recovered files on.

      Whenever friends or family ask me to look at a disk I always tell them to give me the disk and two new ones of the same or greater capacity and I’ll give it a shot. Usually they discover the data isn’t that important after all. If it is I have all I need.

    • @sun_is_ra
      link
      English
      97 months ago

      use dd and save the whole drive to a bigger drive or maybe compress it with gzip while using dd to save it to a slightly smaller one

      command would be something like this:

      dd if=/dev/…/myparition|gzip status=progress > /mnt/external_hd/mypartition.gzip

      • @[email protected]
        link
        fedilink
        6
        edit-2
        7 months ago

        Wouldn’t you want to use

        dd if=/dev/sda3 of=/dev/sdc1 status=progress && sync

        Where /dev/sda3 is the damaged partition and /dev/sdc1 is the freshly formatted external drive

        You’ll find your attached devices with lsblk

        You’re going to want to make sure /dev/sda3(broken partition) is unmounted so as not to write any more data to it.

        • @[email protected]
          link
          fedilink
          English
          4
          edit-2
          7 months ago

          To add on to this answer (which is correct):

          Your “of” can also just be a regular file if that’s easier to work with vs needing to create a new partition for the copy.

          I’ll also say you might want to use the block size parameter “bs=” on “dd” to speed things up, especially if you are using fast storage. Using “dd” with “bs=1G” will speed things up tremendously if you have at least >1GB of RAM.

        • @sun_is_ra
          link
          English
          27 months ago

          this clones one parition to another which is fine if you have free partition with enough space lying around. My code was for taking compressed backup of the partition to be restored later if needed. Its less convenient but doesnt require as much space nor does it require an entire partition

          • @[email protected]
            link
            fedilink
            17 months ago

            Don’t you have to read the partition to compress it, which is fine on a healthy partition but can further damage a broken one?

            • @sun_is_ra
              link
              English
              07 months ago

              depends on what you mean by “broken”. If broken means has bad sector or other hardware issue, then yes OP should transfer data to healthy partition and work from there. though it certainly won’t hurt if he attempted to recover data from broken partition (worst the HD dies and OP restore the backup on healthy HD) However he said “i broke my partition” which make me think its software issue, not hardware. in which case, would be faster to recover data directly after taking backup

  • @[email protected]
    link
    fedilink
    197 months 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!

  • @[email protected]
    link
    fedilink
    15
    edit-2
    7 months ago

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

  • lemmyvore
    link
    fedilink
    English
    137 months ago

    It would help if you told us what exactly you did to break the partition.

  • Illecors
    link
    fedilink
    English
    117 months 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.

    • @[email protected]
      link
      fedilink
      87 months ago

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

      … exact same starting block, size and geometry.

    • @[email protected]
      link
      fedilink
      47 months ago

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

  • auth
    link
    fedilink
    0
    edit-2
    7 months ago

    Did you delete the partition? Or quick format?

  • @[email protected]
    link
    fedilink
    English
    -47 months ago

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