Discussion:
Building grub2 for use as a kernel on qemu
Shaun Reitan
2017-02-02 00:33:58 UTC
Permalink
I'm attempting to build a grub2 image that will be used with QEMU to
load the grub configuration from a flat disk image (no partitioning,
just a filesystem). I've created a grub.cfg with the following inside of
it.

echo "Hold onto your grub!"
for grubcfg in /boot/grub2/grub.cfg /etc/grub.cfg; do
echo $grubcfg
done

I've then built the image by doing the following...

grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/

When starting qemu using that image as the kernel I do see grub loaded,
however i'm dumped at a shell. What i've realized is that the for loop
in my grub.cfg is not working, but whats weird is that a for loop in the
shell works fine. I am able to load the grub.cfg from the disk if i do
the following...

set root=(hd0)
configfile /boot/grub2/grub.cfg

Any help on what i'm doing wrong here. This grub2 image will boot many
different linux distros so i need grub to search for the grub.cfg in a
few places.

--
Shaun
Andrei Borzenkov
2017-02-02 03:25:17 UTC
Permalink
Post by Shaun Reitan
I'm attempting to build a grub2 image that will be used with QEMU to
load the grub configuration from a flat disk image (no partitioning,
just a filesystem). I've created a grub.cfg with the following inside of
it.
echo "Hold onto your grub!"
for grubcfg in /boot/grub2/grub.cfg /etc/grub.cfg; do
echo $grubcfg
done
I've then built the image by doing the following...
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
When starting qemu using that image as the kernel I do see grub loaded,
however i'm dumped at a shell. What i've realized is that the for loop
in my grub.cfg is not working, but whats weird is that a for loop in the
shell works fine.
That's correct. Embedded config is executed in very limited environment
(this is rescue mode you end in when normal.mod cannot be loaded),
before normal.mod is loaded, and does not support scripting which is
implemented by normal.mod. Embedded config is intended only to provide
information about normal.mod (or in general $prefix) location.
Post by Shaun Reitan
I am able to load the grub.cfg from the disk if i do
the following...
set root=(hd0)
configfile /boot/grub2/grub.cfg
Any help on what i'm doing wrong here. This grub2 image will boot many
different linux distros so i need grub to search for the grub.cfg in a
few places.
Use grub-mkstandalone to create image that includes internal memory disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Andrei Borzenkov
2017-02-02 08:01:58 UTC
Permalink
On Thu, Feb 2, 2017 at 6:25 AM, Andrei Borzenkov <***@gmail.com> wrote:
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal memory disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
Shaun Reitan
2017-02-02 19:30:27 UTC
Permalink
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using

./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core

and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.

--
Shaun



------ Original Message ------
From: "Andrei Borzenkov" <***@gmail.com>
To: "Shaun Reitan" <***@ndchost.com>; "help-***@gnu.org"
<Help-***@gnu.org>
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal memory disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of
megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Andrei Borzenkov
2017-02-03 03:15:41 UTC
Permalink
Post by Shaun Reitan
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using
./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core
and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.
QEMU platform is intended to run on "bare metal" replacing BIOS, i.e.

qemu-system-x86_64 -bios grub2.img

You will need to include at_keyboard in image to get console input.
Post by Shaun Reitan
--
Shaun
------ Original Message ------
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal memory disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Shaun Reitan
2017-02-03 18:23:28 UTC
Permalink
Ya, that’s where i originally started with this was building a bios
(actually started with coreboot + grub2) but the issue i found was that
grub doesn't seam to be able to see the disks. It can if i run the qemu
system using full virt with harddrive emulation but if i try and use
virtio for better performance the disk is just missing. I'm guessing
grub probably needs virtio drivers simular to what was done with xen.

At this point i'm a bit lost as to what i should try next. Sounds like
i386-pc built at a kernel is probably the best solution however i need
to figure out how to build an image that can search and load a
configfile from the disk. grub-mkstandalone says the image is too
large, i'm not sure how to strip it down.

So then, should i be using grub-mkimage with a memdisk that has another
grub config? So i'd build the kernel with a configfile
(memdisk)/boot/grub/grub.cfg and inside that grub.cfg it would do the
searching? Would i be in normal mode then? I'm going to attempt to
test this out now, i just wanted to shoot off this email just in-case
your still up since it seams like were on opposite ends of the world :)

--
Shaun



------ Original Message ------
From: "Andrei Borzenkov" <***@gmail.com>
To: "Shaun Reitan" <***@ndchost.com>; "help-***@gnu.org"
<Help-***@gnu.org>
Sent: 2017-02-02 07:15:41 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using
./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core
and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.
QEMU platform is intended to run on "bare metal" replacing BIOS, i.e.
qemu-system-x86_64 -bios grub2.img
You will need to include at_keyboard in image to get console input.
Post by Shaun Reitan
--
Shaun
------ Original Message ------
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
On Thu, Feb 2, 2017 at 6:25 AM, Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat
echo
gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal
memory
disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Andrei Borzenkov
2017-02-03 19:06:28 UTC
Permalink
Post by Shaun Reitan
Ya, that’s where i originally started with this was building a bios
(actually started with coreboot + grub2) but the issue i found was that
grub doesn't seam to be able to see the disks. It can if i run the qemu
system using full virt with harddrive emulation but if i try and use
virtio for better performance the disk is just missing. I'm guessing
grub probably needs virtio drivers simular to what was done with xen.
Yes, unfortunately qemu port currently does not support virtio devices.
Post by Shaun Reitan
At this point i'm a bit lost as to what i should try next. Sounds like
i386-pc built at a kernel is probably the best solution however i need
to figure out how to build an image that can search and load a
configfile from the disk. grub-mkstandalone says the image is too
large, i'm not sure how to strip it down.
--fonts= --locales= --themes= --install-modules="..."

This will omit all fonts, locales and themes and only add to memory disk
modules you explicitly listed. I used it successfully more than once on
i386-pc.
Post by Shaun Reitan
So then, should i be using grub-mkimage with a memdisk that has another
grub config? So i'd build the kernel with a configfile
(memdisk)/boot/grub/grub.cfg and inside that grub.cfg it would do the
searching? Would i be in normal mode then? I'm going to attempt to
test this out now, i just wanted to shoot off this email just in-case
your still up since it seams like were on opposite ends of the world :)
--
Shaun
------ Original Message ------
Sent: 2017-02-02 07:15:41 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using
./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core
and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.
QEMU platform is intended to run on "bare metal" replacing BIOS, i.e.
qemu-system-x86_64 -bios grub2.img
You will need to include at_keyboard in image to get console input.
Post by Shaun Reitan
--
Shaun
------ Original Message ------
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat echo gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal memory disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Shaun Reitan
2017-02-03 20:49:46 UTC
Permalink
Andrei,

Tried to build a kernel image using the following.

./bin/grub-mkstandalone -O i386-pc -o grub2.img grub.cfg --fonts=""
--locales="" --themes="" --install-modules="acpi adler32 affs ahci
all_video aout ata at_keyboard biosdisk blocklist boot bufio cat cbfs
cbls cbmemc cbtable cbtime chain cmosdump cmp configfile cpio_be cpio
cpuid crc64 cryptodisk crypto date datetime diskfilter disk div div_test
dm_nv drivemap echo efiemu ehci elf eval exfat exfctest ext2 extcmd fat
file gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync
gzio halt hashsum help iorw iso9660 keylayouts keystatus ldm legacycfg
legacy_password_test linux16 linux loadenv loopback lsacpi lsapm lsmmap
ls lspci lzopio macbless macho memdisk memrw minicmd mmap morse mpi
mul_test multiboot2 multiboot nativedisk net newc nilfs2 normal ntldr
odc offsetio ohci part_gpt password pata pcidump pci priority_queue
probe procfs random read reboot regexp relocator romfs scsi
search_fs_file search_fs_uuid search_label search sendkey serial setjmp
setpci shift_test signature_test sleep syslinuxcfg tar terminal terminfo
test_blockarg testload test tga time trig tr true udf uhci usb_keyboard
usb usbms usbtest vbe verify vga vga_text video_cirrus video xfs xzio"

basically i took every module from the i386-pc/*.mod directory and
attempted to add it. The image was too large so i went through the
module list and removed stuff that i was pretty sure i didnt need.

When i boot the image, i see nothing but the memdisk, i'm also in that
same grub2 shell. I should see a (hd0) along with my (memdisk)

Do you hang out in the #grub channel on irc.freenode.net?

--
Shaun



------ Original Message ------
From: "Andrei Borzenkov" <***@gmail.com>
To: "Shaun Reitan" <***@ndchost.com>; "help-***@gnu.org"
<Help-***@gnu.org>
Sent: 2017-02-03 11:06:28 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
Ya, that’s where i originally started with this was building a bios
(actually started with coreboot + grub2) but the issue i found was that
grub doesn't seam to be able to see the disks. It can if i run the qemu
system using full virt with harddrive emulation but if i try and use
virtio for better performance the disk is just missing. I'm guessing
grub probably needs virtio drivers simular to what was done with xen.
Yes, unfortunately qemu port currently does not support virtio devices.
Post by Shaun Reitan
At this point i'm a bit lost as to what i should try next. Sounds like
i386-pc built at a kernel is probably the best solution however i need
to figure out how to build an image that can search and load a
configfile from the disk. grub-mkstandalone says the image is too
large, i'm not sure how to strip it down.
--fonts= --locales= --themes= --install-modules="..."
This will omit all fonts, locales and themes and only add to memory disk
modules you explicitly listed. I used it successfully more than once on
i386-pc.
Post by Shaun Reitan
So then, should i be using grub-mkimage with a memdisk that has another
grub config? So i'd build the kernel with a configfile
(memdisk)/boot/grub/grub.cfg and inside that grub.cfg it would do the
searching? Would i be in normal mode then? I'm going to attempt to
test this out now, i just wanted to shoot off this email just in-case
your still up since it seams like were on opposite ends of the world :)
--
Shaun
------ Original Message ------
Sent: 2017-02-02 07:15:41 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using
./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core
and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.
QEMU platform is intended to run on "bare metal" replacing BIOS, i.e.
qemu-system-x86_64 -bios grub2.img
You will need to include at_keyboard in image to get console input.
Post by Shaun Reitan
--
Shaun
------ Original Message ------
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
On Thu, Feb 2, 2017 at 6:25 AM, Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat
echo
gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal
memory
disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all
available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Andrei Borzenkov
2017-02-04 05:44:07 UTC
Permalink
Post by Shaun Reitan
Andrei,
Tried to build a kernel image using the following.
./bin/grub-mkstandalone -O i386-pc -o grub2.img grub.cfg --fonts=""
--locales="" --themes="" --install-modules="acpi adler32 affs ahci
all_video aout ata at_keyboard biosdisk blocklist boot bufio cat cbfs
cbls cbmemc cbtable cbtime chain cmosdump cmp configfile cpio_be cpio
cpuid crc64 cryptodisk crypto date datetime diskfilter disk div div_test
dm_nv drivemap echo efiemu ehci elf eval exfat exfctest ext2 extcmd fat
file gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync
gzio halt hashsum help iorw iso9660 keylayouts keystatus ldm legacycfg
legacy_password_test linux16 linux loadenv loopback lsacpi lsapm lsmmap
ls lspci lzopio macbless macho memdisk memrw minicmd mmap morse mpi
mul_test multiboot2 multiboot nativedisk net newc nilfs2 normal ntldr
odc offsetio ohci part_gpt password pata pcidump pci priority_queue
probe procfs random read reboot regexp relocator romfs scsi
search_fs_file search_fs_uuid search_label search sendkey serial setjmp
setpci shift_test signature_test sleep syslinuxcfg tar terminal terminfo
test_blockarg testload test tga time trig tr true udf uhci usb_keyboard
usb usbms usbtest vbe verify vga vga_text video_cirrus video xfs xzio"
basically i took every module from the i386-pc/*.mod directory and
attempted to add it. The image was too large so i went through the
module list and removed stuff that i was pretty sure i didnt need.
When i boot the image, i see nothing but the memdisk, i'm also in that
same grub2 shell. I should see a (hd0) along with my (memdisk)
You need to include biosdisk into image (or in memory disk and load
explicitly from grub.cfg). PC BIOS offers alternative disk driver so
this is image-build-time option.

***@bor-Latitude-E5450:~/build/grub$ echo "insmod biosdisk" > /tmp/grub.cfg
***@bor-Latitude-E5450:~/build/grub$ pkgdatadir=$PWD ./grub-mkstandalone
-d grub-core -O i386-pc -o grub.img --locales= --themes= --fonts=
--install-modules="all_video boot btrfs cat chain configfile echo ext2
fat font gettext gfxmenu gfxterm gfxterm_background gzio halt hfsplus
iso9660 jpeg keystatus loadenv loopback linux memdisk minicmd normal
part_apple part_msdos part_gpt password_pbkdf2 png reboot search
search_fs_uuid search_fs_file search_label sleep squash4 test true video
zfs zfscrypt zfsinfo biosdisk echo linux linux16 ls"
/boot/grub/grub.cfg=/tmp/grub.cfg

***@bor-Latitude-E5450:~/build/grub$ qemu-system-x86_64 -m 1G -device
virtio-scsi-pci -drive
file=/home/bor/vm/tw/hd0.img,if=none,id=hd0,discard=on,format=raw
-device scsi-hd,drive=hd0 -drive
file=/home/bor/vm/tw/test1.img,if=virtio,format=raw -drive
file=/home/bor/vm/tw/test2.img,if=virtio,format=raw -net user -net
nic,model=virtio -kernel grub.img

And "ls" in CLI shows me all disks. Of course you also need to manually
load suitable partition drivers to access partitions.

Alternative is to use grub-mkstandalone ... --modules=biosdisk.

May be we should add --disk-module option of grub-install to other high
level tools.

Oh, and $prefix in standalone image is set to (memdisk)/boot/grub, which
means you need to put grub.cfg in /boot/grub if you want it to be
executed automatically; you use graft syntax for this

grub-mkstandalone ... /boot/grub/grub.cfg=/path/to/your/config/file
Shaun Reitan
2017-02-06 19:40:36 UTC
Permalink
When using this method every time i boot into grub and attempt to search
or even ls (hd0)/ i get a bunch of errors of missing modules.

example:

ls (hd0)/
error: file `/boot/grub/i386-pc/xfs.mod` not found
error: file `/boot/grub/i386-pc/ufs2.mod` not found
error: file `/boot/grub/i386-pc/ufs1_be.mod` not found
...

Any idea why?


--
Shaun


------ Original Message ------
From: "Andrei Borzenkov" <***@gmail.com>
To: "Shaun Reitan" <***@ndchost.com>; "help-***@gnu.org"
<Help-***@gnu.org>
Sent: 2017-02-03 09:44:07 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
Andrei,
Tried to build a kernel image using the following.
./bin/grub-mkstandalone -O i386-pc -o grub2.img grub.cfg --fonts=""
--locales="" --themes="" --install-modules="acpi adler32 affs ahci
all_video aout ata at_keyboard biosdisk blocklist boot bufio cat cbfs
cbls cbmemc cbtable cbtime chain cmosdump cmp configfile cpio_be cpio
cpuid crc64 cryptodisk crypto date datetime diskfilter disk div div_test
dm_nv drivemap echo efiemu ehci elf eval exfat exfctest ext2 extcmd fat
file gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync
gzio halt hashsum help iorw iso9660 keylayouts keystatus ldm
legacycfg
legacy_password_test linux16 linux loadenv loopback lsacpi lsapm lsmmap
ls lspci lzopio macbless macho memdisk memrw minicmd mmap morse mpi
mul_test multiboot2 multiboot nativedisk net newc nilfs2 normal ntldr
odc offsetio ohci part_gpt password pata pcidump pci priority_queue
probe procfs random read reboot regexp relocator romfs scsi
search_fs_file search_fs_uuid search_label search sendkey serial setjmp
setpci shift_test signature_test sleep syslinuxcfg tar terminal terminfo
test_blockarg testload test tga time trig tr true udf uhci
usb_keyboard
usb usbms usbtest vbe verify vga vga_text video_cirrus video xfs xzio"
basically i took every module from the i386-pc/*.mod directory and
attempted to add it. The image was too large so i went through the
module list and removed stuff that i was pretty sure i didnt need.
When i boot the image, i see nothing but the memdisk, i'm also in that
same grub2 shell. I should see a (hd0) along with my (memdisk)
You need to include biosdisk into image (or in memory disk and load
explicitly from grub.cfg). PC BIOS offers alternative disk driver so
this is image-build-time option.
/tmp/grub.cfg
./grub-mkstandalone
-d grub-core -O i386-pc -o grub.img --locales= --themes= --fonts=
--install-modules="all_video boot btrfs cat chain configfile echo ext2
fat font gettext gfxmenu gfxterm gfxterm_background gzio halt hfsplus
iso9660 jpeg keystatus loadenv loopback linux memdisk minicmd normal
part_apple part_msdos part_gpt password_pbkdf2 png reboot search
search_fs_uuid search_fs_file search_label sleep squash4 test true video
zfs zfscrypt zfsinfo biosdisk echo linux linux16 ls"
/boot/grub/grub.cfg=/tmp/grub.cfg
virtio-scsi-pci -drive
file=/home/bor/vm/tw/hd0.img,if=none,id=hd0,discard=on,format=raw
-device scsi-hd,drive=hd0 -drive
file=/home/bor/vm/tw/test1.img,if=virtio,format=raw -drive
file=/home/bor/vm/tw/test2.img,if=virtio,format=raw -net user -net
nic,model=virtio -kernel grub.img
And "ls" in CLI shows me all disks. Of course you also need to manually
load suitable partition drivers to access partitions.
Alternative is to use grub-mkstandalone ... --modules=biosdisk.
May be we should add --disk-module option of grub-install to other high
level tools.
Oh, and $prefix in standalone image is set to (memdisk)/boot/grub, which
means you need to put grub.cfg in /boot/grub if you want it to be
executed automatically; you use graft syntax for this
grub-mkstandalone ... /boot/grub/grub.cfg=/path/to/your/config/file
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Andrei Borzenkov
2017-02-07 14:05:31 UTC
Permalink
When using this method every time i boot into grub and attempt to search or
even ls (hd0)/ i get a bunch of errors of missing modules.
ls (hd0)/
error: file `/boot/grub/i386-pc/xfs.mod` not found
error: file `/boot/grub/i386-pc/ufs2.mod` not found
error: file `/boot/grub/i386-pc/ufs1_be.mod` not found
...
Any idea why?
That is filesystem driver autoprobe which is using
/boot/grub/$platform/fs.lst file; this file is created when grub is
built and contains all available drivers. grub-mkstandalone copies it,
but does not trims according to modules included in memory disk. It
was discussed but I cannot find reference.
--
Shaun
------ Original Message ------
Sent: 2017-02-03 09:44:07 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
Andrei,
Tried to build a kernel image using the following.
./bin/grub-mkstandalone -O i386-pc -o grub2.img grub.cfg --fonts=""
--locales="" --themes="" --install-modules="acpi adler32 affs ahci
all_video aout ata at_keyboard biosdisk blocklist boot bufio cat cbfs
cbls cbmemc cbtable cbtime chain cmosdump cmp configfile cpio_be cpio
cpuid crc64 cryptodisk crypto date datetime diskfilter disk div div_test
dm_nv drivemap echo efiemu ehci elf eval exfat exfctest ext2 extcmd fat
file gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync
gzio halt hashsum help iorw iso9660 keylayouts keystatus ldm legacycfg
legacy_password_test linux16 linux loadenv loopback lsacpi lsapm lsmmap
ls lspci lzopio macbless macho memdisk memrw minicmd mmap morse mpi
mul_test multiboot2 multiboot nativedisk net newc nilfs2 normal ntldr
odc offsetio ohci part_gpt password pata pcidump pci priority_queue
probe procfs random read reboot regexp relocator romfs scsi
search_fs_file search_fs_uuid search_label search sendkey serial setjmp
setpci shift_test signature_test sleep syslinuxcfg tar terminal terminfo
test_blockarg testload test tga time trig tr true udf uhci usb_keyboard
usb usbms usbtest vbe verify vga vga_text video_cirrus video xfs xzio"
basically i took every module from the i386-pc/*.mod directory and
attempted to add it. The image was too large so i went through the
module list and removed stuff that i was pretty sure i didnt need.
When i boot the image, i see nothing but the memdisk, i'm also in that
same grub2 shell. I should see a (hd0) along with my (memdisk)
You need to include biosdisk into image (or in memory disk and load
explicitly from grub.cfg). PC BIOS offers alternative disk driver so
this is image-build-time option.
/tmp/grub.cfg
-d grub-core -O i386-pc -o grub.img --locales= --themes= --fonts=
--install-modules="all_video boot btrfs cat chain configfile echo ext2
fat font gettext gfxmenu gfxterm gfxterm_background gzio halt hfsplus
iso9660 jpeg keystatus loadenv loopback linux memdisk minicmd normal
part_apple part_msdos part_gpt password_pbkdf2 png reboot search
search_fs_uuid search_fs_file search_label sleep squash4 test true video
zfs zfscrypt zfsinfo biosdisk echo linux linux16 ls"
/boot/grub/grub.cfg=/tmp/grub.cfg
virtio-scsi-pci -drive
file=/home/bor/vm/tw/hd0.img,if=none,id=hd0,discard=on,format=raw
-device scsi-hd,drive=hd0 -drive
file=/home/bor/vm/tw/test1.img,if=virtio,format=raw -drive
file=/home/bor/vm/tw/test2.img,if=virtio,format=raw -net user -net
nic,model=virtio -kernel grub.img
And "ls" in CLI shows me all disks. Of course you also need to manually
load suitable partition drivers to access partitions.
Alternative is to use grub-mkstandalone ... --modules=biosdisk.
May be we should add --disk-module option of grub-install to other high
level tools.
Oh, and $prefix in standalone image is set to (memdisk)/boot/grub, which
means you need to put grub.cfg in /boot/grub if you want it to be
executed automatically; you use graft syntax for this
grub-mkstandalone ... /boot/grub/grub.cfg=/path/to/your/config/file
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Shaun Reitan
2017-02-04 01:48:47 UTC
Permalink
Hi Andrei,

OK, i got it to work but it was a process and i'm still not sure it's
100% right. Here's what I did....


# Created grub-bootstrap.cfg
normal (memdisk)/grub.cfg


# Created grub.cfg
for grubcfg in /boot/grub2/grub.cfg /boot/grub2/grub2.cfg
/boot/grub/grub2.cfg /boot/grub/grub.cfg /grub2/grub2.cfg /grub/grub.cfg
/etc/grub2.cfg /etc/grub.cfg ; do
if search -s -f $grubcfg ; then
echo "Reading (${root})$grubcfg"
sleep 1
source $grubcfg
break
fi
done


# Created a memdisk
mkfs.msdos -C memdisk.fat 64

# Copied grub.cfg into the memdisk
mcopy -i memdisk.fat grub.cfg ::grub.cfg

# Built grub2 as a kernel image
./bin/grub-mkimage -O i386-pc -o grub.img -c grub-bootstrap.cfg -m
memdisk.fat -p /boot/grub all_video boot btrfs cat chain configfile echo
ext2 fat font gettext gfxmenu gfxterm gfxterm_background gzio halt
hfsplus iso9660 jpeg keystatus loadenv loopback linux memdisk minicmd
normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search
search_fs_uuid search_fs_file search_label sleep squash4 test true video
zfs zfscrypt zfsinfo biosdisk echo linux linux16

# Started QEMU
qemu-system-x86_64 -vnc 0.0.0.0:0 -drive
file=/dev/mapper/storage1-vm1,if=none,id=hd,format=raw -device
virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -kernel ./grub.img


So far it boots, searches for a grub config in multiple locations and
loads the first one it finds. Everything here look good/ok to you? Any
advice or recommendations? I know you originally wanted me to use
grub-mkstandalone, not sure if there's any difference, advantage,
disadvantage to the way i did this...

Thanks for your help!

--
Shaun R


------ Original Message ------
From: "Andrei Borzenkov" <***@gmail.com>
To: "Shaun Reitan" <***@ndchost.com>; "help-***@gnu.org"
<Help-***@gnu.org>
Sent: 2017-02-03 11:06:28 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
Ya, that’s where i originally started with this was building a bios
(actually started with coreboot + grub2) but the issue i found was that
grub doesn't seam to be able to see the disks. It can if i run the qemu
system using full virt with harddrive emulation but if i try and use
virtio for better performance the disk is just missing. I'm guessing
grub probably needs virtio drivers simular to what was done with xen.
Yes, unfortunately qemu port currently does not support virtio devices.
Post by Shaun Reitan
At this point i'm a bit lost as to what i should try next. Sounds like
i386-pc built at a kernel is probably the best solution however i need
to figure out how to build an image that can search and load a
configfile from the disk. grub-mkstandalone says the image is too
large, i'm not sure how to strip it down.
--fonts= --locales= --themes= --install-modules="..."
This will omit all fonts, locales and themes and only add to memory disk
modules you explicitly listed. I used it successfully more than once on
i386-pc.
Post by Shaun Reitan
So then, should i be using grub-mkimage with a memdisk that has another
grub config? So i'd build the kernel with a configfile
(memdisk)/boot/grub/grub.cfg and inside that grub.cfg it would do the
searching? Would i be in normal mode then? I'm going to attempt to
test this out now, i just wanted to shoot off this email just in-case
your still up since it seams like were on opposite ends of the world :)
--
Shaun
------ Original Message ------
Sent: 2017-02-02 07:15:41 PM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
Post by Shaun Reitan
I guess the question is, should i be using i386-qemu? For kicks i just
built a image using
./grub-mkstandalone -O i386-qemu -o grub2.img boot/grub/grub.cfg -d
grub-core
and qemu will use it, however when i connect to the VNC console all i
see is a bunch of colorful giberish.
QEMU platform is intended to run on "bare metal" replacing BIOS, i.e.
qemu-system-x86_64 -bios grub2.img
You will need to include at_keyboard in image to get console input.
Post by Shaun Reitan
--
Shaun
------ Original Message ------
Sent: 2017-02-02 12:01:58 AM
Subject: Re: Building grub2 for use as a kernel on qemu
Post by Andrei Borzenkov
On Thu, Feb 2, 2017 at 6:25 AM, Andrei Borzenkov
...
Post by Andrei Borzenkov
Post by Shaun Reitan
grub-mkimage -O i386-pc -c grub.cfg -o grub2.img at_keyboard configfile
biosdisk ext2 linux serial halt minicmd terminal all_video cat
echo
gzio
search linux16 normal disk test true fat memdisk tar ls sleep -p
/usr/src/grub/grub-core/
...
Post by Andrei Borzenkov
Use grub-mkstandalone to create image that includes internal
memory
disk
and place your config on this memory disk. Do not include your modules
in image itself. By default grub-mkstandalone adds all
available
modules; if size is an issue (but this is really a couple of megabytes,
so I do not expect it), you can restrict module list and other
components - see help output.
Sorry, missed that you use i386-pc platform, not i386-qemu. Then size
of boot image does matter, you may want to at least exclude themes and
translations (if any). Full standalone image that includes all bells
and whistles for GUI boot does not fit in available memory on this
platform.
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
_______________________________________________
Help-grub mailing list
https://lists.gnu.org/mailman/listinfo/help-grub
Loading...