I'm trying to boot a bare system in the form of an ISO written on a USB drive. I compiled the kernel and Busybox, created an initramfs file with Busybox and an init script, formatted the kernel and initramfs images into an ISO, then wrote that ISO directly to the USB drive using dd. I tested the drive directly using the following command:
Code:
qemu-system-x86_64 -hda /dev/sda
It boots into GRUB and displays the one entry I created. I can select the entry, and the boot procedure begins and prints out all the log info to the screen, and eventually I get access to the shell that I spawn in the init script. If I press CTRL+D and kill the shell, the kernel goes into a panic as would be expected.
However, when I try to boot the drive directly on my PC, GRUB loads, but when I select the entry to boot, nothing is displayed. I think the kernel is booting up, because if I press CTRL+D I can see from my blinking CAPS lock key that the kernel is panicking. But nothing shows up on the screen. Any ideas as to why the drive is bootable in QEMU but not my actual PC?
Some extra details--
Linux Kernel 5.19.17
compilation commands:
Code:
make x86_64_defconfig
(everything else left default)
Busybox 1.34.1
Code:
make x86_64_defconfig
Enable static linking, everything else default. I'm running Manjaro which doesn't include libcrypt.a, so I downloaded it manually and copied it into my /lib directory.
Inside the Busybox _install directory
Create a file "init".
Init script:
Code:
#!/bin/sh
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
echo "Hello, Linux!"
exec /bin/sh
Creating initramfs.cpio.gz from the _install directory
Code:
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz
To create the ISO image, inside of a directory called iso/
Code:
mkdir iso/boot iso/boot/grub
cp <kernel build dir>/boot/bzImage <Busybox build directory>/initramfs.cpio.gz .
Create a file in iso/boot/grub gruf.cfg, contents:
Code:
set default=0
set timeout=10
insmod efi_gop
insmod font
if loadfont /boot/grub/fonts/unicode.pf2
then
insmod gfxterm
set gfxmode=auto
set gfxpayload=keep
terminal_output gfxterm
fi
menuentry 'myos' --class os {
insmod gzio
insmod part_msdos
linux /boot/bzImage
initrd /boot/initramfs.cpio.gz
}
To make the ISO
Code:
grub-mkrescue -o myos.iso iso/
And finally I write myos.iso directly to /dev/sda.