Hot-adding memory to a Linux VM

Problem: When I hot-add memory to a linux VM, it doesn’t show up in the system when I type¬†free

This has likely been bashed to death and can be readily found on the internet if you search for it, but here’s one more for completeness.

In it’s simplest people just need to refer to the kernel documentation either in the kernel source Documentation/memory-hotadd.txt or online via YAGS (yet another google search)

Here’s a script to “online” any offline memory after you have added it.

if [ "$UID" -ne "0" ]; then
 echo -e "You must be root to run this script"
 exit 1
for MEMORY in /sys/devices/system/memory/memory*
  if grep -q online "${MEMORY}/state"; then
   echo -e "${MEMORY} is online"
   echo -en "${MEMORY} is offline, bringing online ..."
   echo online > "${MEMORY}/state"
   echo "OK"