# How an Operating System work?



## hack3rcon (Oct 22, 2020)

Hello,
I want to learn how an Operating System work and I guess BSD is clear and simpler than other OSes like GNU/Linux and Windows OS. I want to change some parts of source codes and recompile them and see the result in the OS. Which version of BSD is simpler for my goal?

Thank you.


----------



## forquare (Oct 22, 2020)

I'm not sure about which BSD is simpler, but I know that there is a book written to describe the design and implementation of FreeBSD: *The Design and Implementation of the FreeBSD® Operating System, Second Edition*.


----------



## mark_j (Oct 22, 2020)

hack3rcon said:


> Hello,
> I want to learn how an Operating System work and I guess BSD is clear and simpler than other OSes like GNU/Linux and Windows OS. I want to change some parts of source codes and recompile them and see the result in the OS. Which version of BSD is simpler for my goal?
> 
> Thank you.


Really? How long's a piece of string? What you ask is so vague it's unanswerable without guessing.

What part of the OS? User/kernel/all? If it's the kernel then go read these:

Operating system concepts - silberschatz & galvin
Modern Operating Systems - tanenbaum.

Then download minix - it's got a netbsd userland and microkernel. That's much easier to work with and understand than vast monolithic kernels as used by *bsd & linux. 
Note: This is not an argument against *bsd, it's just fact that microkernels are easier to dissect because nearly everything that makes the OS run is in userspace not the kernel. YMMV.


----------



## olli@ (Oct 22, 2020)

What mark_j says. Minix is good for learning certain aspects of OS design.

I’d like to add that the BSD systems are far away from what I would call “simple”. But if you’re still curious to have a look at a BSD system, one option is to get the stuff from ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/1.0-RELEASE (this is actually 1.0.2) and dissect it. You can install it in a VM (my recommendation is to use QEMU because it can emulate an NE2000 ISA network interface which is supported by FreeBSD 1.0). Of course it’s a historic release from 1993, so you won’t find all modern state-of-the-art things in there. But for curiosity and educational purposes it might be useful.  For example, the kernel sources are just 7.5 MB, compared to more than 400 MB for a recent version of FreeBSD.


----------



## ekvz (Oct 22, 2020)

hack3rcon said:


> Hello,
> I want to learn how an Operating System work and I guess BSD is clear and simpler than other OSes like GNU/Linux and Windows OS. I want to change some parts of source codes and recompile them and see the result in the OS. Which version of BSD is simpler for my goal?
> 
> Thank you.



There is way to many unknown variables here to give you areal answer. In a general sense i'd agree about it being easier to get an overview of all the nuts and bolts with BSD systems (but then you also list Windows for comparison so i am not sure how much actual research went into this statement). Which one is best for you? I guess it would be most appropriate if you were the judge of that. There isn't _that_ many relevant BSD systems so just grab the sources and see which one makes the most sense to you after spending like an evening playing with it. As long as your C skills are somewhat solid and you have a bit of basic experience with programming for unix-like systems you shouldn't run into any major problem with any of these.


----------



## hack3rcon (Oct 22, 2020)

Thank you so much for all of your answers. I want to download ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/1.0-RELEASE/ or https://9p.io/sources/plan9/sys/src/ but after download of these codes then how can I compile and boot the OS and see the result?
Consider a developer that want to add some features to current version of BSD or examine it. How he\she could see the result of his\her works after changed some parts of a code? He\She must save the source code changes but how about to compile and make .iso file for boot the OS and see the result?


----------



## kpedersen (Oct 22, 2020)

For me simplicity also comes from how easy it is to compile and test code changes quickly and allowing me to tinker with internals.

From my experience, 9front (Plan 9) is possibly the quickest to get started with, followed by OpenBSD and then FreeBSD. That said, FreeBSD has the best documentation so I tend to go with that.

Minix and some of the very old UNIXes can be a little awkward to jump in to.
Linux can be OK. Pretty heavy in some ways, all the kernel config stuff actually gets in my way a little.


----------



## ralphbsz (Oct 22, 2020)

You are not going to learn how an OS works by downloading, compiling, and using it. You are going to learn how it works by reading about the reasons for things to be designed the way they are. I would start with the books Mark_j recommended above.


----------



## Jose (Oct 22, 2020)

The easiest way to make some kernel changes and examine the results is probably to write a "Hello world" driver for Linux. There are walkthroughs all over the Web. Here's one of the first ones I found:








						How to write a linux device driver
					

A beautiful guide for the Hello World of the device driver programming




					medium.com
				




Here's the Freebsd version. It will require more reading:








						Chapter 9. Writing FreeBSD Device Drivers
					

Writing FreeBSD Device Drivers




					www.freebsd.org


----------



## hack3rcon (Oct 22, 2020)

Thank you so much for all replies.
I want to download and compile FreeBSD version 1 from ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/1.0-RELEASE. Which steps I must do?


----------



## ekvz (Oct 22, 2020)

hack3rcon said:


> Which steps I must do?



To archive what?


----------



## hack3rcon (Oct 22, 2020)

ekvz said:


> To archive what?


I downloaded the all the files in that URL and wanting to compile and make that OS. How can I do it?


----------



## drhowarddrfine (Oct 22, 2020)

hack3rcon Have you looked at The Developer's Handbook?


----------



## mark_j (Oct 22, 2020)

hack3rcon said:


> Thank you so much for all replies.
> I want to download and compile FreeBSD version 1 from ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/1.0-RELEASE. Which steps I must do?


What platform are you using now? You would find it hard to locate hardware that suits 1.0-R. Your best bet is a virtual system, but I suspect even that would be a tricky manoeuvre.
Unless you have the hardware to match the software it's a chicken and egg situation if you want to compile it.
I would guess your ONLY option is to install FreeBSD 1 on a virtual machine and then muck around in /src/sys.


----------



## ekvz (Oct 22, 2020)

hack3rcon said:


> I downloaded the all the files in that URL and wanting to compile and make that OS. How can I do it?



I don't have the slightest clue. There is probably some instructions on how to build a modified kernel and/or world bundled with the source distribution. Just poke around a bit. Also there is an install.txt in /floppies that seems quite extensive. You might want to read that.

Word of advise: People around here tend to be extremely helpful if you have _specific_ questions but they won't go and solve your problems. If your idea of learning how operating systems work is to download something and hit a "Build + Install" button you won't get far.


----------



## a6h (Oct 23, 2020)

hack3rcon How much are you familiar with computer and programming and why you want to learn OS internals?


----------



## ralphbsz (Oct 23, 2020)

hack3rcon said:


> I downloaded the all the files in that URL and wanting to compile and make that OS. How can I do it?


What do you expect to learn from compiling an existing OS? You will not learn how it works, or how to write one. Before you can learn that, you need to get pretty darn good at programming, and computer architecture. I took an OS class about 40 years ago. The first semester was about computer architecture (Burroughs 5000, PDP-11, IBM 360, CDC 6600), instruction sets, and assembly programming. We learned things like implementing semaphores and mutexes in IBM 360 assembly language, and doing IO using the PP on the CDC. Clearly, that is for hardware that is not relevant any longer. If you really want to learn about how an OS works, start by understanding how to program an x86 processor, how memory and IO works. Then start reading the source code.
I think FreeBSD 1.0 is significantly too complex as a starter project (as is Linux 0.99-13, which is roughly from the same period); I would read the source code to Minix to begin with, along with the book by Tanenbaum.

If you can't even figure out how to compile the sources, you are not making good progress.


----------



## hack3rcon (Oct 23, 2020)

drhowarddrfine said:


> hack3rcon Have you looked at The Developer's Handbook?


Is it about building OS?


----------



## hack3rcon (Oct 23, 2020)

mark_j said:


> What platform are you using now? You would find it hard to locate hardware that suits 1.0-R. Your best bet is a virtual system, but I suspect even that would be a tricky manoeuvre.
> Unless you have the hardware to match the software it's a chicken and egg situation if you want to compile it.
> I would guess your ONLY option is to install FreeBSD 1 on a virtual machine and then muck around in /src/sys.


I know that I need an old PC. I want to use Xen or VirtualBox for it, but can I compile this version of FreeBSD using a moden Linux Distro?


----------



## ekvz (Oct 23, 2020)

hack3rcon said:


> I want to use Xen or VirtualBox for it



Well, then i guess you should try it? I think the recommendation was to use Qemu but if those also support the mentioned hardware (you checked this, have you?) it shouldn't really make a difference.



hack3rcon said:


> but can I compile this version of FreeBSD using a moden Linux Distro?



Look, i hate to be _that_ grumpy guy but what is it with these questions? Did you do any research at all (or even just read this thread...)? Anyways i'll answer your question if you can explain to me why you think going straight for a crossbuild is a good idea.


----------



## a6h (Oct 23, 2020)

vigole said:


> @hack3rcon How much are you familiar with computer and programming and why you want to learn OS internals?






drhowarddrfine said:


> @hack3rcon Have you looked at The Developer's Handbook?






hack3rcon said:


> Is it about building OS?



EOT


----------



## hruodr (Oct 23, 2020)

Perhaps you can begin reading this:



			https://www.bell-labs.com/usr/dmr/www/cacm.pdf


----------



## drhowarddrfine (Oct 23, 2020)

hack3rcon said:


> Is it about building OS?


Gee. I don't know. How would we ever find out?


----------



## olli@ (Oct 25, 2020)

hack3rcon said:


> Thank you so much for all replies.
> I want to download and compile FreeBSD version 1 from ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/1.0-RELEASE. Which steps I must do?


First you have to install it. Then you can boot it and compile it with itself. You _cannot_ compile FreeBSD under Linux or anything else.

Your best bet is probably to install it inside a VM, because it won’t run on current physical hardware. My recommendation is to use QEMU because it can emulate an NE2000 network card, which is supported by FreeBSD 1.

So, the steps are:
1. Install QEMU.
2. Create a QEMU VM with an emulated NE2000 network card. A single-core CPU and 16 MB RAM (_not_ GB!) should be sufficient.
3. Boot the VM with the installation media of FreeBSD 1, then install FreeBSD, including source code. The files that you downloaded contain documentation about how to do that (“readme” files etc.).
4. Once FreeBSD is installed, boot it and learn how to use it. Configure the network etc. Read the documentation, read the manual pages.
5. Try to compile the system. The sources are installed in /usr/src. There should be instructions, too (at the very least, there should be extensive comments at the beginning of the Makefile).

Good luck.


----------



## T-Daemon (Oct 26, 2020)

olli@ said:


> You _cannot_ compile FreeBSD under Linux or anything else.


I read somewhere it's possible, but couldn't remember where, vermaden's Valuable News 2020/10/26 reminded me where it was:



			FreeBSD Quarterly Status Report
		


```
...
As of September 2020 it should be possible to use the buildworld and buildkernel make targets
to build afully-functional FreeBSD installation on macOS and Linux hosts.
...
```


----------

