How do I recreate a primary partition starting at cylinder 1?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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:
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)
Disk /dev/sda: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x0001ed87
Device Boot Start End Blocks Id System
/dev/sda1 104856255 109049219 2096482+ b W95 FAT32
/dev/sda2 109049220 109466909 208845 83 Linux
/dev/sda3 109466910 625137344 257835217+ 5 Extended
/dev/sda4 620944380 625137344 2096482+ 82 Linux swap / Solaris
/dev/sda5 109467036 620928314 255730639+ 83 Linux
And save that text document as "partition_table.txt" on your desktop. When you copy the above text, make sure there are no spaces at the end of any of the lines. Then run the following command as root:
That will produce a lot of output including some warnings, so you don't need to be alarmed, but please post the output of the above command. Next reboot, and then post again the output of:
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.
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
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x0001ed87
Device Boot Start End Blocks Id System
/dev/sda1 104856255 109049219 2096482+ b W95 FAT32
/dev/sda2 109049220 109466909 208845 83 Linux
/dev/sda3 109466910 625137344 257835217+ 5 Extended
/dev/sda4 * 63 104856254 52428096 7 HPFS/NTFS
/dev/sda5 109467036 620928314 255730639+ 83 Linux
As said, I haven't saved the partition table yet. I would prefer CJS's option, because it also restores the original device order (saving me from also having to change fstab, etc.). So I was planning to use a modified version of CJS's sfdisk instructions:
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:
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
Therefore the stop sector of your sda1 partition is 104856316 according to the table you posted, yet your sda2 partition should start at 104856255, which is before that value. Thus I would recommend going with the partition table I gave in my last post, but it's up to you.
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!
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
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x0001ed87
Device Boot Start End Blocks Id System
/dev/sda1 63 104856254 52428096 7 HPFS/NTFS
/dev/sda2 104856255 109049219 2096482+ b W95 FAT32
/dev/sda3 109049220 109466909 208845 83 Linux
/dev/sda4 109466910 625137344 257835217+ 5 Extended
/dev/sda5 109467036 620928314 255730639+ 83 Linux
/dev/sda6 620944380 625137344 2096482+ 82 Linux swap / Solaris
I've only checked to see if I could mount the linux partition and that went OK. Tomorrow I'll try the Windows install, put Grub back in the MBR, and hopefully be finished before lunch time.
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.
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.
You said in post #8 that using the partition table I gave would restore the original device order, so I thought that's what you wanted. You can assign device numbers using that sfdisk method, you just have to rearrange the output of the sfdisk -d accordingly. For instance, if you want the FAT32 partition to be sda3 and then make the current sda3 linux partition sda2, you could use the following table:
You just have to be careful to actually swap the lines like shown above and not simply change the device numbers from sda3 to sda2 and vice versa in the sfdisk partition table. So swapping primary partitions around is not a big deal, but it is not a good idea to swap the logical partitions around, because the logical partitions should be in the physical order on the drive in order to avoid problems in some cases. But if you prefer to delete and recreate partitions with gparted/fdisk, that could work just fine too.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.