2

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):

gparted problem

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:

➜  ~  sudo fdisk -l
[sudo] password for olalonde: 

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001db65

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       60801   488384001    7  HPFS/NTFS

Disk /dev/sdb: 7998 MB, 7998537728 bytes
255 heads, 63 sectors/track, 972 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005e98c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         972     7807558+   7  HPFS/NTFS

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...

UPDATE 2:

Output of mount and cat /proc/mounts:

➜  ~  mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
/home/olalonde/.Private on /home/olalonde type ecryptfs (ecryptfs_check_dev_ruid,ecryptfs_sig=ee352762b400fa23,ecryptfs_fnek_sig=70e5eee62e053b1b,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs)
gvfs-fuse-daemon on /home/olalonde/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=olalonde)
/dev/sda1 on /mnt type ext4 (rw)

➜  ~  cat /proc/mounts
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=2005108k,nr_inodes=501277,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
/dev/disk/by-uuid/bbf66c3f-ae71-4389-9f83-282e95ce6ee9 / ext4 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0
none /sys/fs/fuse/connections fusectl rw,relatime 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0
none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0
none /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
/home/olalonde/.Private /home/olalonde ecryptfs rw,relatime,ecryptfs_fnek_sig=70e5eee62e053b1b,ecryptfs_sig=ee352762b400fa23,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs 0 0
gvfs-fuse-daemon /home/olalonde/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
/dev/sda1 /mnt ext4 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0

UPDATE 3:

I am trying to use testdisk. Can anyone confirm that I'm doing this right and whether I should click that scary looking "Write"?

enter image description here enter image description here enter image description here enter image description here (selected N) enter image description here enter image description here

15
  • 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".
    – geirha
    Jul 25, 2012 at 9:45
  • It does work. pastebin.com/ynbgp2eM Jul 25, 2012 at 9:56
  • Now when I open GParted it says "Mounted on /, /mnt". Is that a good sign? Can I safely reboot? Jul 25, 2012 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.
    – ish
    Jul 25, 2012 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.
    – ish
    Jul 25, 2012 at 10:53

3 Answers 3

2

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....

1
  • +1 for the backup suggestion. But I think, Gparter allow creating a new partition table on the parent device before unmounting
    – Anwar
    Jul 25, 2012 at 10:53
1

I just reproduced your problem in a virtual machine using fdisk instead of gparted.

Before I had:

  Device  Boot  Start   End    Blocks   Id  System
/dev/sda1   *       1    18    144553+  83  Linux
/dev/sda2          19  2450  19535040   83  Linux
/dev/sda4        2451  2610   1285200   82  Linux swap / Solaris

I then used fdisk to delete partitions 4, 2 and 1 and create a new primary partition covering the whole disk. I then changed the type to NTFS (07) and wrote it to disk.

fdisk -l /dev/sda then reported:

  Device  Boot  Start   End    Blocks   Id  System
/dev/sda1           1  2610  20964793+   7  HPFS/NTFS

I then ran 'testdisk /dev/sda' which almost instantly came up with a list of partitions which when written were reported as:

  Device  Boot  Start   End    Blocks   Id  System
/dev/sda1   *       1    18    144553+  83  Linux
/dev/sda2          19  2450  19535040   83  Linux
/dev/sda3        2451  2610   1285200   82  Linux swap / Solaris

The only difference is that it moved /dev/sda4 to /dev/sda3. The VM rebooted successfully.

In your case, since mount shows you only have a single partition, /dev/sda1, testdisk should be able to recover it without any problem.

In any event, testdisk gives you the option of deciding whether to write its findings out, so you can't lose by running it. Obviously, you may need to do sudo apt-get install testdisk.

Of course, if it's possible, it's probably prudent to back up anything critical.

1

Could you do:

sudo fdisk -l /dev/sda

This way you should be able to see if it still recongizes the partitions, e.g:

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1171455      584704   83  Linux
/dev/sda2         1171456     3125247      976896   82  Linux swap / Solaris
/dev/sda3         3127294    15611903     6242305    5  Extended
/dev/sda5         3127296    13869483     5371094   83  Linux
/dev/sda6        13871104    15611903      870400   83  Linux

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .