Blew away my partition table

J. Epperson Dell at
Tue Jun 29 19:54:54 CDT 2010

On Tue, June 29, 2010 19:59, Ray Van Dolson wrote:
> On Tue, Jun 29, 2010 at 04:54:11PM -0700, J. Epperson wrote:
>> Thanks to all for the input, and particularly to Bond for getting me
>> thinking about the kernel data on disks in /proc and /sys, since the
>> kernel doesn't know about the mishap yet.  I got the start sectors
>> and sizes out of /sys/block/sda/sda* and I think I'll get the table
>> restored with parted's rescue command.  I should be able to reset the
>> MBR with grub-install.
> If you've taken notes, would be nice to reply back here with your
> procedure.
> Ray

Here's what it looks like so far.  For those who missed the trim, I
stupidly overwrote the /dev/sda partition table with a blank one.

Get the partition starts and sizes from /sys/block/sda/sda*.  Handy query:
grep . /sys/block/sda/sda*/{start,size}
Start parted for /dev/sda, change units to sectors:
u s
Then start rescuing using start and end=start+(size - 1):
rescue 63 401624
was my command for /dev/sda1 (/boot).
After rescuing, set boot flag on sda1:
set 1 boot on
Continue rescuing other partitions.

It found /boot and / ok, didn't recognize swap as a partition for sda3,
but I made that manually and it shouldn't matter if the size is off a few
sectors (the start-end of what it found for sda1 and sda2 didn't match
calculations for start-end, was off by -2 on sda1, by -6 on sda2).  I used
parted command:
mkpart primary linux-swap 139299616 143380124

Still have to do a grub-install /dev/sda (probably after booting rescue). 
I won't get around to testing this on a reboot for a day or two, need to
wait until I know I'll have time to restore from an image I took a few
months ago and reload from rsync if I didn't get it right.

Right now it looks like:
(parted) p
Model: MegaRAID LD 0 RAID1 70G (scsi)
Disk /dev/sda: 143380480s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start       End         Size        Type     File system  Flags
 1      63s         401622s     401560s     primary  ext3         boot
 2      401625s     139299608s  138897984s  primary  ext3
 3      139299616s  143380124s  4080509s    primary               swap

or in default units:

Model: MegaRAID LD 0 RAID1 70G (scsi)
Disk /dev/sda: 73.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  206MB   206MB   primary  ext3         boot
 2      206MB   71.3GB  71.1GB  primary  ext3
 3      71.3GB  73.4GB  2089MB  primary               swap

The /proc/partitions and /sys/block/sda dumps looked like:

[root at server ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   71690240 sda
   8        1     200781 sda1
   8        2   69448995 sda2
   8        3    2040255 sda3
   8       16  488386584 sdb
   8       17  488384001 sdb1

[root at server ~]# grep . /sys/block/sda/sda*/{start,size}

Will post back on final results.  Oh, this is a Fedora 12 system, mostly
sendmail, imap, and httpd, on an ancient Precision 530 with a PERC3.

Thanks again.

More information about the Linux-PowerEdge mailing list