Saturday, July 19, 2014

Reordering Hard Disk Partition Numbers With Linux

Hard drive partitions are numbered by their order of creation. So if we create a new partition in between two existing partitions, it will get the next highest number. But we often want it be ordered based on their logical physical order, rather than ordered by their order of creation.

We can easily reorder the partition numbers based on their logical order, by using your favorite linux distros (eg. Ubuntu Live CD) or can use Parted Magic, which is no longer free now. But you can download the final free version of Parted Magic from here (Another link here).

Note: If you’ve a similar environment setup as described below, you can directly follow the setup. But if you’ve a dissimilar  setup, you may need to do some additional actions based on your environment.

1. Details about existing environment

Ok. Below is a live example on how to do this. We’ve a dual boot system (Uses GRUB), with Lubuntu14.04 and Windows XP. Below is my existing hard disk partition details.

image

We’ve “Lubuntu14.04” installed in “Sda5” and Windows XP installed in “Sda1”. “Sda6” is another NTFS partition to store common data.

Now we would like to install FatDog64-631 (another Linux OS) as a Full Install (How? here its discussed in detail). So we need a new partition for this. For this we’ve opted to shrink “sda5” (Lubuntu installed partition), and create a new partition out of it. Shrinking existing partition is easy using Gparted. Simply select the partition and opt resize option. Now you can drag the partition boundaries. After the resize, we’ve the below setup now. We can see a new unallocated space between “Sda5” and “Sda6”.

image

From GParted itself, we’ve created a new partition out of the unallocated space and formatted it to ext4. Finally applied the changes using “Apply” button. So the current configuration is the below.

image

Now the new partition got a number “Sda7”. Now the partition numbers are out of order (Sda5->Sda7->Sda6). Now we would like to make it in the order of their positions.

2. Reordering HDD Partition Numbers using “fdisk

Now open a command prompt and type in the below command.

“fdisk /dev/sda”

This will let you to command mode, now press letters x,f,w one after another, with Enter Key after each letters.

image

Once you done this, you can verify the partitions are ordered correctly.

image

Now the partitions are properly ordered. (Sda5->Sda6->Sda7)

Now if your system does not boot, you’ve to fix your GRUB.

3. Fixing Boot Issue with GRUB

Boot to your “Lubuntu or Ubuntu” Live CD and open a terminal. Type in the following command one by one. Replace “Sda5”, with your setup.

Note (NB): This step, assumes you’ve GRUB installed on your linux partition. In our case it is “sda5”. If you’ve installed GRUB in a dedicated partition or your are relying on your windows to load the boot loader (No GRUB at all!), you may better not to follow the below but rather look into the official documentation here.

sudo mount /dev/sda5 /mnt

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /usr /mnt/usr

sudo chroot /mnt

update-grub

grub-install /dev/sda

grub-install --recheck /dev/sda

sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt/usr

sudo umount /mnt

Now reboot. Your GRUB should appear.

image

Reference post here.

No comments:

Post a Comment