How do I recreate a primary partition starting at cylinder 1?
History:
I recently had to replaced the motherboard of my dual-boot system. I'm running Fedora 9 (x86_64) and Windows XP 64bit on a single 320 GB Serial ATA3 disk. After the replacement, I got Fedora running without much difficulty. Of course Windows was another matter. Today I decided to try and see if I could get Windows up and running again. The plan was to reinstall Windows, replace Grub in the MBR and be finished before lunch time ... My partition table (3 x primary; 1 x extended): /dev/sda1 * 1 6527 52428096 7 HPFS/NTFS (Windows XP 64bit) /dev/sda3 6528 6788 2096482+ b W95 FAT32 (shared space) /dev/sda2 6789 6814 208845 83 Linux (mounted on /boot) /dev/sda4 6815 38913 257835217+ 5 Extended /dev/sda6 6815 38651 255730639+ 83 Linux (mounted on /) /dev/sda5 38653 38913 2096482+ 82 Linux swap / Solaris Mistake: During the Windows installation, I thought that it might be a good idea to remove primary partition with the previous Windows installation, put it back (forcing windows to format), and start afresh ... Big mistake! After removing the partition, the Windows installer complained that it could not create a partition because the maximum number of partitions was reached. So I popped in my Fedora 9 DVD, booted in rescue mode, and started fdisk to recreate the partition. It showed the following partition table: /dev/sda1 6528 6788 2096482+ b W95 FAT32 (shared space) /dev/sda2 6789 6814 208845 83 Linux (mounted on /boot) /dev/sda3 6815 38913 257835217+ 5 Extended /dev/sda4 38653 38913 2096482+ 82 Linux swap / Solaris /dev/sda5 6815 38651 255730639+ 83 Linux (mounted on /) But fdisk will not allow me to recreate the original Windows partition (cylinders 1-6527) either! It only provides access to the extended partition. I had a look around, but I can't seem to find any useful threads or links. I did read somewhere that (apparently) the order of deleting partitions is: logical, extended, primary. But that does not help me much anymore ... So my questions are: - Why can't I get access to the cylinders 1-6527? Is this possible in "expert" (x) mode of fdisk? (I did not dare try this for the moment) - How do I get my original partitioning back without destroying the data my linux partitions? Can I remove the entire table and rebuild it up from scratch? Any help will be appreciated. |
I did not know that fdisk would not do this.....you might try GParted. This comes with many "live CD" Linux distros, and is also available on a standalone bootable CD. It IS possible to do what you are asking.
(I don't currently have a system where I can do a test with fdisk.) |
Nothing to do with fdisk - blame the crappy M$oft installer.
It appears to have converted one of the logicals (the swap partition) to a primary. What a lame piece of junk. Your orphaned space is now unreachable as you now have 4 primaries, and Windoze will only install into a primary partition. What a lame piece of junk. I have seen other threads with this sort of partition layout, and wondered how it happened - maybe now we know. You're lucky it's the swap - from the Linux liveCD delete it, run the 'doze install, re-add the swap (as a logical), and fix up fstab in need. |
RichyAD, as syg00 all ready pointed out, your sda5 swap logical partition was somehow converted into the sda4 primary partition; yet the sda4 swap partition is still inside of your sda3 extended partition, so basically your partition table is corrupt at this point. I've helped a number of people easily correct partition table problems like that using a trick with "sfdisk", so if you want, I can help you fix your partition table if you can first post the output of:
Code:
fdisk -lu |
Thanks for the replies, guys.
A primary partition INSIDE an extended partition? OK ... I didn't know a partition table could get screwed up so much. I'd have to agree with syg00: what a lame piece of junk! Anyway, let's see if I can clean up this mess (with your help). fdisk -lu /dev/sda: Code:
omitting empty partition (5) Code:
# partition table of /dev/sda |
OK, how about copying/pasting the following into a text document:
Code:
# partition table of /dev/sda Code:
sfdisk --force /dev/sda < /home/<username>/Desktop/partition_table.txt Code:
fdisk -lu |
The sda4 swap partition is not in the extended it is a primary partition so as syg00 suggested, delete the swap. You will then be able to create a primary partition. In Linux, logical partitions start with 5. If you create an extended partition as the first partition on your drive, then create a logical partition, it will be sda5 not sda2.
I don't know if you will be able to access cylinders 1-6527 but it seems deleting sda4 and trying would be the simplest. |
CJS, are you sure that's OK?
I wanted to have a look at the option from syg00 and yancek (without saving the new table!). So using fdisk I removed the swap partition. This indeed allowed me to create a new primary partition and gave me access to cylinder 1. However the windows partition would then run from sector 63 to 104856254 (and not 104856192) as indicated here: Code:
Disk /dev/sda: 320.0 GB, 320072933376 bytes Code:
# partition table of /dev/sda Thanks. |
I've double-checked the partition table that I gave in my post, so to the best of my knowledge, yes I think that it is OK to use those instructions I gave. As I mentioned I've helped others correct their partition table problems with the same method, so I think you should be fine. Please see these threads if you would like some examples:
http://ubuntuforums.org/showthread.php?t=1032234 http://ubuntuforums.org/showthread.php?t=1031659 http://ubuntuforums.org/showthread.php?t=1008458 http://ubuntuforums.org/showthread.php?t=1027533 But it's of course up to you, I can understand your reluctance to trust someone you don't know. Please do whatever you feel is best. :) EDIT: The partition table you show above I think has some problems; the size of sda1 will make sda1 extend into sda2, because: Code:
size = stop sector - start sector + 1 |
CJS, just out of curiosity: how did you come up with sector 104856192 instead of 104856254. I mean, 104856254 seems to make more sense since the next partition starts at 104856255 ...
Anyway, thanks for the advice. I'll let you know if it works. |
Please see my edit in the last post; I think the size value you are using for sda1 is not going to work. Please don't confuse the "size" number with the stop sector of the partition. :)
|
Oops, my bad ... I didn't realise that the format of sfdisk was different. I thought it also indicated start and STOP (instead of SIZE). I'm probably not completely sober yet after the holidays! :)
Thanks, CJS, you saved me from a lot of misery. |
I used the instructions as given by CJS and (so far) all went smoothly. The new partition table is now:
Code:
Disk /dev/sda: 320.0 GB, 320072933376 bytes One note though: I was a bit disappointed to see that even with this method I could not assign device numbers (e.g. W95 FAT32 as /dev/sda3); this was simply ignored by sfdisk. No matter, I'll edit fstab to correct for the new structure. But, in this case, the suggestion by syg00 and yancek of deleting the (primary) swap partition would have been the simpler solution. Thanks. |
Quote:
Code:
# partition table of /dev/sda |
Sorry for the confusion, CJS. I only noticed the device order later in the thread. What I meant was the "original" order as mentioned at the start of post #1.
I did indeed try to change the device order by simply changing the device numbers in the sfdisk input file. That explains why it didn't work ... Another case of RTFM. Well, live and learn! Anyway, I changed the order and now everything was back to original. And I got some extra practice because (would you believe it!) the Windows installer did it again! After I put everything back, I started installing Windows. And this time I did NOT remove the partition but simply told it to (quickly) format the partition. After it had finished I checked the partition table and my Linux swap partition had been deleted! Unbelievable! I guess it updated the partition table (incorrectly) when it installed the Windows bootloader or something. I've now put back the table again, reinstalled Grub and everything is working properly. So for me, this is finally SOLVED. Thanks for all the help. |
All times are GMT -5. The time now is 02:57 PM. |