Hallo.
I've just overwritten my partition table of my system's hard disk. i made a cfdisk
on the wrong device (/dev/sda
instead of /dev/sdd
), deleted all partitions, made one new primary spanning over the whole device, set its type to 07
(NTFS) and hit write
.
So here i am with my system running. Until i reboot, i hope/guess nothing will change - meaning: all my data is accessible (I'm currently making a dd
-backup of the whole device and plan to make a .tar.gz
-backup of the most important data later). I also backed up /proc/partitions
, /proc/diskstats
(even though i guess this is more about throughput and stuff like this ...) and /sys/block/sda/sda?/{start,size}
.
Some further things i know:
- 4 primary partitions
- 1st partition: ~100Mb, ext3, /boot
- 2nd partition: ~100Mb, "Win7 Boot Partition", ntfs(?)
- 3rd partition: ~20...30GB, Win7, ntfs
- 4th partition: ~20...30GB, luks-encrypted device
- The luks- de crypted device is a LVM-PV
- The
/
,/home
&swap
-partitions are all LVs on the (VG on the) above noted PV
So my questions:
- What is the simplest way to just write the kernels partition table to the disk?
- What is the simplest way to take the above mentioned (and perhaps other I don't know of ...) data and generate the partition table?
- Are there any problems to take care of regarding to luks and/or lvm?
- Is there any data I should backup before rebooting (meanig stuff from kernel [ /sys/..., /proc/...] and so on, which could help me regenerate the partition table)?
Thanks a lot!
P.S.: debian sid, Kernel 2.6.34-1-amd64 from debian-experimental, 80GB Intel SSD
-
If the partition table is damaged, I'd suggest using a boot disk of RIP (rescue is possible Linux) to run testdisk. Heck, you might be able to run testdisk from your running system to have it scan and recover partitions, but I'd not try that because I don't know what it would do to a running system with open files.
If you want to try a backup of essential data (you don't already have it?) now would be a good time to do so...
m.sr : I have backups of (most of) the data of my system, and my system is up and running and all data is accessible (as far as i can see). I just don't want to make a fresh installation of my whole system(s), because: - The data is here, only the partition table is gone - I don't want to setup this "complicate" (luks, lvm, ...) system again ;) - This is an interesting task ;) - even if setting up debian again would be fast, setting up win7 again is pain (because of "unusual stuff" like drivers for accessing luks-partitions, ext2-Partitions in luks, ...)m.sr : Just testing testdisk on the still-running-system. Looks promising - Thanks a lot for that hint. I'm just not really knowing which data this program will restore / rewrite and how .... but I will RTFM ...Bart Silverstrim : Testdisk is a diamond in the rough, interface-wise. It can restore your partition, or it can scan for and recover individual files (a function in the advanced tools, I believe, working from memory...). It's not really a generally recovery tool as much as it'll scan for and repair partitions, just as you described having problems :-) It'll extrapolate and repair partitions for me when we're trying to duplicate disks and have trouble with clones with NTFS drives.From Bart Silverstrim -
Not too tricky. Hopefully.
First of all, note the size and order of all your partitions on /dev/sda:
challenger:/home/michael # grep . /sys/block/sda/sda*/{start,size} /sys/block/sda/sda1/start:63 /sys/block/sda/sda2/start:228690000 /sys/block/sda/sda3/start:257040 /sys/block/sda/sda1/size:256977 /sys/block/sda/sda2/size:83885760 /sys/block/sda/sda3/size:228432960
Run fdisk on /dev/sda and change the units to sectors:
Command (m for help): u Changing display/entry units to sectors
Then start making partitions. Use the appropriate numbers
start
andsize
for each partition.
Avoid an off-by-one error - subtract one fromsize
before typing it into fdisk.Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First sector (63-312581807, default 63): Using default value 63 Last sector, +sectors or +size{K,M,G} (63-312581807, default 312581807): +256976 Command (m for help): p 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 Disk identifier: 0x02b002af Device Boot Start End Blocks Id System /dev/sda1 63 257039 128488+ 83 Linux
Don't forget to set your partition IDs and toggle the boot flag on the right partition
Now re-install your MBR and you should be ready to go.
Naturally you can do all this using your favorite partition editor... parted works just fine as well.
If you've lost the information regarding start/end of partitions - parted has 'rescue' options to search the disk for lost partitions. But you shouldn't need those.
m.sr : Just waiting until my dd-backup is finished. I will try your fdisk-restore-advice - which looks promising and is one of the first i kind of thought of. But some questions are missing: 1.) I guess things like lvm/luks will work without further attention, won't they? 2.) Is there a reason why i should rewrite the MBR - i didn't change it if fdisk doesn't change it.MikeyB : 1) LVM should work with further attention - you can run pvscan after you fix the partition table to verify. 2) Actually, right, no need to redo the MBR if you haven't clobbered it or moved files in /boot.m.sr : just for your information: I did it exactly as your outlined it in your answer. Everything worked as expected, system with repaired partition table up and running. No Problems with lvm, luks or win7. MBR was untouched the whole time so didn't need to be regenerated (which would have been an easy grub-install). Thanks a lot!From MikeyB
0 comments:
Post a Comment