os-tutorial icon indicating copy to clipboard operation
os-tutorial copied to clipboard

How To Run On A Real PC

Open circutrider21 opened this issue 4 years ago • 31 comments

I Have Gone through the whole tutorial, and now that i am complete, i want to boot the tutorial on my computer, but i don't know how. I have tried everything from using rufus, to using the windows disk-part utility. Please Help

circutrider21 avatar Mar 19 '20 15:03 circutrider21

try balenaEtcher. Also when you are done, tell me if it worked because I am trying to do the same thing and it won't work. However, I think it's just my computer. balenaEtcher

thecoder08 avatar Mar 20 '20 12:03 thecoder08

Why not just use dd? Safer and easier.

jlagarespo avatar Mar 20 '20 13:03 jlagarespo

@thecoder08 I tried balena etcher but it didn’t work.

As for the recommendation to use dd, I don’t know how to do that and wish you would further explain how to do that

circutrider21 avatar Mar 20 '20 23:03 circutrider21

the tools you are using are fine, you likely have CSM (for legacy BIOS with newer UEFI systems), the problem is because the code doesn't actually work on real hardware. For real hardware, you are probably better off starting with something like GRUB.

Menotdan avatar Mar 21 '20 04:03 Menotdan

@circutrider21 Let's say the image I want to burn is in my current working directory and is called disk.img. Also my flash drive is on /dev/sdb. Then it would be as simple as dd if=disk.img of=/dev/sdb bs=4M. ifis input file, of is output file, bs is block size, which in this case, because no huge amounts of data must be written, 4M is probably fine. You'll probably have to run this as root. And it should be as easy as that.

jlagarespo avatar Mar 22 '20 14:03 jlagarespo

Thanks for the help

circutrider21 avatar Mar 25 '20 20:03 circutrider21

If you have any old computer lying around there is a good chance it will work there.

jlagarespo avatar Mar 26 '20 12:03 jlagarespo

For me it is just a blinking cursor a few lines down from the top of the screen. I used dd command to just put the os-image.bin to a blank usb and then i have a laptop which has uefi on it and when i try to boot there is just a blinking cursor. Can someone help? (Sorry for the small amount of details. I need to write this quickly.)

personnumber3377 avatar Apr 19 '20 13:04 personnumber3377

If you use EFI it won't boot, you need your EFI to have legacy support or just a regular good old BIOS. As I said previously:

If you have any old computer lying around there is a good chance it will work there.

jlagarespo avatar Apr 19 '20 14:04 jlagarespo

I have csm enabled (forgot that very crucial detail), but still the same thing.

personnumber3377 avatar Apr 19 '20 17:04 personnumber3377

So there is no way to make this run on a real pc?

personnumber3377 avatar Apr 20 '20 08:04 personnumber3377

Try to translate the os-image to el-torito format before use dd: El-Torito

jorge-correia avatar Apr 20 '20 15:04 jorge-correia

I tried the commands from here: https://littleosbook.github.io/ at the section "building an iso image" on the os-image.bin with appropriate modifications (os-image instead of kernel.elf in the guide). Now when i type file it shows: "ISO 9660 CD-ROM filesystem data 'CDROM' (bootable)", but when i flash it onto the usb stick the os says "select proper boot device..." or something like that (cant copy and paste obviously), but after a bit of research, i found this : https://codedump.net/blog/extracting-a-bootable-disk-image-from-an-iso-image , but when i take a portion of the file and then flash that portion, the os still says the same thing. Any help?

Edit: And running file on the el torito formatted file says: "GRand Unified Bootloader stage2 version 3.2, identifier 0x0, GRUB version 0.95, configuration file /boot/grub/menu.lst"

personnumber3377 avatar Apr 21 '20 09:04 personnumber3377

Does your PC use EFI or BIOS? Are you using GRUB? Can you describe your hardware?

jorge-correia avatar Apr 21 '20 13:04 jorge-correia

I've had the same problem with this tutorial, with CSM on, the code is likely broken due to some bug that only affects certain machines, such as mine. Like I said above, I recommend GRUB2 or qloader2, which loads you into 64-bit mode and you can do more fun things there, you will need a different cross compiler though, so remember that.

Menotdan avatar Apr 21 '20 17:04 Menotdan

It can be a alternative, but it isn't a solve to this specific problem. I think we can do a little more research before change the approach.

jorge-correia avatar Apr 21 '20 18:04 jorge-correia

True

Menotdan avatar Apr 21 '20 18:04 Menotdan

For example, in the boot sector, the segment registers are never cleared.

Menotdan avatar Apr 21 '20 18:04 Menotdan

That should be done as soon as you get code execution, especially in real mode. Also, setting the stack pointer to 0x7b00 isn't a terrible idea for real mode afaik

Menotdan avatar Apr 21 '20 18:04 Menotdan

I think the problem is before that. I have been reading a few things and el-torito should be our solution. It defines three types of boot: hard disk emulation, floppy emulation and no emulation. I think we can try them all.

jorge-correia avatar Apr 22 '20 14:04 jorge-correia

Or we can write our boot_sector directly on a hard drive (if anyone has a spare HD).

jorge-correia avatar Apr 22 '20 14:04 jorge-correia

OK i decided to stop procrastinating and actually do something. So the laptop i am using is an ASUS laptop model number X551MA, it is quite old but but still pretty new. It has UEFI, but i have csm enabled. the laptop arch is x64 and the main os (windows 8) is also 64 bit. the computer has 4 gb of ram. as an usb i use kingston 64 gb usb stick. i doubt that this will help anyone because there is who knows how many laptops out there with slightly different io addresses etc.. Any help again?

Edit: Actually the laptop has windows 8.1 my bad

personnumber3377 avatar Apr 23 '20 07:04 personnumber3377

Found this gem: https://www.youtube.com/watch?v=1rnA6wpF0o4&list=PLHh55M_Kq4OApWScZyPl5HhgsTJS9MZ6M

personnumber3377 avatar Apr 23 '20 09:04 personnumber3377

I think the problem is before that. I have been reading a few things and el-torito should be our solution. It defines three types of boot: hard disk emulation, floppy emulation and no emulation. I think we can try them all.

uh just write a bootsector on a usb drive bruh it should boot fine with CSM, and proper code that actually works on systems that don't clear the segment registers.

Menotdan avatar Apr 25 '20 01:04 Menotdan

@personnumber3377 I have checked out this Playlist And found this tutorial that goes with the playlist I just mentioned. Together those 2 tutorials are better than this one. The best part is, that tutorial works on real hardware👍🎉

circutrider21 avatar Apr 28 '20 19:04 circutrider21

I've had the same problem with this tutorial, with CSM on, the code is likely broken due to some bug that only affects certain machines, such as mine. Like I said above, I recommend GRUB2 or qloader2, which loads you into 64-bit mode and you can do more fun things there, you will need a different cross compiler though, so remember that.

Does this mean it is not possible to modify this bootloader to run in 64 bit mode like with [BITS 64]

Matthiasclee avatar Jun 18 '20 12:06 Matthiasclee

I've had the same problem with this tutorial, with CSM on, the code is likely broken due to some bug that only affects certain machines, such as mine. Like I said above, I recommend GRUB2 or qloader2, which loads you into 64-bit mode and you can do more fun things there, you will need a different cross compiler though, so remember that.

Does this mean it is not possible to modify this bootloader to run in 64 bit mode like with [BITS 64]

64 bit long mode requires a lot of other important things to run properly, also [bits 64] just tells the assembler to create 64 bit instructions, it doesn't put CPU to 64 bit mode.

Menotdan avatar Nov 30 '21 19:11 Menotdan

@Menotdan I'm glad to see you still do osdev😄

circutrider21 avatar Dec 04 '21 21:12 circutrider21

If you have Linux just use dd to put on a drive and boot it on a compatible machine.

Ccode-lang avatar Dec 04 '21 22:12 Ccode-lang

@Menotdan I'm glad to see you still do osdev😄

I don't really work on my project anymore I'm just here because I like to help people with stuff

Menotdan avatar Dec 21 '21 00:12 Menotdan