How to Recover a Dual-Boot System after a Windows Update

How to Recover a Dual-Boot System after a Windows Update

Introduction

Ah, the age-old dual-boot dilemma: install Windows after your Linux distro, and you’re practically inviting trouble. “No problem,” you say, “I’ll just install Windows first!” Easy, right? Well, not really it turns out. Even if you follow the rules and everything’s running smoothly, one day your system might just decide to... well... not be a system lol. Welcome to the Battle of the Boot Loaders, where even the most intricately built system is at the mercy of the all mighty Windows Boot Loader!

I have been running a Dual-Boot System on one of PCs for about 7 years now, and everything had be working perfectly fine... until recently, when Windows decided to update. The problem? well sometimes windows will resize the boot partition. In my case, Windows resized the /boot/efi partion from 1GB to 500MB, and in doing so, changed the UUID, and this caused my Linux Installation (Gentoo) to become unbootable.

In more technical terms, Windows will auto detect and reformat your /boot drive, this will change the UUIDs and probably also delete any kernel and inframfs images.

To fix this:

This guide will run through how to fix this from a fresh install of Windows (it was easier to do that in my case), but you could also use it to recover the update fuckery.

Reinstall windows and use the partition that you aren't using for Linux, or delete the old Windows partition and build up the new disk. DONT DELETE THE ESP partition, you're FUCKED if you do this.

My example is recovering a Gentoo install

Recover Dual Boot

Step 1: Boot off a live USB,

i would recommend either an ARCH live or the same OS

Step 2: ID the relevant partitions to reinstall GRUB
fdisk -l

ID the ESP and rootfs from the output, eg the /boot is /dev/sda1 and root is /dev/sda4

Step 3: Mount the partitions

you can mount them anywhere, but the convention is to mount in /mnt lets mount a gentoo install in /mnt/gentoo in this example

you want to mount / before /boot because they use the same mount point

mkdir -p /mnt/gentoo/boot
mount /dev/sda4 /mnt/gentoo #the rootfs
mount /dev/sda1 /mnt/gentoo/boot #/boot

you want to mount / before /boot because they use the same mount point

Step 4: Mount the binds
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys 
mount --rbind proc /mnt/gentoo/proc
cp --dereference /etc/resolv.conf etc/resolv.conf #for DNS
Step 5: Change Root
choot /mnt/gentoo
export PS1="(chroot) $PS1" #unique prompt
ls /boot

the output of ls /boot will vary depending on your distro, if you installed Gentoo, then you should see vm-linuz and inframfs images in /boot. If you dont see those, Windows got you and you'll have to get them back.

If those files arent there, you can restore them in 1 of 2 ways

Option A: manually reproduce the vmlinuz image to /boot and remake the imframfs image

Step 1: Reproduce the kernal image
eselect kernel list
eselect kernel set 2
ln -sf /usr/src/linux-3.4.9-gentoo /usr/src/linux  ##Dont do this step, just make sure that symlink exists 
make menuconfig #this compies the kernal to /boot
Step 2: Reproduce the infraamfs image
emerge --ask sys-kernel/dracut
dracut --kver=6.1.38-gentoo-_x86-64 ## tailor to your own kernal
Step 3: Reinstall Grub
grub-install --target=x86_64-efi --efi-directory=/boot
Step 4: Reconfigure Grub
cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak
grub-mkconfig -o /boot/grub/grub.cfg

Option B: use genkernal or Distro equivelent

Step 1: Genkernel
genkernel all
# this will recomplie the kernal and inframfs images and put them in /boot
Step 2: Reinstall Grub
grub-install --target=x86_64-efi --efi-directory=/boot
Step 3: Reconfigure Grub
cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak
grub-mkconfig -o /boot/grub/grub.cfg

Assuming you already have OS-Prober installed and configured, the vmlinuz and inframfs images and Windows Boot Manager ready, you should be good to boot back into your Linux partion.

CAVEAT: recheck /etc/fstab and see if the the UUID for any of the devices has changed.

windows.png

turns out that Windows might change your UUIDs and if you dont change this then, your kernel will panic.

kernal-panic.png