Grub fix linux boot

From richud.com
Jump to: navigation, search


MBR and/or grub config broken

Easiest and quickest way to just fix it if either is a problem is using a LiveCD from the OS

  • Boot into LiveCD of Ubuntu, if you are fixing a 64bit system use a 64bit live CD otherwise chroot wont work.
  • sda = drive to fix
  • sdb4 = boot partition on drive to fix
  • Check 4th partition is marked active with fdisk in this example.
sudo fdisk -l /dev/sda
sudo mkdir -p /mnt/a
sudo mount /dev/sda4 /mnt/a
sudo mount -o bind /dev /mnt/a/dev
sudo mount -o bind /sys /mnt/a/sys
sudo mount -o bind /proc /mnt/a/proc
sudo chroot /mnt/a
grub-install /dev/sda
update-grub

BTFRS additional notes

  • If it is BTFRS change "sudo mount /dev/sda4 /mnt/a" to "sudo mount -o subvol=@ /dev/sda4 /mnt/a"
  • You also need a partition starting at 1Mb , not sector 63, else grub won't fit.

Test grub Fix Run through

Should see something like

ubuntu@ubuntu:~$ sudo fdisk -l /dev/sda

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001f875

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63   102398309    51199123+   7  HPFS/NTFS/exFAT
/dev/sda2       102398310   266245244    81923467+   7  HPFS/NTFS/exFAT
/dev/sda4   *   348168192   488396799    70114304   83  Linux

ubuntu@ubuntu:~$ sudo mkdir -p /mnt/a
ubuntu@ubuntu:~$ sudo mount /dev/sda4 /mnt/a
ubuntu@ubuntu:~$ sudo mount -o bind /dev /mnt/a/dev
ubuntu@ubuntu:~$ sudo mount -o bind /sys /mnt/a/sys
ubuntu@ubuntu:~$ sudo mount -o bind /proc /mnt/a/proc
ubuntu@ubuntu:~$ sudo chroot /mnt/a
root@ubuntu:/# grub-install /dev/sda
Installation finished. No error reported.
root@ubuntu:/# update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-29-generic
Found initrd image: /boot/initrd.img-3.2.0-29-generic
Found linux image: /boot/vmlinuz-3.0.0-24-generic
Found initrd image: /boot/initrd.img-3.0.0-24-generic
Found linux image: /boot/vmlinuz-2.6.38-10-generic
Found initrd image: /boot/initrd.img-2.6.38-10-generic
Found linux image: /boot/vmlinuz-2.6.38-8-generic
Found initrd image: /boot/initrd.img-2.6.38-8-generic
Found linux image: /boot/vmlinuz-2.6.35-28-generic
Found initrd image: /boot/initrd.img-2.6.35-28-generic
Found linux image: /boot/vmlinuz-2.6.32-28-generic
Found initrd image: /boot/initrd.img-2.6.32-28-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Microsoft Windows XP Professional on /dev/sda1
Found Windows 7 (loader) on /dev/sda2
done
root@ubuntu:/#