November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

The file /boot/grub/stage1 not read correctly

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>