Ubuntu 16.04: Repair GRUB2


Table of Contents

1 Run LiveDVD

Run Ubuntu 16.04’s LiveDVD like ubuntu-16.04.1-desktop-amd64.iso and select “Try Ubuntu”.

2 Mount storage

Mount HDD and SSD which is installed Ubuntu 16.04. This article uses VirtIO and storage device is /dev/vda. In case of physical machine is /dev/sda.

When using LVM, /dev/vda1 is /boot, /dev/vda5 is LVM volume and /dev/ubuntu-vg is root filesystem. When not using LVM, /dev/vda1 is /boot and /dev/vda5 is root filesystem.

$ sudo mount -o rw /dev/ubuntu-vg/root /mnt # In case non-lvm is /dev/vda5$ sudo mount -o rw /dev/vda1 /mnt/boot$ for fs in proc sys dev; do sudo mount -o bind /$fs /mnt/$fs; done

3 Copy /etc/default/grub

grub-mkconfig’s variable is defined at /etc/default/grub. When installing Ubuntu, /etc/default/grub in LiveDVD will be copied to root filesytem.

$ sudo cp /etc/default/grub /mnt/etc/default/

4 Run chroot

Run chroot to storage root filesystem.

$ sudo chroot /mnt

5 Run lvm2-lvmetadの起動

When using LVM, grub-mkconfig needs running /etc/init.d/lvm2-lvmetad.

# /etc/init.d/lvm2-lvmetad start

6 Repair GRUB2

Reinstall GRUB2 package.

# sudo apt install -y grub2 –reinstall

Write GRUB2 to MBR and /boot with grub-install.

# grub-install /dev/vdaInstalling for i386-pc platform.Installation finished. No error reported.

Create GRUB2 menu with grub-mkconfig.

# grub-mkconfig -o /boot/grub/grub.cfgGenerating grub configuration file …Found linux image: /boot/vmlinuz-4.4.0-42-genericFound initrd image: /boot/initrd.img-4.4.0-42-genericFound linux image: /boot/vmlinuz-4.4.0-38-genericFound initrd image: /boot/initrd.img-4.4.0-38-genericFound linux image: /boot/vmlinuz-4.4.0-31-genericFound initrd image: /boot/initrd.img-4.4.0-31-genericFound memtest86+ image: /memtest86+.elfFound memtest86+ image: /memtest86+.bindone

Android | Linux | SDL - Narrow Escape