Ubuntu – Boot: error: attempt to read or write outside of disk ‘hd0’ after update

backupbootdeja-dupgrub2

error: attempt to read or write outside of disk 'hd0'

(the cause for this below is wrong)

I started using an external hdd to backup using the built in backup software (I'm guessing the back end of this is deja-dup).

After this I start getting error: attempt to read or write outside of disk 'hd0' on boot.

I can still boot since the OS itself is in another drive and the error screen offers to press enter to continue.

It is a minor bug but nice to fix. Does anyone have a workaround?

EDIT 2:

The reason mentioned in the original question is not correct. It probably had to do with an update on grub (I honestly don't know).

Eventually the error caused me to not be able to boot and redirected to grub command line (grub rescue).

I tried this fix but was unsuccessful. Trying to read/write under (hd0,mdsosX) throws the error: attempt to read or write etc.. still.

My fix is below in the answer.

EDIT:

xxx@xxxx:~$ uname -a
Linux xxxx 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Best Answer

The solution that worked for me was re-installing grub using a live USB/CD Ubuntu installer.

After booting to the installer, select try Ubuntu and follow the instructions here to reinstall/reconfigure grub on your main Ubuntu installation.

Mount the partition your Ubuntu Installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount /dev/sda1 mnt.

sudo mount /dev/sdXY /mnt

Now bind the directories that grub needs access to to detect other operating systems, like so.

sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys

Now we jump into that using chroot.

sudo chroot /mnt

Now install, check, and update grub.

This time you only need to add the drive letter (usually a) to replace X, for example: grub-install /dev/sda, grub-install –recheck /dev/sda.

grub-install /dev/sdX
grub-install --recheck /dev/sdX
update-grub  

Now grub is back, all that is left is to exit the chrooted system and unmount everything.

exit &&
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt

Shutdown and turn your computer back on, and you will be met with the default Grub2 screen.

It seems for some reason (maybe some update) grub in the MBR is referring to a wrong location under hd0. Reinstalling/reconfig grub fixed it for me.

Related Question