a1ive/grub

Query: How to get RAM size of system

steve6375 opened this issue · 12 comments

In grub4dos I can get the total amount of RAM in a system.
How can I do this with grub2 (MBR and UEFI)?
For instance, I can automatically select a 32-bit install of Windows from a dual architecture ISO if the system has <4GB of RAM. Or run a 32-bit version of Linux if <4GB of RAM instead of the 64-bit version.

a1ive commented

UEFI BIOS?

a1ive commented

I can automatically select a 32-bit install of Windows from a dual architecture ISO if the system has <4GB of RAM.

You can't boot/install a 32-bit Windows if UEFI firmware is 64-bit.

Sure , in that case I was thinking of Legacy boot.
But you can run Linux 32-bit kernels from UEFI64 boot (for instance).

a1ive commented

But you can run Linux 32-bit kernels from UEFI64 boot (for instance).

compatibility of 32-bit linux is bad. It doesn't work no some tablets with 64-bit CPU/UEFI.
besides many linux distros (eg. Ubuntu) have dropped support for 32-bit.

a1ive commented

Sure , in that case I was thinking of Legacy boot.

How to get the total amount of RAM in grub4dos?

set /a M=*0x8298 & 0xffffffff>>10+1 > nul && set /a M1=*0x82c0>>10+1 > nul
set /a M=%M% + %M1% > nul

grub4dos has documented memory location where it is stored.
0000:8298 4 (DWORD) saved_mem_upper (extended memory size in KB)
0000:82C0 8 (QWORD) saved_mem_higher (max contiguous mem in KB starting at 4G

can do a BIOS call, int15 e820h
https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820

See grub4dos stage2\common.c for code.

That is showing memory above 4GB
You need to add up all conv-mem entries to get total memory?

What variable is the result returned in?
--set=VAR work ?

a1ive commented

download latest build.
stat -q -r -s a
echo $a
深度截图_选择区域_20200417201506

Thanks. MBR result agrees with grub4dos within +/-1. 👍

Thanks - great work!