While trying to format my USB key, I accidentally selected /dev/sda and proceeded to format the disk. Luckily, the formatting was interrupted when GParted noticed the drive was currently mounted. However, I can't see the partitions anymore (even when I restart GParted, I keep seeing this):

I haven't rebooted yet as I am afraid to do so. At the moment, I can use my filesystem just fine but I'm afraid that if I reboot some bad things might happen. What can I do to fix this? Is it safe to reboot?

UPDATE:

I was attempting to create a bootable USB key for Windows 7 so I clicked Device/Create partition table and selected "msdos". I then attempted to create a primarty partition (NTFS) and got an error due to the fact that /dev/sda was already mounted. I'm not sure where I can get an exact log. Here's the output of sudo fdisk -l:

As I said, my file system is correctly mounted so I can backup all my files but I'd rather not go through that lengthy process if it is safe to reboot or if there's a way to fix this before rebooting...

Does sudo mount /dev/sda1 /mnt successfully mount the filesystem on /mnt? gparted should keep a log of what it did, but it is lost when you close gparted, unless you chose "Save details".
–
geirhaJul 25 '12 at 9:45

Now when I open GParted it says "Mounted on /, /mnt". Is that a good sign? Can I safely reboot?
–
Olivier LalondeJul 25 '12 at 9:57

You need to tell us HOW you were running gparted. What is the output of sudo fdisk -l? It should be easy to save/restore the in-memory layout of sda. However if at all possible I would back up the important stuff to an external drive/another disk/etc. without rebooting.
–
izxJul 25 '12 at 9:58

1

Yes, there's hope :). Backup important data though... If geirha doesn't solve this for you before then, I will continue working on this in about 12 hours.
–
izxJul 25 '12 at 10:53

Is what I get on my system. If it does not recognize your filesystem properly anymore then I am not sure whether there is much more you can do.

I recommend making a backup of all of your most important files in this case, since you might be able to use fdisk or cfdisk to set the partition type, and afterwards use fsck to check the filesystem.

But I am not sure whether it will still fix your partition. Things like this can really be bummer, I accidentally typed rm -rf /tmp / once, in the split second that I pressed CTRL+C half of my /bin was already removed and I had to reinstall.

I hope my advise guides you in the right direction and that you are able to fix your system.

If you run into anything just let me know.

Answer to Update 3:

I believe Write is the way to go. It should restore the partition type and flags as they were before gparted. However I cannot state how important it is to have a backup just in case something does go wrong.

After 'testdisk' is done run 'fdisk -l /dev/sda' again and post output.

I'm having trouble replicating your scenario -- if a partition is mounted, whether explicitly (fstab/mount), or implicitly (by Nautilus, etc.), GParted will not let you create a partition table on the parent device before unmounting.

I suspect GParted successfully overwrote the MBR/partition table on /dev/sda. Rebooting WILL make the contents inaccessible, don't do it yet. If you are prepared to, I believe testdisk should be able to recover the partition table.

There should be a way to get the in-memory (kernel) partition table layout -- that's how you can still access the contents -- but I can't remember an easy way to do that.

In the meanwhile it may be a good idea to at least back the critical stuff up....