LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-02-2006, 06:36 PM   #1
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Rep: Reputation: 45
restore partition table from the cache?


Doh! All of the sudden, I couldn't access any of my data on my NFS mount. When I went to go check it out, my partition no longer exists (cfdisk shows no partitions). This is the most important hard drive in my house since it is the storage drive for the network.

I've been working on a remote partitioning utility and while I don't know exactly how it happened, I'm pretty sure this is what caused it (which is weird since it doesn't actually partition yet, just creates a partition table ready to be written to the disk).

OK, now for my question.

Back when I was doing my initial testing, I was using sfdisk to dump the partition table to a file, modify and write it back to the disk. I was able to do this while still working in Linux, (as long as I restored the original output before I rebooted). I belive this was because partition table was cached.

Can I somehow grab this "cached" partition table and write it back to my disk and *hopefully* save my 250Gb of data? (included some development work for my project)

I haven't modified the disk, or rebooted, so theoretically, I should just be able to restore the partition table and be good to go ...right?

Here's hoping,
...drkstr

**edit**
FYI, I do know the start/end sectors (we'll I can calculate them that is, luckly it's only 1 partition). I could just overwrite the partition table manually, but I wanted to check first before I ruin my chances for good.

Last edited by drkstr; 09-02-2006 at 07:10 PM.
 
Old 09-02-2006, 07:09 PM   #2
theoffset
Member
 
Registered: Aug 2005
Location: Guadalajara, Jal, Mexico
Distribution: Slackware Linux
Posts: 211

Rep: Reputation: 31
I don't think there's any cache for the partition table itself, at least not at the OS level, since usually direct disk access is used to read and write to it... Maybe you can recreate it manually using the /dev/hd?? devices, if they aren't gone (i.e., you can tell that if you have a /dev/hda1 and /dev/hda5 that you have primary (1), extended (not shown) and logical (5) partitions and you might be able to query the kernel about the partition (device) size...), I'm just guessing.

If I understood your post correctly, then sfdisk is dumping the same partition table, even after it has been modified (which doesn't make any sense to me, tho').

If that's the case, can't you just use it to dump again the same partition table?

Anyway, why were you modifying the partition table of a machine with important work and data on it and (presumably) no backups?

Last edited by theoffset; 09-02-2006 at 07:28 PM.
 
Old 09-02-2006, 07:20 PM   #3
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Original Poster
Rep: Reputation: 45
Quote:
If I understood you're post correctly, then sfdisk is dumping the same partition table, even after it has been modified (which doesn't make any sense to me, tho').
Sorry, I didn't explain it very well. I would dump the partition table to a back up file. Then dump it again to another file, modify, rewrite, then restore from the unmodified backup when I was done testing.

Quote:
If that's the case, can't you just use it to dump again the same partition table?

Anyway, why were you modifying the partition table of a machine with important work and data on it and (presumably) no backups?
I don't have a backup onfortunatly. The testing I was referring to was done on my laptop with no important data whatsoever. To be honest, I have no idea why my partition got deleted on my development server. I can only assume that I did something stupid by accident without even realizing it. At no point did I intentionally try and modify the partition table on my server.

I guess I will just calculate the start/end sector and try my luck and restoring it manually.

Ironically, this was the whole purpose of the testing I did 3-4 weeks ago on my laptop. I wanted to see if I could restore the partition table manually after making modifications to it. I guess I'm not 100% confident in my calculations though.

Thanks for the help! I'll let you know how it turns out.
...drkstr
 
Old 09-02-2006, 07:46 PM   #4
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Original Poster
Rep: Reputation: 45
F'ing SWEET! It totally worked! Linux kicks so much arse.

I dumped the partition table to my first disk in a file to get a template, then 0'd everything out:
Code:
# partition table of /dev/hdb
unit: sectors

/dev/hdb1 : start=        0, size=        0, Id= 0
/dev/hdb2 : start=        0, size=        0, Id= 0
/dev/hdb3 : start=        0, size=        0, Id= 0
/dev/hdb4 : start=        0, size=        0, Id= 0
Then I did 'sfdisk -l /dev/hdb' to get my Cyllinders, Heads, and Sectors per track.
Code:
Disk /dev/hdb: 30515 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Since there was only 1 partition, start sector is 63 (for thr MBR), and size is (Cylinders*Heads*sect_per_track) - 63
Then in my file containing the partition table (ptable.dump)
Code:
# partition table of /dev/hdb
unit: sectors

/dev/hdb1 : start=       63, size=490223412, Id=83
/dev/hdb2 : start=        0, size=        0, Id= 0
/dev/hdb3 : start=        0, size=        0, Id= 0
/dev/hdb4 : start=        0, size=        0, Id= 0
Then all I had to do was
Code:
sfdisk /dev/hdb < ptable.dump
Mounted the partition, and there were my files. Didn't even have to reboot!

I'm going to create a partition table dump for each hard drive I have and save them to a floppy disk.

<whew> I'm quite relived.

Thanks for the moral support. I just needed a nudge to suck it up and just try it.

...drkstr
 
Old 09-02-2006, 07:54 PM   #5
theoffset
Member
 
Registered: Aug 2005
Location: Guadalajara, Jal, Mexico
Distribution: Slackware Linux
Posts: 211

Rep: Reputation: 31
WOW! Well done! I must say that I'm impressed.

Now there's an (and the only I know) argument to keep just one partition: It's easier to write the partition table manually that way
 
Old 09-02-2006, 08:12 PM   #6
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Original Poster
Rep: Reputation: 45
hehe, yeah I lucked out. I would have been boned if it was my system drive which has 8 partitions (including extended of course). This is why I'm going to back up my partition tables for the other disks, just in case.

I'm glad to know my partition utility will work as expected. ...well, assuming it doesn't delete random partitions when I'm not looking

take care,
...drkstr
 
Old 09-02-2006, 11:17 PM   #7
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
There's a nice utility to save your partitions in those situations: http://www.cgsecurity.org/wiki/TestDisk
It has been very usefull to me sometimes
 
Old 09-02-2006, 11:46 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Testdisk is excellent - and the site has some handy doco for recovery.
Also, next time have a look at /proc/partitions.

Partition table backups (use sfdisk) are a bit debateable. You have to remember to do it each time you fiddle with partitions.
In my case this is all the bloody time. For a while I thought of doing it in rc.local, but it was too much of a pain finding a floppy every boot.
I just rely on testdisk now.
 
Old 09-03-2006, 12:46 AM   #9
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Original Poster
Rep: Reputation: 45
Thanks for the tip, I'll check it out, it looks pretty advanced. Maybe I will get some ideas for my own utility.

regards,
...drkstr
 
Old 09-07-2006, 02:20 PM   #10
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 55
Quote:
Originally Posted by drkstr
hehe, yeah I lucked out. I would have been boned if it was my system drive which has 8 partitions (including extended of course). This is why I'm going to back up my partition tables for the other disks, just in case.

I'm glad to know my partition utility will work as expected. ...well, assuming it doesn't delete random partitions when I'm not looking

take care,
...drkstr
I always email myself before and after printouts of the partition table in cyls AND sectors (fdisk -l and fdisk -lu). I do the sector thing because *BSD thinks in sectors and if you have one of those and try to rebuild the partition table in cyls/megs/whatever you're gonna be toast.

Twice I've rebuilt the partition table by hand. Talk about sweating boo-lats And it works.

Last edited by Randux; 09-07-2006 at 02:21 PM.
 
Old 09-08-2006, 03:05 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
There's a simple program called gpart which may be useful to you. You might have a look at fixdisktable also.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to restore partition table without a CDROM? welson_sun Fedora - Installation 2 10-11-2005 03:30 PM
ext3 partition table restore pats Linux - General 1 07-22-2005 10:44 PM
Overwrote partition table. System still running. :) Ways to restore? sleeper.service Linux - Hardware 9 12-19-2004 01:06 PM
Why can't I restore a partition table backup containing a reiser partition? oldweasel Linux - Software 2 05-23-2004 12:11 AM
No partition table present on scsi drive How do I restore it? kosiadis Red Hat 1 10-17-2003 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration