The file /boot/grub/stage1 not read correctly

After pxe booting a server and installing linux from a cpio archive, grub failed to load using the grub-install command. The error presented was as follows:

root@pxe:~# mkdir /target
root@pxe:~# mount /dev/sda1 /target
root@pxe:~# chroot /target
root@pxe:~# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.

Since command line didn’t work, I tried installing grub via the grub shell:

root@pxe:~# grub
 
    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)
 
 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... no
 
Error 2: Bad file or directory type
grub>

This too failed, with a different error message. You may have noticed the first error message given while attempting to install grub with the grub-install command yielded: The file /boot/grub/stage1 not read correctly While attempting to install grub via the grub shell yielded: Error 2: Bad file or directory type After some research, grub only works on an inode size of 128, and the pxe system formatted the file system with an inode size of 256.

root@pxe:~# tune2fs -l /dev/sda1 | grep -i 'inode size'
Inode size:               256

The system being reimaged was an older legacy system, and the pxe system had been upgraded months prior. Having remembered this, I compared versions of mke2fs and found that the upgraded version creates 256-byte inodes by default, where the older version was 128. To correct this, I updated the pxe imaging scripts responsible for formatting the disks with the -I option as follows:

root@pxe:~# mke2fs -L / -I 128 -F -j -O dir_index /dev/sda1

Once recreating the file system with a defined inode size of 128, the grub-install command worked successfully.

root@pxe:~# tune2fs -l /dev/sda1 | grep -i 'inode size'
Inode size:               128

Link to original: The file /boot/grub/stage1 not read correctly

Other useful links:

Link to original: Remove Master Boot Code but leave Partition Table?

Link to original: Installing GRUB using grub-install

Link to original: How to make a Super Grub2 Disk

Leave a Reply