Saturday, January 17, 2009

Bad Memory HowTo

Note:  This site is being deleted, this content will live on here:
http://bryanquigley.com/planet-ubuntu/bad-memory-howto

So.. Memtest tells you have bad ram! Here are your easy options:
  1. Buy new ram
  2. Turn off everything after the bad memory* (mem=###M option)
  3. Turn off just the memory around the bad memory* (memmap=#M$###M option)
*May require moving RAM around in the computer for best results.

Testing The Memory
Tool 1: Memtest
There is the classic Memtest which is on every Ubuntu LiveCD and most other Free operating system CDs. It tests memory and gives you back fun technical numbers and also what sectors are bad in the easier form of 797M or 84M. It's the easier number we want. So try to write down the range (if applicable) of bad results.

Tool 2: Memtester
Memtester (click here to install) is like memtest only it runs from a command line once Ubuntu has loaded. It can't test your whole ram so you should make sure that it would be testing the area that memtest has detected being bad.
You absolutely need to run it with sudo/root.

WARNING: Don' try to test your whole RAM, just say 100M over where the error is. Doing really close to your actual total ram will make your computer unresponsive (unless you are following this with nothing but a shell, then you might be fine).

Ex. Let's say you have 150M taken up by your OS, the badram is at 797M (from memtest) and you have 1024M total memory.

This command would work:

sudo memtester 750M
Option 1 - Buy New Ram

Simple. Easy. Safest. Might be cheap if your computer supports new ram. Wastes hardware that we could likely get to work. Some people say that once RAM starts to go, it will just keep getting worse, I personally don't believe them.
I will not be liable for you losing data by using bad RAM. Use YOUR own judgment.

Option 2 - Turn off everything after the bad memory (mem=###M option)
This is simple take the lowest number from memtest, subtract let's say 3 from it for a bit of safety. Then add it to your kernel command line for bootup.
Ex. So for bad memory at 797M we would add to the default kernel options:

mem=795M
Option 3 - Turn off just the memory around the bad memory (memmap=#M$###M option)WARNING: This is much less tested than Option 2. There may be bugs lurking about.
This isn't much more difficult. Instead of just stopping at 795M, we are going to stop at 795M but then only ignore the next 10M. If there are multiple places try to make a range that includes them both.

Ex. So for bad memory at 804M and 806M we could use:
memmap=10M$800M
But for this option I will fell better if you use memtester afterwards to make sure you actually got the right memory spot. (And maybe do it before too, too make sure you actually were testing the right spots in the test)

HowTo Kernel Default Options
Edit the file /boot/grub/menu.lst with sudo/root
(ex. sudo nano /boot/grub/menu.lst)\

Navigate to here
## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=f0906667-bcde-4b64-86bc-5a47320d5517 ro
Edit the line (DO NOT GET RID OF THE #):
# kopt=root=UUID=f0906667-bcde-4b64-86bc-5a47320d5517 ro (add mem stuff here)
Then run:
sudo update-grub

Then reboot.

Thanks for following my HowTo. Many happy PCs and memory modules saved from landfills.

13 comments:

LeDopore said...

Hey gQuig,

Thanks for the help! You have a well-written tutorial that's a beacon of hope for people with sick computers.

I have a quick question. When I try to work around my bad RAM, it looks like top still sees just as much RAM as before. Does that mean that my kernel isn't avoiding the bad ram?

My menu.lst file had the following line in it:

# kopt=root=UUID=a9f39ac2-c67f-418e-93ce-967bdda5e3a4 ro memmap=100M$1800M


and I did remember to sudo update-grub.

Thanks for your help!

LeDopore

gQuigs said...

@LeDopore: tell me more about your setup. Anything odd? It should definitely report a different amount.

Try looking at:
cat /proc/meminfo

When you are booting up, stop at grub, by pressing escape and try to edit the lines to see what is actually being used. Remove it and double check that it didn't change the amount of ram.

LeDopore said...

Thanks, gQuigs. I hadn't known about editing the boot options with grub.

I added the memmap=100M$1800M to grub right at boot and my memory available dropped by 100 megs, so I guess the trouble was that my grub wasn't listening to my /boot/grub/menu.lst file. I'll look into this; thanks a million for the help!

Cheers,

LeDopore

LeDopore said...

Here's the permanent fix:

I have Ubuntu 9.04 running, but I've upgraded a few times so there might be some funny cobwebs in my installation.

In any case, I found that adding memmap=100M$1800M under # defoptions (see below) propagates the memory reduction when you run update-grub, even though adding it earlier didn't.

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash memmap=100M$1800M

Thanks again for the help!

LeDopore

Bogdan C. said...

You can map multiple intervals of your ram. Lets say that you want to "ban"

20 MB from 550 to 570
and
35 MB from 800 to 835

You can write at the end of the line mentioned in the post above "memmap=..." multiple times. Like this:

# kopt=root=UUID=a9f39ac2-c67f-418e-93ce-967bdda5e3a4 ro memmap=20M$550M memmap=35M$800M

prh said...

thanks for this really helpful blog -
just a question: when, after adding this (multiple) memmap, I start from grub the windows2000 installation I also have on my hard disk, is then the bad memory also blocked for windows?

prh

Bogdan C. said...

Hm... i don't know if this has any effect on Windows.

But you can test this easily: just block, for example, 50 MB of ram. IF Windows shows you (yourAmountOfRam-50) MB then you are one lucky guy :P

Deftronic said...

hello

i'm trying to apply this tutorial but i got ubuntu 9.10 karmic (first installation)
so that i don't got this menu.lst file

i can find a /boot/grub/grub.cfg but there's no kopt=root ... in the while content

any help ?

the grub.cfg file content =>
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by /usr/sbin/grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s /boot/grub/grubenv ]; then
have_grubenv=true
load_env
fi
set default="0"
if [ ${prev_saved_entry} ]; then
saved_entry=${prev_saved_entry}
save_env saved_entry
prev_saved_entry=
save_env prev_saved_entry
fi
insmod ext2
set root=(hd0,6)
search --no-floppy --fs-uuid --set 0fac7a3d-ec9c-4cd2-899e-a78a899c973b
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=640x480
insmod gfxterm
insmod vbe
if terminal_output gfxterm ; then true ; else
# For backward compatibility with versions of terminal.mod that don't
# understand terminal_output
terminal gfxterm
fi
fi
if [ ${recordfail} = 1 ]; then
set timeout=-1
else
set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/white
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
menuentry "Ubuntu, Linux 2.6.31-16-generic" {
recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
set quiet=1
insmod ext2
set root=(hd0,1)
search --no-floppy --fs-uuid --set f017e4b3-7a62-48d7-a2fe-d3842503a7e3
linux /vmlinuz-2.6.31-16-generic root=UUID=0fac7a3d-ec9c-4cd2-899e-a78a899c973b ro quiet splash
initrd /initrd.img-2.6.31-16-generic
}
menuentry "Ubuntu, Linux 2.6.31-16-generic (recovery mode)" {
recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
insmod ext2
set root=(hd0,1)
search --no-floppy --fs-uuid --set f017e4b3-7a62-48d7-a2fe-d3842503a7e3
linux /vmlinuz-2.6.31-16-generic root=UUID=0fac7a3d-ec9c-4cd2-899e-a78a899c973b ro single
initrd /initrd.img-2.6.31-16-generic
}
menuentry "Ubuntu, Linux 2.6.31-14-generic" {
recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
set quiet=1
insmod ext2
set root=(hd0,1)
search --no-floppy --fs-uuid --set f017e4b3-7a62-48d7-a2fe-d3842503a7e3
linux /vmlinuz-2.6.31-14-generic root=UUID=0fac7a3d-ec9c-4cd2-899e-a78a899c973b ro quiet splash
initrd /initrd.img-2.6.31-14-generic
}
menuentry "Ubuntu, Linux 2.6.31-14-generic (recovery mode)" {
recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
insmod ext2
set root=(hd0,1)
search --no-floppy --fs-uuid --set f017e4b3-7a62-48d7-a2fe-d3842503a7e3
linux /vmlinuz-2.6.31-14-generic root=UUID=0fac7a3d-ec9c-4cd2-899e-a78a899c973b ro single
initrd /initrd.img-2.6.31-14-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
linux16 /memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
linux16 /memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
if [ ${timeout} != -1 ]; then
if keystatus; then
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
else
if sleep --interruptible 3 ; then
set timeout=0
fi
fi
fi
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

jordanwb said...

Thanks. I got a 1 Gigabyte stick with one bad address and I don't want to throw it out. I'll try this.

Bogdan C. said...

Deftronic ... i had this problem too.

Now (in Ubuntu 9.10) the boot loader is upgraded and the menu.lst file doesn't exist. Stop searching it.

The solution is... different now.

You have to edit the /etc/default/grub file (or grub.cfg; i don't know exactly... i don't have my computer with linux near me). Of course... you have to have admin rights, so edit this file with sudo.

Now... you will se something like this:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=false
GRUB_TIMEOUT="10"
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memmap=54M\\\$970M"
GRUB_CMDLINE_LINUX=""

save the file and run
sudo update-grub

Those backslashes are important so don't forget them. And 3 of those are now necessary, as you can see in the code posted above.
Of course, you can map, as before, more than one part of your memory. In this case the above line will look something like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memmap=14M\\\$170M memmap=54M\\\$340M memmap=34M\\\$670M"

Anyway... hope this helped you a little :)

Jose Luis Lopez said...

Thanks a lot for this info.

eTabuk said...

thank you,
in /etc/default/grub file
just
memmap=80M\\\$539M

fix my 2GB DDR3 .

eTabuk said...

in /etc/default/grub file
just memmap=80M\\\$539M fix my 2GB ddr3
thank you.