Moving Linux on a windows drive for dual booting

README! There are many use cases for dual booting and guides for achieving it, this one concerns moving an existing Linux to a drive on which Windows is already installed and dual booting them. In other words, you will be combining existing Windows and Linux systems to coexist on the same hard drive.

I’ve been using the same hard drive for a while and transporting it from laptop to laptop whenever one would fail me (you can do that with linux). Now, after 8 years, I was fearing it was the actual hard drive that would break next so this time, I had to move my actual operating system to another physical disk.

Wanting to be able to dual boot into windows as well, I was stuck in a scenario for which there was not much help on the web. Here’s what I did:

  1. Resize your Windows partition using the disk management tool to make room for Linux and its swap. The new Linux partition must be larger that the one you are moving from.
  2. Reboot to a Linux live CD or GParted and create a bootable Linux and a swap partition (they must be primary) after the Windows partition.
  3. Clone you existing Linux OS partition from the old hard drive to the new.
    1. Plug in your old drive (external SATA, external disk case, extra hard-drive bay, etc.) but leave it unmounted.
    2. dd if=/dev/sdXY of=/dev/sdWZ bs=1M

      where XY is the drive letter and partition of the Linux OS you are moving from and WZ those of the partition you are moving to.

    3. Wait for a while, depending on the size of the partition, this could take a bit because you are cloning every single byte from one partition to the other. In my case, it tool a good solid two hours and half.
  4. Unmount and disconnect your old Linux OS hard drive. In case something goes wrong, simply popping it back in your computer will restore your setup just the way it was before.
  5. Mount your new Linux partition.
  6. From within the Live CD, restore the GRUB2 bootloader by executing
    grub2-install --root-directory /mountPoint /dev/sdW

    where mountPoint is where you new Linux partition is mounted and sdW is the drive where it resides.

  7. Since the partition’s GUIDs have changed you need to update the /etc/fstab file on your Linux with the new ones. Any file editor will do. Look up the new GUIDs for your new OS and swap partitions by running
    ls -al /dev/disk/by-uuid/
  8. Remove the live CD and restart the computer.  From within GRUB2’s boot menu, you should only see your Linux and not Windows, that’s normal. Boot your Linux OS.
  9. Run
    grub-mkconfig -o /boot/grub2/grub.cfg

    GRUB2 will scan your hard drive, find the Windows install and create a new boot configuration file. Now, when you reboot your machine, you will see Windows within the boot menu menu entries.

  10. Finally, since the size of the underlying partition holding your Linux installation has changed, the size of the file system has to be updated as well:
    resize2fs /dev/sdW

Done! Moving operating systems around and getting them to cohabit alongside each other is tricky and far from being straightforward so I hope this guide worked for you. You will most likely have to adapt it to your own situation and if you feel something you did could benefit others, please comment.

Leave a Reply

Your email address will not be published. Required fields are marked *