1. Introduction

Typically if we want to know the number of RAM slots on our computer, we can open the case to look, or maybe we can search for the model specifications. But it’s much easier to take advantage of some useful Linux commands.

In this tutorial, we’re going to use dmidecode and lshw to retrieve the RAM configuration of our system.

2. Using dmidecode

First, let’s have a look at dmidecode, a command that queries the DMI table in our BIOS and displays it in a friendly format.

We need to execute this command as a superuser:

$ sudo dmidecode -t memory
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.1.1 present.

Handle 0x0049, DMI type 16, 23 bytes
Physical Memory Array
	...
	Number Of Devices: 2

Handle 0x004A, DMI type 17, 40 bytes
Memory Device
	Array Handle: 0x0049
	...
	Size: 8192 MB
	...
	Locator: DIMM A
	...

Handle 0x004B, DMI type 17, 40 bytes
Memory Device
	Array Handle: 0x0049
	...
	Size: No Module Installed
	...
	Locator: DIMM B
	...

In the property Number of Devices, we can see the total number of slots, and in the Memory Device sections, we see details about each slot.

In the above example, we see that the first slot has 8GB RAM while the second slot has no memory module installed.

Let’s suppose now that we want to print only the empty slots, and ignore all other information. We can pipe dmidecode to the grep command:

$ sudo dmidecode -t memory | grep "No Module Installed" -A 3
	Size: No Module Installed
	...
	Locator: DIMM B

The -A option will make grep add the three lines after the Size entry, enough to see what slot we’re talking about.

3. Using lshw

The lshw command queries the DMI table along with other sources, so it may display memory information in cases where dmidecode doesn’t. It can print its results in JSON, HTML, or XML formats.

As with dmidecode, we need to execute this command as a superuser:

$ sudo lshw -class memory
  ...
  *-memory
       ...
     *-bank:0
          description: SODIMM DDR4 Synchronous Unbuffered (Unregistered) 2400 MHz (0.4 ns)
          ...
          slot: DIMM A
          ...
     *-bank:1
          description: SODIMM DDR4 Synchronous [empty]
          ...
          slot: DIMM B
  ...

In the output above, we can see both slots, the first with a memory module and the second with nothing installed. When a slot is available, the description includes the message [empty].

Now, let’s imagine we want to print only the empty slots as we did with dmidecode. We can likewise pipe lshw to grep:

$ sudo lshw -class memory | grep empty -B 1
     *-bank:1
          description: SODIMM DDR4 Synchronous [empty]

In this case, we used grep with the -B argument to get the line before the description.

4. Conclusion

In this short article, we saw that dmidecode and lshw are handy tools to examine our hardware configuration.

When querying for memory, both commands show a similar output, allowing us to clearly identify slots that are being used or are available.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments