paint-brush
How to Install Windows on Disk With Linuxby@matejsmycka
New Story

How to Install Windows on Disk With Linux

by Matěj SmyčkaJanuary 8th, 2025
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Setting up a dual-boot system on a PC typically requires installing Windows first and then Linux.
featured image - How to Install Windows on Disk With Linux
Matěj Smyčka HackerNoon profile picture

Preface

Setting up a dual-boot system on a PC typically requires installing Windows first and then Linux. This sequence is recommended because Windows tends to overwrite the bootloader (like GRUB) during its installation, which can complicate a pre-existing Linux setup. However, I successfully reversed the process—installing Windows after Linux—by employing a series of workarounds. In this post, I’ll document the method, explaining the technical challenges and how I addressed them so others can replicate them.


To summarize the tutorial: You will Install Windows on top of the old Linux, Install the new linux, and clone data from the old linux to a new one.

Step 1 - Existing Linux

I assume you have installed Linux; otherwise, do not bother and install it in the usual order.

Use the following commands to identify your disk's EFI, swap, and root partitions, and write them somewhere.

lsblk -l sudo blkid

Step 2 - Install Windows

  1. Prepare Windows Installer onto USB; use Rufus if you have other Windows; otherwise, use Ventoy or WoeUSBng.
  2. Do not use BalenaEtcher; it is not designed to flash Windows on USB.
  3. Boot to Windows Installer
  4. Delete EFI and swap all other partitions, except for one partition with the root file system of the existing Linux.
  5. Resize existing OS and create new space for Windows
  6. Create a new partition for “Step 3” more than 20GB of space. At least the size of the original OS used space.
  7. Install Windows


Now, you cannot boot into the original Linux, but you should be able to boot into Windows.

Step 3 - New Linux 2

We will install a second linux to have a functional bootloader and restore data from the original OS.

  1. Flash USB with Linux image, use the same distro as the original OS.
  2. Install it on the partition from “Step 2”.
  3. Ensure the Linux bootloader is above the Windows boot manager in the BIOS/UEFI boot order.
  4. Now, the following commands will clone data from old Linux and move it to the new one.
sudo su
# if original disk encrypted, decrypt it.
cryptsetup luksOpen /dev/<ORIGINAL-OS-DISK> cryptdisk 

mount /dev/mapper/cryptdisk /mnt
#If disk is not encrypted, just mount it directly


for i in /opt /usr /home /.config /.local /bin /root ; do rsync -avz /mnt$i $i ;done


Well, this means the disk is not cloned; only data are.


This command is safe. You also can mount the whole “/” root system. However, you will encounter errors, which you will have to resolve.


To give an example: /etc/fstab cannot be copied because the partitions do not exist anymore.

Step 4 - Cleanup

  1. Boot into live USB linux
  2. Delete the original OS partition.
  3. Resize the Linux 2 partition, so it has more space.
  4. Boot into new linux
  5. Clean up with the following steps if any leftover stuff from the original OS is on the EFI partition.
  6. Regenerate initramfs file on Manjaro, use mkinitcpio
  7. Use update-grub command to regenerate GRUB config.
  8. Reboot

Conclusion

You have successfully installed Windows on the existing Linux and restored the original data.