After installing and removing various Linux versions, adding, deleting and moving partitions the numbering is all over the place and and I want to get it back in order again. The drive is now partitioned like this:
|-SDA4 Windows-|-unallocated space-|-SDA3-Data-|
And I want it to look like this:
|-SDA1 Windows-|-unallocated space-|-SDA2-Data-|
There are ways of convincing Linux to swap the partition numbers after booting but they may not be suitable for various reasons and some of us just want things neat and tidy. This method will delete the partition table and then recreate it with the correct numbers. It is very likely the drive will not be bootable after the procedure but that's reasonably easy to fix later. No changes will be made to the disk until we write them in the last step. If you make a mistake at any time up until that point you can simply quit and start again.
WARNING: Although the procedure is reasonably safe we are about to delete the partition table. If you make a mistake here it is easy to lose all your data. Make a backup first!
Make a backup or all your data.
Unplug any other drives so you can't accidentally mess them up.
Open the terminal, start fdisk and tell it the drive you want to work with. You may get a warning like I did but it's doesn't seem to be a problem.
Code: Select all
# fdisk /dev/sda
The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Print out the partition table, change to sectors as the unit and print it again. You should use sectors as unit, it's the actually written place on the disk.
Code: Select all
Command (m for help): p
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda4 * 1 4088 32833536 7 HPFS/NTFS
/dev/sda3 4088 30401 211361472+ 7 HPFS/NTFS
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda4 * 2048 65669119 32833536 7 HPFS/NTFS
/dev/sda3 65669120 488392064 211361472+ 7 HPFS/NTFS
We have all the information we need. Delete all partitions using the "d" command (Partition number 1 = SDA1, partition 2 = SDA2, etc)
Code: Select all
Command (m for help): d
Partition number (1-4): 4
Command (m for help): d
Selected partition 3
Command (m for help): d
No partition is defined yet!
It's time to recreate the partition table with the correct partition numbers. Start with the first partition. I'm going to make it a primary partition and call it SDA1
Copy the starting and ending sectors from the second print out we did above.
Code: Select all
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-488397167, default 63): 2048
Last sector or +size or +sizeM or +sizeK (1234-488397167, default 488397167): 65669119
Code: Select all
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (63-488397167, default 63): 65669120
Last sector or +size or +sizeM or +sizeK (7890-488397167, default 488397167): 488392064
Code: Select all
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 7
Changed system type of partition 3 to 7 (HPFS/NTFS)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 7
Changed system type of partition 3 to 7 (HPFS/NTFS)
Code: Select all
Command (m for help): w
Use Gparted or any other program to check the partition numbers are correct. You may find your OS will no longer boot. I had no problem with Vista but you may need to fix the MBR with bootrec.exe /fixmbr and bootrec /fixboot. Google for more instructions. If you are using Linux you may need to update the boot manager to point at the right partition. Again Google it because I don't know how.