Preparing a dual boot system is quite easy when we install ubuntu after windows OS, but it became challenging when installing windows after Ubuntu OS.
For this below are some steps you need to follow:
1. Boot your machine with ubuntu live CD or USB.
2. Open gparted application from console
3. Resize the existing drive from where you can opt free space for windows installation. Make sure you leave enough space for ubuntu OS also.
4. After alteration hit apply button and exit the gparted application
5. Now reboot the system with windows live CD this time.
6. During windows installation choose the empty volume created using gparted app.
Now windows boot loader file will override the grub so ubuntu will not boot this time, so you need to reinstall grub boot loader.
To recover ubuntu you have to you use live CD (or live USB) and follow these steps:-
Get the drive info using below command
lsblk
now,
sudo mount /dev/sda1 /mnt sudo mount --bind /dev /mnt/dev && sudo mount --bind /dev/pts /mnt/dev/pts && sudo mount --bind /proc /mnt/proc && sudo mount --bind /sys /mnt/sys sudo chroot /mnt grub-install /dev/sda grub-install --recheck /dev/sda Update-grub exit && sudo umount /mnt/sys && sudo umount /mnt/proc && sudo umount /mnt/dev/pts && sudo umount /mnt/dev && sudo umount /mnt exit
Reboot the system, and now you can choose OS from Grub loader
Type sudo fdisk -l in the terminal and enter your password if asked.
Find the installed Ubuntu partitions, and run the below mentioned commands in terminal.
sudo mount /dev/sde3 /mnt sudo mount /dev/sde3 /mnt/boot ls /mnt ls /boot for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done sudo chroot /mnt #change the root sudo update-grub # now update grub sudo for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done sudo chroot /mnt sudo update-grub sudo grub-install /dev/sde3 sudo for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done sudo umount /mnt/boot sudo umount /mnt sudo reboot
To recover grub:
Open the live version.
Open the terminal and run sudo fdisk -l to see where Linux is installed.
Run sudo mount /dev/sdaX /mnt where x is the letter for said drive.
Run sudo grub-install –root-directory=/mnt /dev/sda to install grub.
Run sudo update-grub to update grub and if this command didn’t work run it after rebooting.
Reboot.
Other option to recover the boot loader is the tools mentioned below.
Boot-Repair is a simple tool to repair frequent boot issues you may encounter in Ubuntu like when you can’t boot Ubuntu after installing Windows or another Linux distribution, or when you can’t boot Windows after installing Ubuntu, or when GRUB is not displayed anymore, some upgrade breaks GRUB, etc.
Remark: this can also be performed from a live-CD or live-USB.
Either add ‘ppa:yannubuntu/boot-repair’ to your Software Sources via the Software Centre or, for speeds-sake, add it using a new terminal session:
sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update sudo apt-get install -y boot-repair && boot-repair
Thanks. A good concise guide. Advance users can easily grasp and install windows alongside Ubuntu using the instructions in this article.
Beginners or naive user’s can refer a detailed article at https://www.techsolveprac.com/install-windows-after-ubuntu-dual/