Hello, Peter Kiem wrote: > Stupid me used MSDOS fdisk to delete a partition and it rewrote the > partition table without the Linux ones. > > Is there some tool that can scan the harddrive and find the partitions? The > data should be still there, just need to recreate the partition table. >
I did something like this a couple of years ago. I had no idea of what the size of the partitions was but I knew the parition names and the filesystems that were mounted on each one. Lets say your parition layout looked something like the following: /dev/hda1 on /boot type ext3 (rw) /dev/hda2 on /var type ext3 (rw) /dev/hda3 on /usr type ext3 (rw) /dev/hda5 on /home type ext3 (rw) /dev/hda7 on / type ext3 (rw) /dev/hda4 is a Windows extended parition which fills the rest of the disk. /dev/hda6 is the swap parition. # fdisk -l /dev/hda Disk /dev/hda: 255 heads, 63 sectors, 2434 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 3 24066 83 Linux /dev/hda2 4 1278 10241437+ 83 Linux /dev/hda3 1279 2338 8514450 83 Linux /dev/hda4 2339 2434 771120 f Win95 Ext'd (LBA) /dev/hda5 2339 2370 257008+ 83 Linux /dev/hda6 2371 2402 257008+ 82 Linux swap /dev/hda7 2403 2434 257008+ 83 Linux What I did was to create the hda1 so that it was larger than the actual file system on the disk. Then use dumpe2fs to find the actual size in blocks for the file system. # dumpe2fs /dev/hda1 | egrep '^Block count' Block count: 24066 Run fdisk and delete /dev/hda1 and recreate it using the correct block count and fsck it to make sure it is still fine. NOTE: Do not allow fsck to make any changes to the file system. You might inadvertently destroy the file system (or the next one) if the parition was created with the wrong size and fsck decides to 'fix' it. # e2fsck -n -f /dev/hda1 .........^^ This opens the file system in read-only mode and assumes no to all questions. If hda1 happends to be the root partition that contains the /etc/fstab file you can mount it read-only and have a look at what the partition layout should be. Next, start with hda2 followed by hda3. Create a parition of the appropriate type larger than the actual file system. Get the size of the file system using dumpe2fs. Delete the partition and re-create it using the correct block count. Upto this point all the partitions were primary partitions. The next step is to create the extended partition on /dev/hda4 which spans the whole drive. The rest of the partitions are all logical (created within the extended partition). Create a logical partition, /dev/hda5, larger than the underlying file system and use dumpe2fs to determine the file system size. Delete the hda5 partition and re-create it using the correct block count. For the swap parition, /dev/hda7, I create the paritions by specifying the sizes using a format like 256M, 128M or 64M etc. I just re-create it using the same size with the correct type. If you're not sure of the size and you have already recovered the parition that contains the /var file system, /dev/hda2 in this case. Mount /dev/hda2 read-only and look for the swap size in /var/log/dmesg or /var/log/messages. # egrep 'Adding Swap' dmesg Adding Swap: 257000k swap-space (priority -1) On this machine I used '256M' in fdisk when I specified the size of the swap parition. All that remains is hda7, and since its the last parition on the disk it is simply recreated using all available space. Use dumpe2fs to make sure that you have the correct size. If the block count reported by dumpe2fs is different, delete the parition and recreate it with the correct size. If the swap parition was created with the wrong size dumpe2fs will probably fail and you'll have to delete both the swap and current partition and try again with different sizes. This worked for me it might not work for you. I'm doing this from memory so it probably contains a lot of inaccuracies and since your setup will more than likely be different this only gives you some idea on how you can recover the partitions. You'l probably need a good recovery floppy or cd-rom with the correct tools on them. A search for 'recover parition' on freshmeat.net returned some usefull links as well. Best Regards Willem Brown -- iServe (Pty) Ltd. http://www.iserve.co.za/ Tel: +27 (0)11 258-7800 Fax: +27 (0)11 258-7888 Cell: +27 (0)83 271-0839 -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list