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

Disabling power management for WiFi after power cord detach

Some Linux systems have very poor WiFi performance after power cord detach. The reason is power management, which sets the WiFi card on powersave. Notably Broadcom cards behave very badly on powersave and under problematic reception conditions may…

Some Linux systems have very poor WiFi performance after power cord detach. The reason is power management, which sets the WiFi card on powersave. Notably Broadcom cards behave very badly on powersave and under problematic reception conditions may break altogether. The best solution if to disable powersave if on battery.

You can do this temporaly with

iwconfig <wifiinterface> power off

A lasting solution is to add this empty file as su:

touch /etc/pm/power.d/wireless

This file overrides the one in /usr/lib/pm-utils/power.d/wireless which sets power consumption when on battery to a lower level.

Get rid of unused Ubuntu Kubuntu kernels

This command, executed as root, will free some space after a kernel upgrade: dpkg -l ‘linux-*’ | sed ‘/^ii/!d;/'”$(uname -r | sed “s/(.*)-([^0-9]+)/1/”)”‘/d;s/^[^ ]* [^ ]* ([^ ]*).*/1/;/[0-9]/!d’ | xargs sudo apt-get -y purge (Seen from h…

This command, executed as root, will free some space after a kernel upgrade:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

(Seen from http://ubuntugenius.wordpress.com/2011/01/08/ubuntu-cleanup-how-to-remove-all…