Unable to restore GRUB / grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi': Input/output error

Hello guys,
I have got a problem to restore GRUB.
UEFI, GPT dual boot with windows 8.1 and Manjaro

I had Windows and Manjaro on the same disk. I had to reinstal Windows. So now, I am trying to restore GRUB and configure dual boot as before. I am following these steps from live USB:wiki.manjaro.org/index.php/GRUB/Restore_the_GRUB_Bootloader

However I am getting following error:
[manjaro-gnome /]# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
Installing for x86_64-efi platform.
grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi’: Input/output error.

In /etc/fstab I found wrong UUID, so I edited the file with correct UUID but still getting the same error.
Bash output here:pastebin.com/JS7mEqWF
Please advise.
Thank you.

Welcome to the forum! :slight_smile:

Correcting the UUID is only half of the story. You also have to mount the correct EFI system partition to /boot/efi. However, my guess is that your Windows installation has nuked your original EFI partition and created a new one.

if the pastebin is not accessible for you, here are some outputs:

lsblk -o PATH,PTTYPE,PARTTYPE,FSTYPE,PARTTYPENAME                                                   ✔ 
PATH       PTTYPE PARTTYPE                             FSTYPE   PARTTYPENAME
/dev/loop0                                             squashfs 
/dev/loop1                                             squashfs 
/dev/loop2                                             squashfs 
/dev/loop3                                             squashfs 
/dev/sda   gpt                                                  
/dev/sda1  gpt    de94bba4-06d1-4d40-a16a-bfd50179d6ac ntfs     Windows recovery environment
/dev/sda2  gpt    c12a7328-f81f-11d2-ba4b-00a0c93ec93b vfat     EFI System
/dev/sda3  gpt    e3c9e316-0b5c-4db8-817d-f92df00215ae          Microsoft reserved
/dev/sda4  gpt    ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 ntfs     Microsoft basic data
/dev/sda5  gpt    0fc63daf-8483-4772-8e79-3d69d8477de4 ext4     Linux filesystem
/dev/sda6  gpt    0fc63daf-8483-4772-8e79-3d69d8477de4 ext4     Linux filesystem
/dev/sda7  gpt    ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 ntfs     Microsoft basic data
/dev/sda8  gpt    ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 ntfs     Microsoft basic data
/dev/sdb   dos                                         iso9660  
/dev/sdb1  dos    0x0                                  iso9660  Empty
/dev/sdb2  dos    0xef                                 vfat     EFI (FAT-12/16/32)
/dev/sr0   

                                                 
    ~  sudo fdisk -l /dev/sda                                                                              ✔ 
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000LM014-1EJ1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F9750146-D985-4076-88BA-37D1A46DA6CA

Device          Start        End    Sectors  Size Type
/dev/sda1        2048     616447     614400  300M Windows recovery environment
/dev/sda2      616448     821247     204800  100M EFI System
/dev/sda3      821248    1083391     262144  128M Microsoft reserved
/dev/sda4     1083392 1691406335 1690322944  806G Microsoft basic data
/dev/sda5  1691406336 1754894335   63488000 30.3G Linux filesystem
/dev/sda6  1754894336 1871630335  116736000 55.7G Linux filesystem
/dev/sda7  1871630336 1902321663   30691328 14.6G Microsoft basic data
/dev/sda8  1902321664 1953521663   51200000 24.4G Microsoft basic data

    ~  su                                                                                                  ✔ 
[manjaro-gnome manjaro]# mount /dev/sda5 /mnt
[manjaro-gnome manjaro]# mount /dev/sda2 /mnt/boot/efi
[manjaro-gnome manjaro]# manjaro-chroot /mnt /bin/bash
[manjaro-gnome /]# pacman -Syu grub
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 multilib is up to date
warning: grub-2.04-22 is up to date -- reinstalling
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (1) grub-2.04-22

Total Installed Size:  49.00 MiB
Net Upgrade Size:       0.00 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                                        [######################################] 100%
(1/1) checking package integrity                                      [######################################] 100%
(1/1) loading package files                                           [######################################] 100%
(1/1) checking for file conflicts                                     [######################################] 100%
(1/1) checking available disk space                                   [######################################] 100%
:: Processing package changes...
(1/1) reinstalling grub                                               [######################################] 100%
:: Running post-transaction hooks...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Updating the info directory file...


[manjaro-gnome /]# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
Installing for x86_64-efi platform.
grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi': Input/output error.

[manjaro-gnome /]# ls /sys/firmware/efi
config_table  efivars  fw_platform_size  fw_vendor  runtime  runtime-map  systab

[manjaro-gnome /]# exit
exit

[manjaro-gnome manjaro]# modprobe efivarfs

[manjaro-gnome manjaro]# manjaro-chroot /mnt /bin/bash

[manjaro-gnome /]# mount -t efivarfs efivarfs /sys/firmware/efi/efivars
mount: /sys/firmware/efi/efivars: efivarfs already mounted on /sys/firmware/efi/efivars.

[manjaro-gnome /]# ls /sys/firmware/efi
config_table  efivars  fw_platform_size  fw_vendor  runtime  runtime-map  systab
[manjaro-gnome /]# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
Installing for x86_64-efi platform.
grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi': Input/output error.

[manjaro-gnome manjaro]# lsblk -f
NAME   FSTYPE   FSVER      LABEL              UUID                                 FSAVAIL FSUSE% MOUNTPOINT
loop0  squashfs 4.0                                                                      0   100% /run/miso/sfs/liv
loop1  squashfs 4.0                                                                      0   100% /run/miso/sfs/mhw
loop2  squashfs 4.0                                                                      0   100% /run/miso/sfs/des
loop3  squashfs 4.0                                                                      0   100% /run/miso/sfs/roo
sda                                                                                               
├─sda1 ntfs                Obnovenie          6040453640451466                                    
├─sda2 vfat     FAT32                         744C-0628                              70.5M    27% /mnt/boot/efi
├─sda3                                                                                            
├─sda4 ntfs                                   86F25DC3F25DB7DF                                    
├─sda5 ext4     1.0                           f070e32a-68a2-4039-9342-adfa4f4ae856   19.4G    29% /mnt
├─sda6 ext4     1.0                           c06822b2-7ce9-4e68-a301-82572c3d9b26                
├─sda7 ntfs                Nový zväzok        849893CE9893BD5C                                    
└─sda8 ntfs                Nový zväzok        8A48C21548C1FFC5                                    
sdb    iso9660  Joliet Ext MANJARO_GNOME_2105 2021-05-19-14-31-36-00                     0   100% /run/miso/bootmnt
├─sdb1 iso9660  Joliet Ext MANJARO_GNOME_2105 2021-05-19-14-31-36-00                              
└─sdb2 vfat     FAT12      MISO_EFI           C301-8C3B                                           
sr0

[manjaro-gnome /]# cat /etc/fstab
#/etc/fstab: static file system information.
#
#Use 'blkid' to print the universally unique identifier for a device; this may
#be used with UUID= as a more robust way to name devices that works even if
#disks are added and removed. See fstab(5).
#
#<file system>             <mount point>  <type>  <options>  <dump>  <pass>
#UUID=EC34-F680                            /boot/efi      vfat    umask=0077 0 2
UUID=744C-0628                            /boot/efi      vfat    umask=0077 0 2
UUID=f070e32a-68a2-4039-9342-adfa4f4ae856 /              ext4    defaults,noatime 0 1
UUID=c06822b2-7ce9-4e68-a301-82572c3d9b26 /home          ext4    defaults,noatime 0 2

[manjaro-gnome /]# ls /sys/firmware/efi
config_table  efivars  fw_platform_size  fw_vendor  runtime  runtime-map  systab

[manjaro-gnome /]# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=manjaro --recheck
Installing for x86_64-efi platform.
grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi': Input/output error.

I think I did it with following, or am I wrong ?
[manjaro-gnome manjaro]# mount /dev/sda2 /mnt/boot/efi

Btw I tried to restore the GRUB few times and restarted a PC. Since that, even my Windows is booting slower…not sure if related.

  • Does the directory /boot/efi/EFI/manjaro exist?

  • Are Secure Boot and Fast Boot disabled? (Windows may have re-enabled them again.)

Yes, secure boot is disabled in UEFI. I checked that before.
In regards your second question, not sure where to look for. In chroot ?
This output outside chroot:

[manjaro-gnome manjaro]# mount /dev/sda5 /mnt
[manjaro-gnome manjaro]# mount /dev/sda2 /mnt/boot/efi

[manjaro-gnome manjaro]# ls -l /boot/
total 11704
-rw-r--r-- 1 root root   40960 May 11 17:12 amd-ucode.img
drwxr-xr-x 2 root root      30 May 19 13:52 grub
-rw-r--r-- 1 root root 3624960 Feb 17 08:15 intel-ucode.img
-rw-r--r-- 1 root root      22 May 11 19:38 linux510-x86_64.kver
drwxr-xr-x 2 root root      34 May 19 13:52 memtest86+
-rw-r--r-- 1 root root 8318336 May 19 13:52 vmlinuz-5.10-x86_64

[manjaro-gnome manjaro]# ls -l /mnt/boot/efi/EFI/manjaro/
**ls: cannot access '/mnt/boot/efi/EFI/manjaro/': Input/output error**

[manjaro-gnome manjaro]# ls -l /mnt/boot/efi/EFI/
ls: cannot access '/mnt/boot/efi/EFI/manjaro': Input/output error
total 2
drwxr-xr-x 2 root root 1024 May 24 15:15 Boot
drwxr-xr-x 3 root root 1024 May 24 15:09 Microsoft
**d????????? ? ?    ?       ?            ? manjaro**

Hint: put three backticks above and below the terminal output ─ it makes everything more readable. :wink:

That’s not looking good. The EFI system partition has a FAT32 filesystem, and therefore its permissions are virtual. This means that ls should be seeing those permissions just as well as for the two other directories in there, and yet it cannot read those permissions. :astonished:

The only thing I can think of, off the top of my head, would be that your reinstallation of Windows has truncated your EFI partition, and thus, that the filesystem is damaged. :thinking:

Okay… Try the following inside the chroot:arrow_down:

[ -f /boot/efi/EFI/manjaro ] && rm /boot/efi/EFI/manjaro
[ -d /boot/efi/EFI/manjaro ] && rm -rf /boot/efi/EFI/manjaro
mkdir /boot/efi/EFI/manjaro
grub-install --target=x86_64-efi --bootloader-id=manjaro --recheck --no-rs-codes --modules="part_msdos part_gpt"

ok, dont kill me if I did it wrongly,
but…
when I reinstalled Windows from live usb, I deleted efi, backup and windows partitions and started from scratch (let windows to recreate the partitions on its own)
Windows installed successfully.

Then I tried to restore GRUB as both (root and home) partitions were still there.
If my logic was wrong, please explain.

Windows tends to create a smaller EFI partition than Manjaro. But try the advice I added to my previous post, and then we’ll take it from there.

No luck. Is the path correct as I mounted it under /mnt ?

[manjaro-gnome manjaro]# mount /dev/sda5 /mnt
[manjaro-gnome manjaro]# mount /dev/sda2 /mnt/boot/efi

[manjaro-gnome manjaro]# manjaro-chroot /mnt /bin/bash

[manjaro-gnome /]# [ -f /boot/efi/EFI/manjaro ] && rm /boot/efi/EFI/manjaro
[manjaro-gnome /]# [ -d /boot/efi/EFI/manjaro ] && rm -rf /boot/efi/EFI/manjaro
[manjaro-gnome /]# mkdir /boot/efi/EFI/manjaro
mkdir: cannot create directory '/boot/efi/EFI/manjaro': Input/output error

[manjaro-gnome /]# [ -f /boot/efi/EFI/manjaro ] && rm /boot/efi/EFI/manjaro
[manjaro-gnome /]# [ -d /boot/efi/EFI/manjaro ] && rm -rf /boot/efi/EFI/manjaro
[manjaro-gnome /]# ls -l /mnt/boot/efi
ls: cannot access '/mnt/boot/efi': No such file or directory
[manjaro-gnome /]# ls -l /boot/efi/EFI/manjaro
ls: cannot access '/boot/efi/EFI/manjaro': Input/output error
[manjaro-gnome /]# ls -l /boot/efi/EFI/       
ls: cannot access '/boot/efi/EFI/manjaro': Input/output error
total 2
drwxr-xr-x 2 root root 1024 May 24 17:15 Boot
drwxr-xr-x 3 root root 1024 May 24 17:09 Microsoft
d????????? ? ?    ?       ?            ? manjaro

[manjaro-gnome /]# grub-install --target=x86_64-efi --bootloader-id=manjaro --recheck --no-rs-codes --modules="part_msdos part_gpt"

Installing for x86_64-efi platform.
grub-install: error: cannot open `/boot/efi/EFI/manjaro/grubx64.efi': Input/output error.

Inside the chroot that shouldn’t matter, but if you’re going to use manjaro-chroot then you should not mount those partitions manually first.

  • Either mount the partitions manually (as you’ve done) and use a regular chroot command; or
  • Let manjaro-chroot take care of the mounting.

hmm, but it is written in this guide:wiki.manjaro.org/index.php/GRUB/Restore_the_GRUB_Bootloader

btw I tried your advice and it fails:
[manjaro-gnome manjaro]# umount /dev/sda2 /mnt/boot/efi
umount: /mnt/boot/efi: not mounted.
[manjaro-gnome manjaro]# umount /dev/sda5 /mnt
umount: /mnt: not mounted.
[manjaro-gnome manjaro]# manjaro-chroot /mnt /bin/bash
mount: /mnt/proc: mount point does not exist.
==> ERROR: failed to setup API filesystems in chroot /mnt
[manjaro-gnome manjaro]# manjaro-chroot
==> ERROR: Can’t create chroot on non-directory
[manjaro-gnome manjaro]# manjaro-chroot /mnt /bin/bash
mount: /mnt/proc: mount point does not exist.
==> ERROR: failed to setup API filesystems in chroot /mnt

The correct usage is…

sudo su -
manjaro-chroot -a

… followed by whatever other commands you need to execute, such as grub-install.

[manjaro-gnome manjaro]# manjaro-chroot -a
grub-probe: error: cannot find a GRUB drive for /dev/sdb1.  Check your device.map.
grub-probe: error: cannot find a GRUB drive for /dev/sdb1.  Check your device.map.
==> Mounting (ManjaroLinux) [/dev/sda5]
 --> mount: [/mnt]
 --> mount: [/mnt/boot/efi]
 --> mount: [/mnt/home]
[manjaro-gnome /]# fdisk -l /dev/sda
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000LM014-1EJ1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F9750146-D985-4076-88BA-37D1A46DA6CA

Device          Start        End    Sectors  Size Type
/dev/sda1        2048     616447     614400  300M Windows recovery environment
/dev/sda2      616448     821247     204800  100M EFI System
/dev/sda3      821248    1083391     262144  128M Microsoft reserved
/dev/sda4     1083392 1691406335 1690322944  806G Microsoft basic data
/dev/sda5  1691406336 1754894335   63488000 30.3G Linux filesystem
/dev/sda6  1754894336 1871630335  116736000 55.7G Linux filesystem
/dev/sda7  1871630336 1902321663   30691328 14.6G Microsoft basic data
/dev/sda8  1902321664 1953521663   51200000 24.4G Microsoft basic data
[manjaro-gnome /]# [ -f /boot/efi/EFI/manjaro ] && rm /boot/efi/EFI/manjaro
[manjaro-gnome /]# [ -d /boot/efi/EFI/manjaro ] && rm -rf /boot/efi/EFI/manjaro
[manjaro-gnome /]# mkdir /boot/efi/EFI/manjaro
mkdir: cannot create directory '/boot/efi/EFI/manjaro': Input/output error
[manjaro-gnome /]# ls -l /boot/efi/EFI/
ls: cannot access '/boot/efi/EFI/manjaro': Input/output error
total 2
drwxr-xr-x 2 root root 1024 May 24 17:15 Boot
drwxr-xr-x 3 root root 1024 May 24 17:09 Microsoft
d????????? ? ?    ?       ?            ? manjaro

Yep, I’m afraid Windows ruined your EFI partition. That, or the drive itself is going bad. :man_shrugging:

What options do we have ?
Btw how to check that partition to confirm/exclude hdd issue?

Wrong question. Check the S.M.A.R.T. status of your drive first. If the drive is okay, then you can try running a fsck.vfat on it ─ important note: the filesystem may not be mounted or otherwise in use when running fsck.vfat!

I ran smart control prior windows reinstallation, yesterday morning. Shall i run it again?

When booting from live usb, do I have to umont /boot/efi? Not sure what you meant by that…

If you boot from the live medium, then you must not mount anything or do any chroot'ing. Just open up a terminal, become root by way of… :arrow_down:

sudo su -

… and then run fsck.vfat on that partition.

Probably, I need your advice what repair option to select:

[manjaro-gnome manjaro]# fsck.vfat -n /dev/sda2
fsck.fat 4.2 (2021-01-31)
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
  65:01/00
  Not automatically fixing this.
/EFI/manjaro
  Contains a free cluster (1781). Assuming EOF.
/EFI/Microsoft/Boot/BCD.LOG
  Contains a free cluster (1781). Assuming EOF.
/EFI/Microsoft/Boot/BCD.LOG
  File size is 32768 bytes, cluster chain length is 29696 bytes.
  Truncating file to 29696 bytes.
Reclaimed 138 unused clusters (141312 bytes).
Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 Automatically removing dirty bit.
Free cluster summary wrong (72213 vs. really 72354)
  Auto-correcting.

Leaving filesystem unchanged.
/dev/sda2: 168 files, 25950/98304 clusters
[manjaro-gnome manjaro]# fsck.vfat /dev/sda2
fsck.fat 4.2 (2021-01-31)
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
  65:01/00
1) Copy original to backup
2) Copy backup to original
3) No action
[123?q]?