Ubuntu Hard Drive Partition Re-Numbering

So with a vanilla Ubuntu installation, I used Gparted to shrink the 1st partition…

Afterwards I had a hard drive with a partition table that looked a bit like this:

  1. SDA1
  2. SDA3
  3. SDA2
  4.  - SDA5

This is very easy to fix and it is best done with an Ubuntu Live Disc.

The Recipe - for use at your own risk!

  1. Check the partition ordering: At a command prompt, run “sudo fdisk -l”. It should be out of numerical order.
  2. Get the partition UUIDs: At a command prompt, run “sudo blkid”. Note the UUIDs for all the partitions on the hard drive.
  3. Lets fix it: At a command prompt, run “sudo fdisk /dev/sda”
  4. At the fdisk prompt, type “p” and press return. Then fdisk should list your partitions and inform you that they are not in order.
  5. At the fdisk prompt, type “x”, then “f”, and finally “w”.
  6. At this point fdisk will write out the new partition information, but will likely complain about the OS still using a cached copy.
  7. Now, reboot the machine back into the Live Disc environment again.
  8. Checking all is well: At a command prompt, run “sudo fdisk -l”. It should now be in numerical order.
  9. Check the UUIDs: At a command prompt, run “sudo blkid”. The UUIDs should be the same. If not, you will probably need to fix the fstab - mount your boot partition and update the UUIDs in /etc/fstab.
  10. All done: Reboot again, back into your normal Ubuntu (not the Live Disc environment).