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.
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.
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.
I totally spaced on BS=4M which I believe is the standard block size for ext4
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
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?