Followup: Memory detection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks everyone for your help in getting memory detection working. Here is some info from the original post.

>Can anyone suggest a reliable method of detecting the amount of memory
>is in an ia32 machine during the install when it is running the -BOOT
>kernel?
>
>I am trying to carve up disks based on ram, number of disks, etc and the
>only tricky part is the ram.

The easiest solution came from Chris Adams who said:

Let anaconda figure it out for you!

%pre
ram=`python <<EOF
import sys
sys.path.append('/usr/lib/anaconda')
import iutil
sizekB = iutil.memInstalled(1)
print sizekB
EOF
`

All of my %pre and %post sections are written in perl so I decided to figure out what the python was doing. This is what I came up with.

sub getram {
        # ia32 boot kernel only sees up to about 1 gig of ram.
        # Have to did to find how much there really is in the machine.
        my $e820info = "/proc/e820info";
        if ( -f $e820info ) {
                open ( MEM, $e820info ) ||
                        die "Couldn't open $e820info\n";
                while ( <MEM> ) {
                        next unless /\(usable\)/;
                        $ram += int ( hex ((split /\s+/)[0]));
                }
        } else {
                open ( MEM, "/proc/meminfo" ) ||
                        die "Couldn't open /proc/meminfo\n";
                while ( <MEM> ) {
                        next unless /^Mem:/;
                        $ram = (split /\s+/)[1];
                        last;
                }
        }
        close ( MEM );
        $ram = int ( $ram / 1048576 );
}

Thanks!

Michael




[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux