LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 01-05-2009, 12:03 PM   #1
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Rep: Reputation: 0
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.

Last edited by RichyAD; 01-05-2009 at 12:07 PM.
 
Old 01-05-2009, 12:46 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.)
 
Old 01-05-2009, 03:20 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,133

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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.
 
Old 01-05-2009, 06:00 PM   #4
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
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
sfdisk -d /dev/sda
And we can work from there if you want.
 
Old 01-06-2009, 06:36 AM   #5
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
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)

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
sfdisk -d /dev/sda:
Code:
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=104856255, size=  4192965, Id= b
/dev/sda2 : start=109049220, size=   417690, Id=83
/dev/sda3 : start=109466910, size=515670435, Id= 5
/dev/sda4 : start=620944380, size=  4192965, Id=82
/dev/sda5 : start=109467036, size=511461279, Id=83
 
Old 01-06-2009, 06:49 AM   #6
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
OK, how about copying/pasting the following into a text document:
Code:
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=       63, size=104856192, Id= 7
/dev/sda2 : start=104856255, size=  4192965, Id= b
/dev/sda3 : start=109049220, size=   417690, Id=83
/dev/sda4 : start=109466910, size=515670435, Id= 5
/dev/sda5 : start=109467036, size=511461279, Id=83
/dev/sda6 : start=620944380, size=  4192965, Id=82
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:
Code:
sfdisk --force /dev/sda < /home/<username>/Desktop/partition_table.txt
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:
Code:
fdisk -lu
sfdisk -d /dev/sda
And we can work from there.
 
Old 01-06-2009, 10:02 AM   #7
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,534

Rep: Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495
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.
 
Old 01-06-2009, 12:04 PM   #8
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
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
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:
Code:
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=       63, size=104856254, Id= 7
/dev/sda2 : start=104856255, size=  4192965, Id= b
/dev/sda3 : start=109049220, size=   417690, Id=83
/dev/sda4 : start=109466910, size=515670435, Id= 5
/dev/sda5 : start=109467036, size=511461279, Id=83
/dev/sda6 : start=620944380, size=  4192965, Id=82
That should work, right? Or will there be some problem with sfdisk not accepting this sector structure?

Thanks.

Last edited by RichyAD; 01-06-2009 at 12:06 PM.
 
Old 01-06-2009, 12:10 PM   #9
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
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
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.

Last edited by CJS; 01-06-2009 at 12:20 PM.
 
Old 01-06-2009, 12:15 PM   #10
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
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.
 
Old 01-06-2009, 12:18 PM   #11
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
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.

Last edited by CJS; 01-06-2009 at 12:21 PM.
 
Old 01-06-2009, 12:34 PM   #12
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
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.
 
Old 01-06-2009, 02:53 PM   #13
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
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.

Thanks.
 
Old 01-06-2009, 03:05 PM   #14
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
Quote:
Originally Posted by RichyAD View Post
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:
Code:
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=       63, size=104856192, Id= 7
/dev/sda2 : start=109049220, size=   417690, Id=83
/dev/sda3 : start=104856255, size=  4192965, Id= b
/dev/sda4 : start=109466910, size=515670435, Id= 5
/dev/sda5 : start=109467036, size=511461279, Id=83
/dev/sda6 : start=620944380, size=  4192965, Id=82
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.

Last edited by CJS; 01-06-2009 at 03:08 PM.
 
Old 01-07-2009, 05:21 PM   #15
RichyAD
LQ Newbie
 
Registered: Sep 2008
Location: Porto, Portugal
Distribution: Fedora 9-16, Linux Mint
Posts: 28

Original Poster
Rep: Reputation: 0
Thumbs up

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.
 
  


Reply

Tags
fdisk, partition, primary, sfdisk, windows, xp



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Partition 1 does not end on cylinder boundary wood_morris Linux - Newbie 6 08-28-2009 04:57 AM
need partition to end on cylinder boundary Master of Reality Linux - General 5 02-03-2006 09:51 PM
Partition Table (Cylinder boundaries) and lost space imitheos Linux - General 3 09-17-2005 02:59 PM
Partition does not end on cylinder boundary. snisheeth Linux - Hardware 0 01-24-2004 04:49 PM
Partition does not end on cylinder boundary snisheeth Linux - General 0 01-22-2004 07:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:56 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