Does every OS need RAM?

76

15

Is there an OS which can be used without RAM, specifically the kind I can create a bootable pendrive from and use it in the computer? This gets awkward, since booting is essentially loading OS in RAM.

Note: I originally wanted to know about a RAM-less OS to check if my laptop (which does not boot but presents a blank screen) RAM had gone bad, but I like the way this question has snowballed.

Suvarna Pattayil

Posted 2014-08-31T08:12:08.780

Reputation: 1 072

23

I'm not sure if a CPU can even function at all without RAM, that may be a good question for Computer Science.SE. What I do know for sure is that you won't get anywhere if you don't even manage to get past the BIOS.

– None – 2014-08-31T08:18:19.037

Even for 'OSes' specifically designed to test ram, some ram is going to be used. There's generally some warning of bad ram in the bios, either through beepage or a error message. In addition to being a software req, which is off topic here, this is quite frankly impossible. – Journeyman Geek – 2014-08-31T10:02:27.270

Hardware the computer cannot operate without RAM. The CPU fetches it’s instructions and data from RAM so without it it cannot execute any normal instruction. – bolov – 2014-08-31T18:26:00.887

12@AndréDaniel a CPU has cache which, from a CS perspective, is also random access memory. So in theory you don't need additional RAM modules. But in practice I doubt that the x86 architecture allows this. – Philipp – 2014-08-31T18:41:52.443

30All these arguments about using the processor cache are of dubious validity, since, at least on x86, the cache is not a memory you can access directly. Your code always refers to RAM, but the processor automatically manages its caches so that it doesn't actually have to fetch the data in RAM for most frequently accessed data. But again, there's no assembly instruction to say "store this in cache" "write this in cache", there are registers and there is main memory (with all its weird accessing modes), period. – Matteo Italia – 2014-08-31T21:43:46.577

3(OTOH, in theory you could exploit other RAM (e.g. video RAM) or peripherals mapped in the physical address space) – Matteo Italia – 2014-08-31T21:50:22.883

13Modern x86 CPUs let you put the on-die cache in "Cache as RAM" mode - I think some MSR's need to be set to do that. This may apply for some ARM CPUs as well. Cache on modern CPUs is in greater quantity than what your first PCs could have as maximum memory. On a PC, the firmware still won't boot without RAM present, though. You'd need a custom firmware or something not a PC platform. – LawrenceC – 2014-09-01T00:08:15.150

2If you boot DOS on a modern CPU, the 640KB it needs will fit in cache. As a result, not a single cache line will be evicted to RAM. The bigger problem is the flawed assumption in the question that you need an OS to get to the BIOS. It's the other way around. – MSalters – 2014-09-01T08:18:23.900

@MSalters Does the BIOS need any RAM? or it can start even if the RAM is not functioning (assume extreme case, no RAM In slot)? – Suvarna Pattayil – 2014-09-01T09:11:08.793

1NO IT IS NOT POSSIBLE – user3459110 – 2014-09-02T18:50:37.893

1@AwalGarg It is possible. You may use memory that can only be accessed sequentially. This has in fact been a much older concept than Random Access Memory. The Turing Machine is based upon this. – SpaceTrucker – 2014-09-03T09:46:16.967

@AndréDaniel I doubt it would be all to welcome on CS since this question seems to be about electronics. – G. Bach – 2014-09-03T13:57:17.643

@G.Bach this question seems to be about theory, ie. can a CPU function without memory rather than how it would practically do that (on the electronic and physical level). – None – 2014-09-03T14:13:56.953

@AndréDaniel To me it seems one would be misconstruing the question if we interpret it like that; we could formalize that interpretation of the question as "is there a TM that uses O(0) space and runs an OS", and the trivial answer would be "no". Replacing O(0) by O(1) gives the - again trivial - answer of "yes". – G. Bach – 2014-09-03T14:16:09.600

@G.Bach fair enough, you seem to know way more about this subject than I do. – None – 2014-09-03T14:18:37.680

@AndréDaniel The original question was related to a laptop which I have and does not boot . The question was originally titled similar to "Is there a OS which doesnt not need RAM ?" . This was to be used for testing – Suvarna Pattayil – 2014-09-03T14:49:03.487

@VusP indeed, I was talking about the "can a CPU run without RAM?" being a good question for ComputerScience.SE, not this actual question from the author. – None – 2014-09-03T14:50:11.073

@AndréDaniel Yes that would be a good question :) – Suvarna Pattayil – 2014-09-03T14:52:33.700

2@MatteoItalia, not really. As ultrasawblade hinted at, modern CPUs in fact, do have to power on in a mode where they use the cache as ram, since they do not yet have access to ram. The bios first has to probe the ram and configure the memory controller before it can access the ram, and to do that, it makes use of the cache as temporary ram. Of course, it insists on completing this process before it will load an OS, and if it can't find any ram it will stop and emit a post beep code... 6 beeps iirc. – psusi – 2014-10-29T18:31:16.467

Cache-as-Ram (no fill mode) Executable Code – phuclv – 2018-08-01T01:28:04.200

Answers

95

Does every OS need RAM?
For IBM PC compatible hardware, a mandatory step of the BIOS POST process is to check if there is RAM to load the BIOS into. Optionally the POST process checks of your RAM functions correctly. After the POST process, the BIOS loads the bootloader to the RAM and gives control to the bootloader. So the answer to your question ("Does every OS need RAM?") is: yes, every IBM PC compatible hardware requires at least some functioning RAM to boot. This is true for any OS that runs on that hardware.

Note that in the OP's original question, there was a reference to a "laptop", which I interpreted as: IBM PC compatible hardware. For the remainder of this answer, I'll assume IBM PC compatible hardware.

Can an OS boot with faulty RAM?
If your RAM is faulty (and not entirely absent/broken) or if you can (partially) replace your RAM, you might be able to boot using the BadRAM of BadMEM kernel patches. It requires you to recompile the kernel (sounds easier than it is if you do it for the first time) and you can reboot and tell the kernel where your bad memory is. A nice explanation of the use of Memtest86/Memtest86+, BadRAM/BadMEM can be found here.

Can an OS boot without RAM and using the CPU's cache as RAM?
As far as I know there is no way to use your CPU's cache as RAM without any RAM present on your system (as is suggested by @philipp and other) in the comments. If there is, it would be nice to add it here. The only paper I could find on this subject is this paper that states: "Using processor’s cache as RAM until the RAM is initialized". Not sure if (and how) it will work without RAM. As far as I know there is no working code that boots an OS on a IBM compatible PC. Any references to proof-of-concepts, working code or anything is welcome in the comments and I'll add it to this answer.

Can I get to the BIOS?
The OP's question is a bit vague if the laptop is able to pass the BIOS POST. As @Tonny points out, no OS will help you to "get to the BIOS". You enter the BIOS using the F1 or F2 or F10 or DEL or ESC key, depending on your brand of BIOS.

How to recover data from the laptop without RAM?
As for the goal behind your question: why do you need access to your laptop? Probably because there is still data on the HDD that you want to recover? If that's the case, it is far more easy to pull out the HDD (see manual) and attach it to an external storage device or directly to a PC. Here is a nice guide to do just that.

agtoever

Posted 2014-08-31T08:12:08.780

Reputation: 5 490

3In practice it is possible to run a machine with somewhat defective RAM (say, there's just one bank which does not work correctly). If the BIOS doesn't notice (or, if it does notice, there may be the usual F1 override) you can still run an OS like Linux with the BadMEM/BadRAM patch, that instructs the kernel to avoid the specified memory blocks. – Matteo Italia – 2014-08-31T21:46:46.010

The OP's question was if an OS could be run without RAM. If there is RAM (or it could be replaced), then if course it would be possible. I'll add that. Your reference to BadMEM/BadRAM is relevant. I didn't know them. Thanks for pointing to them! I'll add that to the question too. – agtoever – 2014-09-01T05:18:52.737

Thanks @agtoever for your input. The data present in the laptop is trivial but I just wanted to check if the problem lies with the RAM or somewhere else. Will go through the links you suggested . Thanks again. – Suvarna Pattayil – 2014-09-01T09:14:09.950

5@VusP: to just check your RAM use a livecd/-usb with Memtest86/Memtest86+, skip the RAM testing in your BIOS and run the memtest from the livecd/-usb. – agtoever – 2014-09-01T09:16:31.200

4Who says testing RAM on boot is "mandatory"? It was common when machines had a few MB or less, but soon became optional as sizes grew and the time became prohibitive. – nobody – 2014-09-01T16:32:48.317

@AndrewMedico RAM became faster too, though. – o0'. – 2014-09-02T08:44:45.633

2@agtoever: Cache as RAM is definitely possible for CPUs, but I don't know what privileges the code needs to do it (not sure if ring 0 is enough). – user541686 – 2014-09-03T07:35:11.430

@Mehrdad: The only paper I could find on this subject is this paper that clearly states: "Using processor’s cache as RAM until the RAM is initialized" (which clearly requires working RAM). Furthermore, I don't know any working code that functions on a IBM compatible PC. Any references to proof-of-concepts, working code or anything is welcome.

– agtoever – 2014-09-03T07:57:25.350

3@agtoever: Huh? The cache-as-RAM trick doesn't suddenly stop working when RAM is initialized. It's just that at that point it's foolish to avoid the RAM, so no one ever tries to. But the trick has nothing to do with RAM being uninitialized; that's just when it's actually useful. – user541686 – 2014-09-03T08:04:42.580

I think there's a step missing between getting to BIOS/passing POST and recovering data. Namely, if OP's laptop can POST and goes into a blank screen before the typical OS loading screen, it's most likely a bad sector or corrupted file on the disk. I know running repair with Windows will work, but I don't know about other OSes in general. – Shaz – 2014-09-03T18:52:35.993

Eesssh now I want to tweak the memory manager on my hobbyist OS to use hardware pages for everything. – imallett – 2014-09-04T16:05:06.307

I am heard of firmware of a device that is executes the code directly from disk(for a booting process -- initializing periphery, etc). This isn't because it had no RAM, no, just it had few RAM and VERY SLOW. And in fact there wouldn't be big impact from executing the code from disk with comparison to RAM. Of course after booted it uses RAM as usual. So, is it possible to run OS without RAMyes, it is. It is also need to mention that a drive in fact could be compared with very slow RAM, so, in some sense, it is still uses it… – Hi-Angel – 2014-09-07T17:20:39.540

@Hi-Angel: sure, but that's surely no IBM-PC compatible pc... – agtoever – 2014-09-07T17:30:49.363

@agtoever, well, the question is Does every OS need RAM?, so this is the case ☺ – Hi-Angel – 2014-09-07T17:37:21.580

OP's question: "...and use it in the computer...". The context of the original question was clearly a laptop (and thus an IBM compatible PC). I agree that beyond that, there probably exist (custom) OS's that work without RAM. – agtoever – 2014-09-07T17:56:06.600

"So the answer to your question ("Does every OS need RAM?") is: no, not on this (IBM PC compatible) hardware" : Perhaps you wanted to say, "Yes, at least on IBM PC compatible..." ? – Abhitalks – 2014-09-08T05:57:09.543

@abhitalks that is entirely correct. I'll edit the answer. – agtoever – 2014-09-08T05:59:17.340

3@Hi-Angel, it can't execute directly from disk since the cpu can not directly access the contents of the disk. It has to poke commands into the disk controller and wait for it to transfer blocks of data from disk to somewhere in ram. Only from there can the cpu directly execute instructions. – psusi – 2014-10-29T18:39:57.827

33

It's possible in theory, but it would be very slow, since it'd need to use the disk for any temporary storage that didn't fit in the CPU caches. (CPUs have a few megabytes of cache because even RAM is too slow for them. Think about that.) So you'd need a rather small OS.

(Well, embedded systems-on-chip can execute code from either RAM or internal Flash memory – the PC BIOS could in theory do the same, but it can't run the whole OS.)

But, another thing is, the BIOS runs before and outside any installed operating system, and it's the BIOS that lets you boot from a pendrive or whatever. So if you cannot reach the BIOS, then no other OS in the world is going to help you.

user1686

Posted 2014-08-31T08:12:08.780

Reputation: 283 655

6It might be that a CPU can use its own cache instead of RAM. It could be a useful feature for those parts of BIOS code, which run before the memory test. But getting other hardware to work without RAM could be tricky. You wouldn't be able to do DMA, so disk I/O would have to be done differently. I guess the BIOS wouldn't even try to load an OS, if no usable RAM was found. The size of the cache is less of a problem though. A few MB may not be a lot by modern standards, but an OS from those days when one MB of RAM was a lot, should still work on modern computers. – kasperd – 2014-08-31T21:39:52.577

2

@kasperd The DEC Alpha was designed to run its very first stage of power-on initialization from cache, preloaded from a "serial ROM". This was because the CPU could not access RAM, conventional ROM, or any other memory-mapped resource (which included all I/O devices, IIRC) until page tables had been initialized.

– zwol – 2014-09-06T13:18:13.507

@grawity what about SSDs? – TechLife – 2015-05-03T16:34:18.127

@TechLife: Still slower than RAM by several orders than magnitude. Though, I guess, if you were to use it as RAM... it would just be called RAM, so still nope. – user1686 – 2015-05-04T05:56:12.730

15

You could, with some effort, design a system that contained no RAM. Load your software from ROM (or storage) and do everything in registers or on cache. Such a system would have exceptionally narrow use and given today's RAM prices be a bit pointless. An off-the-shelf laptop will not function without some onboard memory.

Your real question is more likely "How do I get information off of a computer that will not boot" and that's easy. Disassemble it, remove the drive, and connect it to an external drive case.

Note, however, that any computer old enough that you can't just get $20 worth of working RAM for it will have an ATA ( regular ATA, not SATA ) drive. This interface is nearly extinct today, so you will also need to find a drive case with an ATA card as well as a full-size to laptop-size adapter. I have one that I bought in 2000, and I keep a couple of old cases around just for this purpose.

peter

Posted 2014-08-31T08:12:08.780

Reputation: 251

Agreed. No RAM means no stack which means no ability to call a routine. Any code that could work in this situation would have to be carefully handcrafted assembly. – Loren Pechtel – 2014-09-01T16:24:17.597

True. I have seen code which did that though. (I was the first part of a BIOS routine before the memory controller was initialised). – Hennes – 2014-09-02T09:20:26.880

2@LorenPechtel That's not entirely true. The stack can be (and often is) stored in on-chip memory. – reirab – 2014-09-03T17:01:06.680

@reirab can you give some chip examples? – domen – 2014-09-04T10:15:36.603

2@LorenPechtel not necessary. ARM doesn't use stack to call a routine. – domen – 2014-09-04T10:16:23.543

@domen One of the ones I've used was the Analog Devices Blackfin family of DSPs (which also used the same architecture that Intel uses for some of its DSP chips.) It had a few different directly-addressable on-chip memories, but the 'scratchpad' memory was the one that was used by the RTOS that I was using to store the stacks. Of course, even on chips without directly-addressable on-chip memories, the stack of at least the active thread will usually be in cache. – reirab – 2014-09-04T14:02:44.843

1As far as I can see those chips have internal SRAM... which counts as RAM. – domen – 2014-09-04T14:18:32.673

While external cases with IDE interface are rare today, one can easily purchase an IDE+SATA PCI-based controller. – Ruslan – 2014-09-08T07:27:35.570

10

If I read the question correctly everybody here is barking up the wrong tree.

He states explicitly "in order to get to the BIOS".

If the laptop is so broken it won't even get into BIOS, everything else is pointless.

You can't boot ANY OS on this regardless of the RAM situation.

Tonny

Posted 2014-08-31T08:12:08.780

Reputation: 19 919

8

Your assumption that the memory is bad is likely invalid. If you get no beeps or on-screen messages, The root cause is almost certainly a failed CPU (somewhat unlikely) or a failed mainboard (very likely). Mainboards fail with age all the time due to cold solder joints, which were a common occurrence in the early days of the ROHS movement and the requirement to use lead-free solder. Manufacturing techniques had been optimized for using lead-based solder and the industry took a while to catch on and resolve the issues. Many component manufacturers weren't very willing to spend the money to upgrade their processes. After all, the devices would test and burn in just fine, only to fail months or years later, after any warranty had likely expired. Only with a growing mountain of failures and intense negative feedback from users did the manufacturers begin to improve things. On such a laptop, having the mainboard re-flowed to rectify the cold solder joints is almost certainly cost prohibitive.

sewalk

Posted 2014-08-31T08:12:08.780

Reputation: 81

That's possible, but bad memory is not a bad guess, either. I've seen bad memory (and even bad memory sockets) cause a failure to POST multiple times before. Of course, the easiest check for memory is usually just to try booting with different sticks removed or booting with only one known good stick. If that resolves the problems, it was either the memory, the memory slots, or the memory controller. – reirab – 2014-09-03T17:44:13.617

5

Most of early computers of the 1980's or about had kind of operating system (hardware drivers, IO support, program loading, very simple command line interface, etc) in the ROM chip. It could somewhat function even while RAM chips were inoperable. This feature was used in special ROM content versions designed for running hardware tests and communicate mostly through the beeper and keyboard lights.

CPU has several registers to remember the address of the command being executed at least, but these are not normally called RAM.

Regular C code cannot run in a system without RAM as it uses stack memory to allocate variables, and stack is in RAM. When a recent computer boots, a regular dynamic RAM is initially not available as RAM refreshing device needs initial setup to work. Assembly code runs first and performs the motherboard initialization. RAM starts to work and then C code can run.

h22

Posted 2014-08-31T08:12:08.780

Reputation: 444

4The last paragraph is not entirely true. The stack does not have to be in off-chip RAM. It is actually quite common for the stack to be located in on-chip memory. Even on normal machines, the stack of the currently-executing thread will usually be in cache and will only get pushed out to DRAM when the scheduler swaps threads. I've written code for DSPs, though, where the stack resided in directly-addressable on-chip memory and never touched the DRAM. Of course, I guess you could argue that the on-chip memory is technically RAM in this case. – reirab – 2014-09-03T17:48:16.990

4Also, it's not unusual for at least some of the parameters and return values to be passed to C functions using registers (rather than the stack.) Furthermore, local variables are also commonly stored in registers rather than on the stack by C compilers. You can even specifically request that the compiler put a particular variable in a register using the 'register' keyword. Of course, once a function needs more local variables than you have register space for, you will need to go out to memory, but that's a hardware constraint that applies regardless of programming language. – reirab – 2014-09-03T17:50:39.673

4

When I went to University in 1967 the Computing Department had a Stantec Zebra. The memory consisted of a 8192 word magnetic drum. There were also 12 registers and two accumulators. You might consider that RAM but not as we know it.

David Marshall

Posted 2014-08-31T08:12:08.780

Reputation: 6 698

3

You would need at least on chip cache for registers (essentially a very small amount of on-chip RAM) so that the CPU execution unit could function. So even your CPU has 'RAM'.

No Von-Neumann OS has been designed without the requirement of memory I believe.

So no.

Hi Lo

Posted 2014-08-31T08:12:08.780

Reputation: 435

3

As per all other people here, I do agree on the fact you DO need RAM and cannot work without it, but I also read the following :

(I originally wanted to load a RAM-less OS to check if the RAM had gone bad, but I like the way this question has snowballed.)

This does actually exist in the BIOS, there is a function to check the RAM in depth. When booting and going inside the BIOS, change the option "Quick Power-on self test" to off, and it shall do a complete check pass on your RAM. This option should be located in "advanced BIOS features", something like second choice on AMI BIOSes.

Hope that will put you one step further. ;-)

Olivier M.

Posted 2014-08-31T08:12:08.780

Reputation: 71

3

You don't need RAM e.g, use a Turing machine.

A Turing machine is a hypothetical device that manipulates symbols on a strip of tape according to a table of rules. Despite its simplicity, a Turing machine can be adapted to simulate the logic of any computer algorithm, and is particularly useful in explaining the functions of a CPU inside a computer.

(I would not consider a tape to be RAM.)

Now your real questions should be asking about “useful” and define what you mean by “useful”.

Ian Ringrose

Posted 2014-08-31T08:12:08.780

Reputation: 1 262

3At the conceptual level of a Turing Machine, all types of read-write data storage are essentially equivalent: RAM, registers, cache, magnetic tape, disk. The only difference between them is speed of access. – Barmar – 2014-09-05T18:52:13.733

1@Barmar RAM means Random Access Memory. That means you can access the cells within it in any order. The cells on a tape on a Turing machine can only be accessed sequentially (in either direction or alternating). So I'd say the tape on a Turing machine is by definition not RAM. – kasperd – 2014-09-06T10:11:07.417

@kasperd Since you can move the tape in either direction, and repeat that action as many times as necessary, it's effectively random access. The tape in a TM is an abstraction for any form of storage. – Barmar – 2014-09-06T22:44:43.790

1@Barmar That is incorrect. The definition of RAM does not allow for seek times. Hence the tape of a TM simply does not fit the definition of RAM, because you cannot access arbitrary cells without seeking. – kasperd – 2014-09-06T23:45:02.337

A TM is totally imaginary, it's just an abstraction used to define computing in general. The notion of time doesn't apply. – Barmar – 2014-09-06T23:53:41.857

1@Barmar, the notion of wall clock time may not apply, but the notion of time, as in it requires O(n) read operations to get there, certainly does. – psusi – 2014-10-29T18:47:08.470

@psusi But you need physical objects to determine that some operations take more time than others. E.g. you could postulate that moving the tape is a million times faster than reading an element from the current tape position, so seek times are negligible compared to number of reads. – Barmar – 2014-10-29T18:51:45.207

1@Barmar, no, you don't. That is why we use big "O" notation to talk about purely mathematical complexity that is unrelated to how much "time" something real might take. The mathematical model of a tape drive in this TM is such that it can only read... in either direction... not zoom forward or backward, in any amount of time. Therefor, if you last read byte 1, you can not read byte 27 without first reading the 26 bytes in between. That is why it is not ram. If you want memory that can skip those 26 bytes, whether doing so takes 0 time or 5 minutes, that would be ram, not a tape. – psusi – 2014-10-29T18:56:24.007

3

There are specialized OSes for embedded use that run entirely out of a ROM (read only memory.) To do anything useful, though, you still usually need at least a small amount of RAM. I have not seen a PC that will boot without RAM though.

As for the original question about a memory test, if the computer will POST (i.e. make it past the Power On Self-Test and attempt to boot) then Memtest86 is designed specifically to test your RAM. It tests the first 64KB of RAM, loads itself into that RAM, then test the rest of your system memory as thoroughly as you'd like. "Flakey" memory (as opposed to just plain bad memory) is uncommon, but I have seen Memtest86 catch a intermittently bad bit that the computer's memory test missed (after all, the POST memory test is meant to complete in a reasonable length of time, while memtest86's fastest test runs 5-10 minutes, with more comprehensive tests taking hours.)

user153822

Posted 2014-08-31T08:12:08.780

Reputation: 61

1

Yes, you can have a computer without RAM. There is a special mode in most x86 processors that allows to run it with cache only. If you check for coreboot (former linuxbios), it can do that. Its called cache-as-ram. Actually you can do a whole operating system based on this, and with the modern big-sized caches it could end up even having a gui (check menuet-os). But none done so yet.

Jorge Aldo

Posted 2014-08-31T08:12:08.780

Reputation: 164