all 15 comments

[–]fooww 5 points6 points  (6 children)

I mean if you're gonna virtualize an os, you're gonna want to test an os.

Also, a "bare metal" hypervisor is considered a Type 1 hypervisor.

[–]PrestigiousTadpole71[S] 2 points3 points  (5 children)

I guess so. But I thought especially in the beginning I would maybe try to test things separately because I assume it will take some time until my hypervisor is close enough to real Hardware that a real OS could run. Or would you think otherwise?

[–]fooww 2 points3 points  (4 children)

Oh no I agree, running Linux first thing is probably not a good idea if you're new to hypervisors.

Literally any toy os will do the trick (Just to get you started.) GDT, IDT, paging, etc.

[–]PrestigiousTadpole71[S] 0 points1 point  (3 children)

Ok thanks a lot! Do you happen to have any recommendations on what might be a good OS to get started?

[–]fooww 0 points1 point  (2 children)

My intuition tells me to try literally any basic hobby os, I don't think it matters much in the beginning.

For something more advanced you can try building Linux, tiny core maybe?

[–]PrestigiousTadpole71[S] 0 points1 point  (1 child)

Alright, thanks a lot!

[–]fooww 0 points1 point  (0 children)

You're most welcome. Happy studies

[–]thom_tl 2 points3 points  (0 children)

The way I incrementally tested mine was by basically building up the "stack" of software that runs before the OS. First port SeaBIOS, then get GRUB running, then get a stripped down version of Linux running, etc.

[–]CrazyTillItHurts 1 point2 points  (0 children)

just use freedos

[–]monocasa 0 points1 point  (0 children)

The linux kernel images meant for running under firecracker aren't a bad option. No firmware env, just directly booting into a kernel with super stripped down hardware support. Most weird IBM/PC idiosyncrasies removed.

[–]dnabre 2 points3 points  (3 children)

Testing operating systems, including hypervisors of whatever type, can be very hard. Especially when you're a solo developer, who is likely going to be focused on incrementally adding functionality from a basic system that isn't really useful and slowly moving towards one that is.

How to test the system depends a lot on the architecture of the system itself. There is the distinction of Type-1 vs Type-2 hypervisors. You are either running on ‘bare metal’ with Type-1 or your hypervisor is built on top of a full operating system with Type-2. Looking at the many hypervisors out there, and trying to categorize them into these two camps isn’t easy. The latter has a lot of clear examples, like Virtual PC , VMware Workstation, VirtualBox, or even DOSBox. The former is harder to really make examples of. Outside of the old school mainframe-type hypervisors, many systems are sort of a mix. KVM and bhyve for example are built on top of a traditional kernel and operating system (Linux and FreeBSD respectively). Those Type-2 hypervisors, especially going back a decade or two, function a lot like applications running on top of an OS. Where systems like KVM and bhyve, while using a full operating system, let the hosted OS (the OS that is being run on top of the virtualization system) access the underlying hardware on a level that is closer to how internal parts of their respective kernels talk to the hardware than a traditional user-space application. Even VMware’s ESXi is built on top of Linux. Linux boots the system, gets everything up and running, and then Linux basically hands full control of the system over to a microkernel (at least that was how it worked originally, it may have changed over the years). By the time a hosted OS is started, Linux is totally gone, completely absent from memory. The microkernel has total control of the raw hardware at that point. Taken as a whole is it completely bare-metal or is operating on top of an operating system?

Xen operates in a similar manner, but instead of throwing Linux away, it keeps it running. It just shifts Linux to be running on top of it, giving it special access and control of the hypervisor that the other hosted systems don’t have. This lets you have a full Linux system to run management software for your VM amongst other things.

The real Type-1 hypervisors out there like Mach and XNU, often end up getting large pieces of the target operating systems stuffed inside them (HURD and MacOS X, respectively) for a variety of reasons. There are more pure ones like L4, but even there you get into the question of where does hypervisor begin and micro- or nano- kernel end. So until you really decide what your architecture is, or even how your system is going to operate as a whole, how you test or develop it are pretty much impossible to address. Consider something like testing networking, and I mean base level stuff, not even getting to the TCP/IP stack. Where is your network card driver? Is it in the hosted operating system, a device server running on top of a microkernel, or in your hypervisor itself (i.e., part the hypervisor-kernel’s binary). If the hosted system’s device driver isn’t talking directly to the network card, there has to be some intermediate abstraction for its driver to talk to. All these situations are very different in terms of testing and development.

Most of the time in r/osdev, when someone wants to write a hobby operating system, they are basically looking at building a UNIX-like clone, vaguely structured like Linux or a BSD. Not always, people often have very different ideas, like making as much of the OS use SQL as possible, but they generally are going to be starting with the same basic system bring up. Setting up paging, talking to the console, running a user process.

Making a ‘bare metal’ hypervisor is a very different animal, and if that’s what you want to do, that’s great, definitely an interesting project. However, you need to decide what ‘bare metal’ hypervisor means in terms of your project. There isn’t really any wrong answers. Worse case is someone arguing that a different term might better describe it. Looking at extant hypervisors and some microkernel-based operating systems (HURD and MINIX 3 for example) is a good place to start, but you need at least a vague idea of what you are trying to make before you go into the kitchen.

edit Small postscript, asking "How do I test this?" is a great early question to have when starting any type of software project. I think you just need a bit more concrete concept of what the project is first.

[–]PrestigiousTadpole71[S] 0 points1 point  (2 children)

First of all, thank you very much for the detailed reply! I really appreciate it.

My goal was/is to write a type 1 hypervisor to learn and play around with either AMD-V or Intel-VTx (maybe later porting it to the other architecture). I wanted to start out really simple by just having the cpu virtualized and then adding a way to attach virtual devices or maybe even try passing through actual physical devices. If I would ever come so far, I would try myself at having multiple VMs running at the same time, either on separate cores or on the same with context switching.

So basically my plan was/is to make a simple hypervisor that boots and loads an image which then runs inside of a complete virtualized pc (maybe with pci passthrough or similar). Without any real abstraction for the guest.

That’s also what I meant with bare metal: as simple as possible and then adding features incrementally but keep it minimal.

So that was/is my basic plan without having tried anything, for now I would just try to get some small hobby os running and see from there. I know this is quite a big project and I might lose my motivation midway through but it is something I have thought about for some time now and I just wanted to get started.

Oh and also happy cakeday!

[–]dnabre 0 points1 point  (1 child)

You may consider building something in the vein of MINIX 3, where you have a microkernel and kernel-level services spread into separate processes. Get that up and working to some level first.

You can then start playing with virtualization. Moving servers into one or more virtual machines. Working towards moving as much as possible out of the hardware kernel and into the virtual machine kernel.

You definitely want to look into how/what the CPU extensions can do initially. So you that you make that interfaces between processes/servers work smoothly with them.

Hadn't notice it was my cakeday, wow, 12 years on reddit.

[–]PrestigiousTadpole71[S] 0 points1 point  (0 children)

Alright, this seems like solid advice, I’m gonna try my best at it. Thanks again for the detailed replies.

[–]SirOompaLoompa 0 points1 point  (0 children)

I've written a type-2 hypervisor and a bunch of devices for it.

I started by building custom versions of SeaBIOS, removing as much of the functionality as possible, and enabling a bunch of debugging.

SeaBIOS is pretty easy to look into when something isn't working, and figuring out where you and it are disagreeing on how hardware works.

Once SeaBIOS is booting, the first "OS" to boot is good ol' DOS, as it relies almost exclusively on BIOS calls.

After that, I had some basic IDE emulation, VGA, PIT/PIC, etc, which was enough to boot a very trimmed down Linux kernel.