LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   rebuild partitions/label from existing partitions - used parted on wrong drive (https://www.linuxquestions.org/questions/linux-software-2/rebuild-partitions-label-from-existing-partitions-used-parted-on-wrong-drive-4175471009/)

zedmelon 07-26-2013 09:38 AM

rebuild partitions/label from existing partitions - used parted on wrong drive
 
After seeing a GPT warning on a 500G drive I wanted to assimilate, I used parted on the wrong drive--my OS drive. Is there a way to reconstruct what I've broken?

The drive I wanted to use
Code:

fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

My confusion began while I inspected the drive for any remaining Winfiles I wanted to keep. I ran parted while the drive was still mounted; it complained, I unmounted the drive, and then I used parted and mklabel msdos.

Unfortunately, I ran it on /dev/sda and not /dev/sdb. When it complained again about being in use, I figured it was a residual tag or something. Not noticing I'd typed the wrong drive letter, I verified in another console that the drive was indeed unmounted. It was, I proceeed, and now I am fearful to reboot.

The drive before I killed it
Code:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe643427f

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          63    35150219    17575078+  7  HPFS/NTFS/exFAT
/dev/sda2        35150220    93739274    29294527+  7  HPFS/NTFS/exFAT
/dev/sda3        93739275    95699204      979965  83  Linux
/dev/sda4        95699205  312581807  108441301+  5  Extended
/dev/sda5        95699268  113274314    8787523+  83  Linux
/dev/sda6      113274378  125965664    6345643+  83  Linux
/dev/sda7      125965728  127925594      979933+  83  Linux
/dev/sda8      127925658  129885524      979933+  83  Linux
/dev/sda9      129885588  132809354    1461883+  83  Linux
/dev/sda10      132809418  142576874    4883728+  83  Linux
/dev/sda11      142576938  304769114    81096088+  83  Linux
/dev/sda12      304769178  312581807    3906315  82  Linux swap

After I broke it, no partitions are listed:
Code:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00077593

  Device Boot      Start        End      Blocks  Id  System

Afterward, I saw a warning that listed all these partitions which were removed, but the kernel wasn't notified. WHAT?!? Oh, crap. At least I still have a scrollback record of what they should be. I've already archived everything from the "disqualified" partitions in case I've royally hosed myself.

Ugh. I've begun a lovely pattern; my last LQ post began with a typo as well, and it bore a strikingly similar theme.
:-(

Is there a way to reinstate from the still-running partitions?
/n00b

TobiSGD 07-26-2013 09:53 AM

You can just use fdisk to recreate the partitions with the exact same blocks (gladly you have the start- and end-sectors), or you could install Testdisk and let it scan for your partitions.

zedmelon 07-26-2013 03:03 PM

Quote:

Originally Posted by TobiSGD (Post 4997256)
You can just use fdisk to recreate the partitions with the exact same blocks

I thought of this but--unlike my brazen efforts to format a relatively unimportant drive--I first wanted an active second opinion instead of passive Google results, just to ensure against further breakage.

Quote:

Originally Posted by TobiSGD (Post 4997256)
(gladly you have the start- and end-sectors)

Yeah, as soon as I saw
Code:

/dev/sda1 won't be reported to kernel
/dev/sda2 won't be reported to kernel
...

(or similar), I immediately copied relevant scrollback to ensure I had as much forensics material as possible.

Quote:

Originally Posted by TobiSGD (Post 4997256)
install Testdisk and let it scan for your partitions.

Haven't heard of Testdisk; I'll check it out. Thanks Tobi.

John VV 07-26-2013 03:08 PM

Quote:

/dev/sda1 won't be reported to kernel
/dev/sda2 won't be reported to kernel
...
so your automounting partitions
disable automount !
or
use a live dvd/cd like gparted livd cd
or
System Rescue CD

zedmelon 07-26-2013 03:42 PM

Quote:

Originally Posted by John VV (Post 4997478)
so your automounting partitions

well, sorta. These partitions automount, but they're my OS drive, so they should.

I ran the parted utility on the wrong drive with a typo and therefore processed partitions which were still mounted in the first place--I'd already unmounted the drive I intended to impact. I'm not at home right now so am paraphrasing the message it actually gave**. It was something along the lines of
Code:

partition /dev/sda1 has been rewritten, but this has not yet been reported to the kernel, please reboot for changes to take effect
(repeat eleven more times)


** I also can't unequivocally mark this thread as solved, since only a reboot will verify the fix worked, and I'm not going to try that remotely. I may run with scissors, but I'm not going to do it in the dark!
:-)


All times are GMT -5. The time now is 04:41 PM.