a1ive / grub

Fork of GRUB 2 to add various features.
GNU General Public License v3.0
138 stars 38 forks source link

Query: How to get RAM size of system #55

Closed steve6375 closed 4 years ago

steve6375 commented 4 years ago

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 4 years ago

Legacy-BIOS? I have no idea.

On Fri, Apr 17, 2020, 14:38 Steve Si notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/a1ive/grub/issues/55, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRNAGUXZA4OQIXQFJEVQMLRM72OPANCNFSM4MKPWAAQ .

steve6375 commented 4 years ago

UEFI BIOS?

a1ive commented 4 years ago

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.

steve6375 commented 4 years ago

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 4 years ago

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 4 years ago

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

How to get the total amount of RAM in grub4dos?

steve6375 commented 4 years ago
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.

steve6375 commented 4 years ago

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

steve6375 commented 4 years ago

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

a1ive commented 4 years ago

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

steve6375 commented 4 years ago

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

steve6375 commented 4 years ago

Thanks - great work!