Restoring dual boot of Windows 10 and Linux when Windows rewrites the Bootloader

Windows will try hard to remain the one and only operating system on your laptop. After a major update of Windows 10 my Ubuntu was no longer accessible as the Windows update process replaced the Grub bootloader with the Windows bootloader, booting only Windows.

The following sequence of command line parameters will restore Grub. These commands are valid if your are using BTRFS for your root partition, booting using EFI and using and NVMe drive.

First get a USB pen drive, download any recent Linux distribution, write it onto the USB pen drive and boot into the live system.

Afterwards you have to determine which is the drive Linux is installed on and your Linux root partition:

`fdisk -l`

which outputs on my system

Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F687432F-DB86-4B88-8CB2-DBB55255216B

Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 534527 532480 260M EFI System
/dev/nvme0n1p2 534528 567295 32768 16M Microsoft reserved
/dev/nvme0n1p3 567296 198828031 198260736 94,6G Microsoft basic data
/dev/nvme0n1p4 445640704 498069503 52428800 25G Microsoft basic data
/dev/nvme0n1p5 498069504 500117503 2048000 1000M Windows recovery environment
/dev/nvme0n1p6 198828032 426108927 227280896 108,4G Linux filesystem
/dev/nvme0n1p7 426108928 445640703 19531776 9,3G Linux swap

From this output the Linux root drive is /dev/nvme0n1p6 and the EFI partition is /dev/nvme0n1p1. Your output may vary.

Mount the existing root partition:

sudo mount -t btrfs -o subvol=@ /dev/nvme0n1p1 /mnt 

Mount all other linux system folders :

for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done

Mount your EFI directory using the following command:

sudo mount /dev/nvme0n1p1 /mnt/boot/efi

chroot into your install

sudo chroot /mnt

Now that you are logged in your installation (not the Ubuntu Live) just do

grub-install /dev/nvme0n1
update-grub

Replace `nvme0n1` with your main drive. After booting Grub should greet you again with Linux and Windows as options to boot.

 

Information derived from https://askubuntu.com/questions/655011/windows-10-upgrade-kills-grub-and-boot-repair-doesnt-help and https://askubuntu.com/questions/851862/can-not-reinstall-grub-after-windows-install-btrfs-subvolumes

Advertisements

Use SSH to connect to Docker Machine created instance

When one of my docker machine created virtual machines got changed by my cloud provider I was left in the dark. Out of a sudden docker-machine ssh no longer worked which comes at no surprise as the initially assigned IP address to me got changed.

In such a situation the SSH command line client has a way to specify the certificate to use when connecting to the VM:

ssh -i /home/john/.docker/machine/machines/T2fiware-postgres/id_rsa ubuntu@130.206.115.143

Replace `T2fiware-postgres` with the name of your docker created machine, ubuntu with the user the certificate was issued to and obviously the IP address with the one of your VM.