I'm trying to prepare an image that I can dd into disk or boot using PXE.
Some context: I create an image, partition it using sfdisk (MBR), create loop devices for the whole disk and main partition, format the main partition as ext4, mount it and install a base system + kernel and grub-pc packages using debootstrap, then generate initramfs, mount dev, proc and sys into partition root directory and install grub.
Output of fdisk -l
for /dev/loop0 (loop device for the whole image):
Disk /dev/loop0: 1,1 GiB, 1211572224 bytes, 2366352 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: 0xfdf8e68d
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 * 2048 2097151 2095104 1023M 83 Linux
/dev/loop0p2 2097152 2359295 262144 128M 82 Linux swap / Solaris
Grub install commands:
chroot $ROOT grub-install --target=i386-pc /dev/loop0
chroot $ROOT update-grub
Grub config seems to be generated correctly with kernel and initramfs detected. But when I'm trying to boot system using the resulting image, grub2 can't find any partition:
Loading boot sector... booting...
error: no such device: some-file-system-UUID
error: unknown filesystem.
Entering rescue mode...
grub rescue> ls
(hd0)
grub rescue> insmod ext2
grub rescue> ls
(hd0)
What could be wrong in my grub installation steps? How grub2 can't see a partition that is present in fdisk output?
PS: BIOS is set up for legacy mode. I also tested my image with kvm and have exactly the same result.