Page 1 of 2

Kernel loading problem

Posted: Tue Jul 03, 2018 10:13 am
by Sipige
Hello, I am on LINUX and I trying to make an little operating system using NASM and QEMU with a FAT12 filesystem but it doesn't work.
I have take the source code from a tutorial that you can download here : http://www.brokenthorn.com/Resources/Demos/Demo1.zip.

I make this :

Code: Select all

sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ cd Stage1
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage1$ nasm -f bin Boot1.asm -o Boot1.bin
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage1$ cd ../Stage2
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage2$ nasm -f bin Stage2.asm -o KRNLDR.SYS
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage2$ cd ..
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ cat Stage1/Boot1.bin Stage2/KRNLDR.SYS /dev/zero | dd of=floppyA bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,00695998 s, 212 MB/s
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ qemu-system-i386 -boot a -fda floppyA
WARNING: Image format was not specified for 'floppyA' 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.
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ 
And I have :

Code: Select all

ERROR : Press Any Key to Reboot
I do not know what to do.
Thanks

Re: Kernel loading problem

Posted: Tue Jul 03, 2018 11:47 am
by neon
Hello,

You shouldn't be concatenating those two files. Reformat the disk, then install stage 1, then mount the disk and copy stage2.bin to the root directory. Please reference the OSDev wiki here for creating and mounting disk images with Linux.

Re: Kernel loading problem

Posted: Tue Jul 03, 2018 11:55 am
by Sipige
Thank you. I will test this tomorrow.

Re: Kernel loading problem

Posted: Wed Jul 04, 2018 2:35 am
by Sipige
Ok but I have a problem with losetup :

Code: Select all

root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,0247006 s, 59,7 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# losetup /dev/loop0 floppy.img
losetup: floppy.img : échec de configuration du périphérique boucle: Périphérique ou ressource occupé
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# 

Re: Kernel loading problem

Posted: Wed Jul 04, 2018 4:57 am
by Velko
échec de configuration du périphérique boucle: Périphérique ou ressource occupé
It complains that /dev/loop0 is already in use.

To see the details, run

Code: Select all

losetup -l
If you know what that loopback device is used for (you did set it up earlier), can detach it by running

Code: Select all

losetup -d /dev/loop0
You can use another loopback device as well. My Linux distro has /dev/loop0, /dev/loop1, ..., /dev/loop7 and there's probably a way to add more.

Re: Kernel loading problem

Posted: Wed Jul 04, 2018 7:02 am
by Sipige
Ok thanks.

I have this :

Code: Select all

root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,0243512 s, 60,6 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# losetup /dev/loop16 floppy.img
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# mkdosfs -F 12 /dev/loop16
mkfs.fat 4.1 (2017-01-24)
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# 
But now I don't know to install stage1 and how to copy stage2.

Re: Kernel loading problem

Posted: Wed Jul 04, 2018 11:42 am
by neon
Hello,

For installing the boot record (stage1) -- This can be done using third party software (i.e. PartCopy or a hex editor like Cygnus or HxD) or writing your own program to do it. We recommend just writing a utility since it can be extended in the future -- for now though all it needs to do is a simple fread/fwrite to read stage1.bin and overwrite the first 512 bytes of the disk image with it.

For copying the boot loader (stage2) -- You need to mount the disk image to some device so you can open it and access its contents. Copy stage2.bin to the root directory of the disk image.

Re: Kernel loading problem

Posted: Thu Jul 05, 2018 4:20 am
by FusT
Did you actually try to search the wiki?
Just about everything you're asking is outlined in the Bare Bones article.
If you're not using Grub to boot the OS, there are resources for that too.

This might come across as hostile, but please search the wiki before posting a question.

Re: Kernel loading problem

Posted: Thu Jul 05, 2018 4:48 am
by Sipige
Fust I have search but I don't want to use grub and all is in english.

Code: Select all

root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage1# nasm -f bin Boot1.asm -o bootloader.bin
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage1# cd ../Stage2
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage2# nasm -f bin Stage2.asm -o KRNLDR.SYS
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage2# cd ..
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,00841148 s, 175 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# losetup /dev/loop15 floppy.img
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mkdosfs -F 12 /dev/loop15
mkfs.fat 4.1 (2017-01-24)
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# chmod a+w floppy.img
Then I use wxHexEditor for replace the beginning of floppy.img by bootloader.bin.
Now I must copy KRNLDR.SYS to /dev/loop15 but I am new on Linux and I don't know ho to do.
Thank you

EDIT : Ah ok. Just had to do cd / mnt!
So I make this :

Code: Select all

root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mount /dev/loop15 /mnt -t msdos -o "fat=12"
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mv Stage2/KRNLDR.SYS /mnt
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# qemu-system-i386 floppy.img
But the boot failed.
I don't know why but it is not in capital letters.

Code: Select all

root@Sipige-GE62VR-6RF:/mnt# dir
krnldr.sys

Re: Kernel loading problem

Posted: Thu Jul 05, 2018 10:04 am
by neon
Hello,

You should be unmounting it before using floppy.img (or just boot directly from /mnt.) Also, case sensitivity (upper/lower case) doesn't matter since we are using the 8.3 short file name to find it. i.e. "krnldr" and "KRNLDR" are two names for the same file.

Re: Kernel loading problem

Posted: Thu Jul 05, 2018 10:16 am
by Sipige
THANK YOU !!!
Thank you very much !
Since the time I was stuck on it I began to believe that it would never work!

Re: Kernel loading problem

Posted: Fri Jul 06, 2018 1:03 am
by FusT
Sipige wrote:and all is in english.
You'll find that the vast majority of OSdev resources are in English, which can make it a bit difficult if your English isn't very good.
This forum, wiki and most of the hardware manuals are in English. I'd argue that, besides knowing ASM/C/C++/whatever you write your OS in, English is a required skill to start OSdeving (though I have come across some French OSdev-related websites and forums too).

Again, this might come across a bit harsh but a lot of the things you're asking can be found through the wiki, forums or Google search with little to no effort and most of it isn't very OSdev-related, it's basic Linux usage.

Also, starting something as hard as OSdev on a platform that is completely new to you is probably not the best choice.
Stick with what you know (Windows I suppose, lots of great tools and resources out there for OSdev), take your first steps in the world of OSdev and become familiar with it.
It's good to want to learn how to use a new system (or programming language, for that matter), but don't combine it with trying to learn how to develop an OS, it'll be too much.

Of course, this is just my take on things, others might disagree.

Re: Kernel loading problem

Posted: Fri Jul 06, 2018 2:15 am
by Sipige
Yes but reading a language is the best way to learn it.
I can read english well but I need time so I prefer french.

Re: Kernel loading problem

Posted: Fri Jul 06, 2018 9:24 am
by dseller
I also suppose that if qemu could not open the image, it would have said something along the lines of "Could not open file" in its log file/output window.

If you got stuck on this part, it might be best to take a step back and get used to Linux first.

Re: Kernel loading problem

Posted: Fri Jul 06, 2018 9:25 am
by Sipige
No it is solved.