cfenollosa / os-tutorial

How to create an OS from scratch
BSD 3-Clause "New" or "Revised" License
27.03k stars 3.28k forks source link

Building in Docker container? #42

Open vsoch opened 6 years ago

vsoch commented 6 years ago

I'm at this step: https://github.com/cfenollosa/os-tutorial/tree/master/13-kernel-barebones

And I'm building in a Docker container, and I continually see the error that it cannot find the hard disk, but then is using floppy? I haven't a clue how to debug or investigate this - would there be a difference doing this in a container than locally? Please help.

Ghifari160 commented 6 years ago

I haven't tested using Docker, but it should be the same. I'm assuming that you see the error from qemu? What exactly is the command that you used with qemu?

vsoch commented 6 years ago

Thank you so much for trying to help! First, I need to use -curses because without, there isn't a video device:

root@b2053c241ecb:/rootfs/boot# qemu-system-i386 /rootfs/boot/os-image.bin        
WARNING: Image format was not specified for '/rootfs/boot/os-image.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
Could not initialize SDL(No available video device) - exiting

So we add -curses! And the result is here:

image

This seems to work to load from disk, but there is some (unknown) error, and I don't have the skillset developed to debug what that means, specifically this part:

Disk read error
0x0C80

Maybe this is the issue and a good starting point to debug? As was suggested here I decided to add -fda: to the command:

qemu-system-i386 -fda /rootfs/boot/os-image.bin -curses

I get

image

I get an error that it cannot read the disk, but on the other hand I see an "X" in the top left... so maybe this is working? I'm not really sure what is going on, because the result in each case doesn't match what the post is saying it should, this:

"Started in 16-bit Real Mode"
"Loading kernel into memory"
(Top left) "Landed in 32-bit Protected Mode"
(Top left, overwriting previous message) "X"
Ghifari160 commented 6 years ago

The error message that you see when you used -fda is normal. The -fda adds a floppy disk to qemu and not a hard disk. The BIOS, however, will still attempt to boot from the hard disk first. qemu knows that there is no hard drive attached, the BIOS doesn't, hence the "could not read the boot disk" message. I'm not quite sure why supplying the image as a disk to qemu gives you an error code of 0C80. I suggest you continue using floppy for now. If you want to investigate further, try using creating a raw disk image with your kernel inside of it (I'm not sure how to do this so you might have to do your own research)

AlanFoster commented 4 years ago

Hey; I had luck running my OS in docker with:

qemu-system-i386 -blockdev driver=file,node-name=f0,filename=$< -device floppy,drive=f0 -curses

Steps + GIFs attached:

https://github.com/AlanFoster/os_concepts/tree/d1c34e5009f459b57afa25df06535251c2bbaa09#using-docker