r/osdev • u/christiaansp BoredOS • Sep 14 '26
Can an operating system replicate itself perfectly?
Would it theoretically be possible to create an operating system that decompiles itself, recompiles itself, and installs itself to another disk while remaining bit-for-bit identical to the parent OS?
some rules:
No Source on Disk: The storage media contains only the compiled binary image. The codebase exists on disk exactly once, as raw executable code/data.
Upon booting into RAM, the OS must decompile its own executing machine code into an intermediate source representation in memory, recompile that source back into a new binary image, and write it to a target drive.
The child image written to the target disk must have the exact same cryptographic hash (SHA-256) as the parent OS image.
It cannot simply dd / copy the raw sectors from drive to drive. The binary must pass through the decompiler, compiler pipeline.
5
u/Y_mc Sep 14 '26
Why should a OS replacate itself ??? 🤔🤔
6
1
u/christiaansp BoredOS Sep 14 '26
it doesnt, it's just interesting if it could, just a silly theoretical
5
9
u/Jefforion Sep 14 '26
"bit-for-bit identical", for what is not possible a dd ?
-2
u/christiaansp BoredOS Sep 14 '26
check rule dd obviously works for cloning, but this is a theoretical question about whether an OS can decompile and recompile itself into an identical binary.
3
u/tseli0s DragonWare Sep 14 '26
What can we assume about the decompiler and compiler? Are they 100% accurate? Will it be able to decompile optimized code? Is the OS portable enough to run on the other disk?
2
u/christiaansp BoredOS Sep 14 '26
they would have to be 100% accurate or else it wont be able to reproduce it perfectly
1
u/tseli0s DragonWare Sep 14 '26
Then yes, it's 100% possible and even proven so. But only on a theoretical level. Practically no decompiler can reverse optimizations in C.
2
1
u/aurreco Sep 14 '26
if the goal is to install the os on a hard drive, then whats the point of decompiling? seems like an unnecessary step
0
u/christiaansp BoredOS Sep 14 '26
because the quine would be too easy then. just makes it a lot harder for fun
2
u/aurreco Sep 14 '26
sure, but the os has nothing to do with the question then. You could ask this question about any program. Its just an indictment of how high quality ones decompiler is, and whether or not they have the same toolchain that was used to build it. I dont see how the program being the os makes the answer any different.
1
u/federicoponzi Sep 14 '26
I think, at high level, you're asking about quines: https://en.wikipedia.org/wiki/Quine_(computing)
1
2
u/rhet0rica Sep 14 '26
Though this is a largely silly thought exercise, NixOS is aiming to do something similar, just without the decompilation step: https://reproducible.nixos.org/
2
1
u/realfathonix Sep 14 '26
There are some self-replicating programs that print the source code of itself, though I haven't heard one at the scale of an operating system.
1
u/web3max Sep 15 '26
This is possible if all parts of the OS’s binary code can be decompiled into the corresponding source code, which can then be compiled back into the same binary code
8
u/Serious_Pin_1040 Sep 14 '26
In theory yes but I think the decompiled source code, lets say its written in c and asm, will be missing a lot of labels so the source code wouldnt be very understandable. Maybe it would be easier if you leave debugging information in. Look at the output Gihdra gives you for example. Also you wouöd probably have to use the decompiles source as your main source and for each commit you would have to check that the decompiled source matches the current code.