26

I am trying to get GRUB installed on my non-booting desktop computer, but I am encountering several errors. Other sources discussing these errors have ascribed them to either a lack of free disk space before the first partition (I have the requisite free space), or to a problem with /boot/grub/grub.cfg (problem persists even after regenerating that file correctly).

I booted with a live USB and attempted to reinstall GRUB using the following commands, but I encounter an error that prevents it from working:

$ sudo mount /dev/sda1 /mnt
$ sudo grub-install --root-directory=/mnt /dev/sda
Installing for i386-pc platform.
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels.  This is not supported yet..
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
grub-install: error: will not proceed with blocklists.

However, /dev/sda appears to be formatted correctly for installing grub:

$ sudo fdisk -l /dev/sda

Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 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
Disklabel type: dos
Disk identifier: 0x8d91017b

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1  *     2048 234440703 234438656 111.8G 83 Linux

$ blkid /dev/sda1
/dev/sda1: UUID="84e9ff65-c4ba-42eb-8a6d-ebc703fae1f7" TYPE="ext4" PARTUUID="8d91017b-01"

It has the standard 1 MiB free space at the beginning, and /dev/sda1 is formatted correctly. I have tried using grub-mkconfig to rebuild the config file:

$ for f in proc sys dev dev/pts ; do sudo mount --bind /$f /mnt/$f ; done
$ sudo chroot /mnt
# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.19.0-26-generic
Found initrd image: /boot/initrd.img-3.19.0-26-generic
Found linux image: /boot/vmlinuz-3.19.0-23-generic
Found initrd image: /boot/initrd.img-3.19.0-23-generic
Adding boot menu entry for EFI firmware configuration
done

However, I still get the same error message when running grub-install, whether in or out of the chroot environment.

Booting the live USB in legacy mode, I get the same error; the only difference is the output of running grub-mkconfig in the chroot environment:

# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.19.0-26-generic
Found initrd image: /boot/initrd.img-3.19.0-26-generic
Found linux image: /boot/vmlinuz-3.19.0-23-generic
Found initrd image: /boot/initrd.img-3.19.0-23-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sdc1
done

How can I get grub installed correctly?

4 Answers 4

35

Nuke the gap between the boot sector and the first partition.

# dd if=/dev/zero of=/dev/sdX seek=1 count=2047

That's for if the first partition starts at sector 2048. Some start earlier, especially on drives that were partitioned by Windows. To be sure, run

# fdisk -l /dev/sdX

before starting and check to see where the first partition starts. Use count=S-1, where S is the start of the first partition.

5
  • This worked for me. I'm trying to use BTRFS along a separate ext4 /boot partition. Thanks. Apr 17, 2017 at 2:50
  • Note that this will trash a GPT layout. It's possible to recover from its backup though.
    – CR.
    Feb 7, 2018 at 14:28
  • if you're using GPT then you need to wipe the BIOS BOOT PARTITION. Where that is depends on how you laid out your disk. I put mine after the GPT, between block 34 and 2047, assuming the first "real" partition begins at block 2048. Modifying the given command-line to use seek=34 count=2014 works for me.
    – starfry
    Oct 6, 2018 at 16:00
  • works perfectly!!!! grub should do it automatically though
    – brauliobo
    Jul 13, 2019 at 14:52
  • 1
    Yeah, you'd think so, @brauliobo, but GRUB is total garbage. I don't even use it any more. These days, I use syslinux for mbr and systemd-boot for gpt. Jul 19, 2019 at 18:34
3

One can create a new partition where the GPT record is, then wipe it using dd. That way, only the MBR record will remain.

Assuming problem device is /dev/sda:

Create a new partition in the initial 1 MiB

$ parted /dev/sda
$ mkpart primary ext4 0MiB 1MiB
$ quit

Then, zero the newly created partition

$ dd if=/dev/zero of=/dev/sda2

Then, delete the partition

$ parted /dev/sda
$ rm 2
$ quit

grub-install should now work as expected.

2
  • Please edit your answer to justify what this code does, and why you believe it to be a solution. Oct 20, 2015 at 21:14
  • Worked for me. Edited it for clarity
    – Nitz
    Dec 30, 2015 at 9:06
3

Had a similar problem with the multiple partition labels, although i am quite sure that that is not the case.

sudo grub-install target=i386-pc /dev/sda --force

is what I used to get around this. Tacking on a --force is not a "recommended" solution, but I have had no issues so far =P

1
  • You mean --target?
    – tokland
    Jan 25, 2020 at 10:30
1

Here is what I did that got it working again:

Used gdisk to convert the MBR partition to GPT, insert a partition into the empty space (type EF02 "BIOS Boot partition"), transposed its entry with my original partition, and flagged it as legacy BIOS bootable.

Then ran

$ sudo mount /dev/sda1 /mnt
$ sudo grub-install --root-directory=/mnt /dev/sda

It then installed successfully, and I able to boot to my main drive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .