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:
- 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.
- 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.
- Clone you existing Linux OS partition from the old hard drive to the new.
- Plug in your old drive (external SATA, external disk case, extra hard-drive bay, etc.) but leave it unmounted.
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.
- 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.
- 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.
- Mount your new Linux partition.
- 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.
- 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/
- 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.
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.
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.