I decided to remove Windows. It was at the beginning of my hard drive, so I deleted the first partition, then I extended the second partition down to the beginning of the hard drive. I assumed that doing this operation (the second partition becomming the first, and it being moved the beginning of the drive) that it would inherit the base partition number (i.e. the kernel device name of sda1). However I’ve learned that disk utilites are generally uninterested in doing this, and instead preserve partition numbers. I believe the likely reason for this is because the designers know that some configurations define partitions (
fstab and bootloader configs, for example) and are thence hesitant to alter a bootable configuration. I, however, like order. And thankfully, the order can be re-based.
The easy way
First thing to do is add a partition, afterward the partition table can be re-based.
Adding a partition
Disk utilities generally follow the pattern that when they create a partition they begin with the first available number; hence, a new partition should be named
sda1. Here’s what my partitions looked like originally:
Since it’s quicker to create a partition at the end of the drive… add a partition to the end… and get
Fixing the partition order
The only disk utilites I know that have this available operation are
gdisk. They have an option to re-order partition numbers (i.e. the first partition is one…). Boot from a install CD or rescue disk and run
# fdisk /dev/sda ... Command (m for help): p # prints partition table ... Device Boot Start End Sectors Size Id Type /dev/sda1 625133568 625141759 8192 4M 83 Linux /dev/sda2 * 2048 608364543 608362496 290.1G 83 Linux /dev/sda3 608364544 625133567 16769024 8G 82 Linux swap / Solaris Partition table entries are not in disk order.
sda1 Starts and Ends after the other partitions. From here enter the expert menu:
Command (m for help): x
And fix the partition order:
Expert command (m for help): f Done. Expert command (m for help): r Command (m for help): p ... Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 608364543 608362496 290.1G 83 Linux /dev/sda2 608364544 625133567 16769024 8G 82 Linux swap / Solaris /dev/sda3 625133568 625141759 8192 4M 83 Linux
The easy but hold-on-tight way
I’ve heard of someone doing this but haven’t tried it myself. What is done is that the partition table values is written down, the partition table wiped, then the partition table values are re-entered. Since you’re creating a new partition table from scratch the correct partition order will be created. This actually is perfectly safe to do.. if the values are gotten right. The partition table is written on the first sectors of the disk so the partition contents are perfectly safe. I’ve known this to be done before; however, I have not tried it so please use at your own risk. To learn more about this read: Fix MSDOS partition manually.
Configurations with partition definitions
Afterward, be sure to adjust the partition definitions in any configurations that have them. Also some bootloaders may store this value in the header region of the drive requiring a re-install of the bootloader.