Page 1 of 1
Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 6:44 am
by Sourcer
I'm writing a POSIX-OS, After i wrote my ATA Driver, i'm headed into writing a ext2 fs.
But i can't understand some things:
1) If i have more than one ATA drives.(i.e. more than 1 is connected into the IDE.. ATAPI, SATA, etc..) which one do i choose to store my fs on?
2) In linux, for example, when you're booting you already get the rootfs:
/etc/
/dev
/root
/bin
and so on..
My question is, where do these directories stored in my kernel binary? When i'm booting my kernel for the first time, suppose from a CD-ROM or a floppy, i only have the Executable ELF on it. I don't get where are these directorie stored.
Thank you.
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 7:36 am
by Octacone
Sourcer wrote:I'm writing a POSIX-OS, After i wrote my ATA Driver, i'm headed into writing a ext2 fs.
But i can't understand some things:
1) If i have more than one ATA drives.(i.e. more than 1 is connected into the IDE.. ATAPI, SATA, etc..) which one do i choose to store my fs on?
2) In linux, for example, when you're booting you already get the rootfs:
/etc/
/dev
/root
/bin
and so on..
My question is, where do these directories stored in my kernel binary? When i'm booting my kernel for the first time, suppose from a CD-ROM or a floppy, i only have the Executable ELF on it. I don't get where are these directorie stored.
Thank you.
1) If you have lets say 3 drives, you choose the one you like the most. Simple.
2) I don't get that at all, like where are all those folder stored inside my compiled kernel? I guess on your hard drive and then your kernel reads them.
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 7:42 am
by Ch4ozz
You have a copy of the filesystem (which you want to have on your hdd later) on your CD/USB using the ISO9660 standard and then you will copy those files over to the HDD of the users choice.
This is a mini-installation of your OS, you have to handle partitioning and formatting the drive/partition.
Keep in mind that if your OS is getting really big, you might want to compress the files so that they fit on a CD/DVD.
After copying the files, grub (or your own bootloader) will detect your kernel on the HDD and boot it before its loaded from CD/USB.
You will need 2 slightly different kernels (or different folder/file structure) to detect whether your running on the CD/USB or on the HDD.
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 9:15 am
by Sourcer
Ch4ozz wrote:You have a copy of the filesystem (which you want to have on your hdd later) on your CD/USB using the ISO9660 standard and then you will copy those files over to the HDD of the users choice.
This is a mini-installation of your OS, you have to handle partitioning and formatting the drive/partition.
Keep in mind that if your OS is getting really big, you might want to compress the files so that they fit on a CD/DVD.
After copying the files, grub (or your own bootloader) will detect your kernel on the HDD and boot it before its loaded from CD/USB.
You will need 2 slightly different kernels (or different folder/file structure) to detect whether your running on the CD/USB or on the HDD.
Hey.
Can you be more specific?
What does "a copy of the filesystem" mean?
How is that minimal filesystem linked to my kernel?
why does it have to be an ISO?
How does my kernel recognize it? I mean, grub loads my kernel to RAM(which is compiled to ELF format), where does this "copy of filesystem" go?
I'm having a hard time understand the exact flow of what you're describing. the flow i have in mind is:
I have a compiled kernel in ELF Format; Grub loads my ELF according to the loading addresses in the sections provided in the ELF format. Where does this filesystem fit in?
Thank you, and sorry for the newbiesh questions, i'm trying to learn
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 9:29 am
by Ch4ozz
Sourcer wrote:Hey.
Can you be more specific?
What does "a copy of the filesystem" mean?
How is that minimal filesystem linked to my kernel?
why does it have to be an ISO?
How does my kernel recognize it? I mean, grub loads my kernel to RAM(which is compiled to ELF format), where does this "copy of filesystem" go?
I'm having a hard time understand the exact flow of what you're describing. the flow i have in mind is:
I have a compiled kernel in ELF Format; Grub loads my ELF according to the loading addresses in the sections provided in the ELF format. Where does this filesystem fit in?
Thank you, and sorry for the newbiesh questions, i'm trying to learn
The filesystem is stored on your CD/DVD/USB.
It follows the ISO9660 standard. Grub will be able to read files on it and find your kernel.
But you also have to be able to read from CD drive, so you can copy the files over and create a new filesystem in the HDD.
The ISO part is only true for VMs, you actually want a bootable version on your CD/DVD/USB (for example created by rufus).
Well you can divide a basic OS into 2 parts:
1. The "installer" part: Boots CD/DVD/USB and installs the OS on the HDD
2. The "normal run" part: Boots directly from HDD
So, heres how the normal (first start) flow of an OS usually looks like:
1. You boot from CD/DVD/USB and an installer-like OS will get loaded from it
2. You choose a HDD and a partition and it will copy all the needed data from the medium to the HDD
3. The system restarts itself, this time it boots the copied files from the HDD
This means you either have to code the installer too, or you think of a trick to identify if your OS was booted from external medium or directly from HDD.
In all cases you will need a working filesystem.
If you just want a live OS it will be much easier of course since you can skip step 1 and 2.
Hope I understood your question and answered everything you wanted to know.
And keep in mind: GRUB has nothing to do with your filesystem, it has its own system of course, but its only used to find your kernel and boot it
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 9:40 am
by Sourcer
Ch4ozz wrote:Sourcer wrote:Hey.
Can you be more specific?
What does "a copy of the filesystem" mean?
How is that minimal filesystem linked to my kernel?
why does it have to be an ISO?
How does my kernel recognize it? I mean, grub loads my kernel to RAM(which is compiled to ELF format), where does this "copy of filesystem" go?
I'm having a hard time understand the exact flow of what you're describing. the flow i have in mind is:
I have a compiled kernel in ELF Format; Grub loads my ELF according to the loading addresses in the sections provided in the ELF format. Where does this filesystem fit in?
Thank you, and sorry for the newbiesh questions, i'm trying to learn
The filesystem is stored on your CD/DVD/USB.
It follows the ISO9660 standard. Grub will be able to read files on it and find your kernel.
But you also have to be able to read from CD drive, so you can copy the files over and create a new filesystem in the HDD.
The ISO part is only true for VMs, you actually want a bootable version on your CD/DVD/USB (for example created by rufus).
Well you can divide a basic OS into 2 parts:
1. The "installer" part: Boots CD/DVD/USB and installs the OS on the HDD
2. The "normal run" part: Boots directly from HDD
So, heres how the normal (first start) flow of an OS usually looks like:
1. You boot from CD/DVD/USB and an installer-like OS will get loaded from it
2. You choose a HDD and a partition and it will copy all the needed data from the medium to the HDD
3. The system restarts itself, this time it boots the copied files from the HDD
This means you either have to code the installer too, or you think of a trick to identify if your OS was booted from external medium or directly from HDD.
In all cases you will need a working filesystem.
If you just want a live OS it will be much easier of course since you can skip step 1 and 2.
Hope I understood your question and answered everything you wanted to know.
And keep in mind: GRUB has nothing to do with your filesystem, it has its own system of course, but its only used to find your kernel and boot it
So basically GRUB only loads my kernel using its ELF Loader. It's up to me when it comes to loading the "minimal file-system" to the HDD.
So i also need a CD-ROM Driver and an a code that deals with ISO-filesystem?
If i understood correctly what you're saying, my final CD-ROM will contain data stored in ISO, and the data will be:
GRUB Bootloader(in the first partition, i assume)
My kernel
Minimal filesystem
Grub loads my kernel -> i load the file system from the disc -> i store grub, kernel, and the filesystem on the HDD -> i reboot from the HDD.
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 10:00 am
by Kevin
Sourcer wrote:1) If i have more than one ATA drives.(i.e. more than 1 is connected into the IDE.. ATAPI, SATA, etc..) which one do i choose to store my fs on?
2) In linux, for example, when you're booting you already get the rootfs: [...[
My question is, where do these directories stored in my kernel binary? When i'm booting my kernel for the first time, suppose from a CD-ROM or a floppy, i only have the Executable ELF on it. I don't get where are these directorie stored.
There is a single answer to both of your questions actually. In the traditional Linux setup, the device that should be mounted as / is passed to the kernel as a boot parameter, i.e. you would have specified something like "kernel /vmlinuz root=/dev/hda5" for GRUB.
Nowadays most Linux systems use an initrd, which is a ramdisk whose content is loaded by the bootloader and then mounted by kernel as /. Later in the boot process, the init scripts on the initrd remount / to point to the real root device instead of the ramdisk. But you can do just fine without an initrd in your OS.
Re: Implementing a file-system(questions)
Posted: Sat Aug 13, 2016 10:06 am
by Ch4ozz
@Sourcer
Yes thats right.
Kevin wrote:There is a single answer to both of your questions actually. In the traditional Linux setup, the device that should be mounted as / is passed to the kernel as a boot parameter, i.e. you would have specified something like "kernel /vmlinuz root=/dev/hda5" for GRUB.
Nowadays most Linux systems use an initrd, which is a ramdisk whose content is loaded by the bootloader and then mounted by kernel as /. Later in the boot process, the init scripts on the initrd remount / to point to the real root device instead of the ramdisk. But you can do just fine without an initrd in your OS.
Too bad Im not that familar with linux, thanks for the explanation
Re: Implementing a file-system(questions)
Posted: Sun Aug 14, 2016 3:20 am
by Sourcer
Thank you for the answers.
One last question:
When the boot loader is loaded to the lower 1MB of RAM and start executing, how does it know where was it loaded from? I mean, if it was loaded from the HDD, obviously the kernel sits in the HDD; but if it was loaded from the CD-ROM, kernel is on the CD-ROM.
Thanks.
Re: Implementing a file-system(questions)
Posted: Sun Aug 14, 2016 3:26 am
by onlyonemac
/bin, /dev, /etc, and so on are initially stored on your initrd (that's a ramdisk image that your bootloader loads at startup with the express purpose of providing those directories). Later on, your kernel can mount a real storage device on / and replace those directories.
Alternatively, you can give your kernel a command-line parameter that somehow tells it where to find a suitable root image, compile the driver for the device where the root image is stored into the kernel itself, and then the kernel can mount that device directly as the root filesystem before entering userspace.
Re: Implementing a file-system(questions)
Posted: Sun Aug 14, 2016 5:01 am
by Sourcer
onlyonemac wrote:/bin, /dev, /etc, and so on are initially stored on your initrd (that's a ramdisk image that your bootloader loads at startup with the express purpose of providing those directories). Later on, your kernel can mount a real storage device on / and replace those directories.
Alternatively, you can give your kernel a command-line parameter that somehow tells it where to find a suitable root image, compile the driver for the device where the root image is stored into the kernel itself, and then the kernel can mount that device directly as the root filesystem before entering userspace.
Hey, thank you.
Can you answer my last question too?
Re: Implementing a file-system(questions)
Posted: Sun Aug 14, 2016 5:39 am
by sleephacker
Sourcer wrote:When the boot loader is loaded to the lower 1MB of RAM and start executing, how does it know where was it loaded from? I mean, if it was loaded from the HDD, obviously the kernel sits in the HDD; but if it was loaded from the CD-ROM, kernel is on the CD-ROM.
Thanks.
The BIOS passes the drive number to the bootloader in the dl register, which it can use with int 13h to load sectors from that drive.
Re: Implementing a file-system(questions)
Posted: Thu Aug 18, 2016 4:36 am
by Sourcer
Hey, sorry for the newbish questions heh.
I'm currently booting from a CD/Floppy using GRUB2.
GRUB2 Reads the ISO filesystem on the disc and loads my kernel.
I'm using GRUB2 feature to load initrd to the RAM(i'm using busybox), which is in ext2.
Now, i can't seem to find what should be my next step/steps here:
1) Implement an ISO filesystem to read the CDROM myself, and load it to the root device.
2) Implement an EXT2 file system to load the intird to the root device.
How do i load the ISO fs to the root device? how will grub recognize the FS on the root device?
If i'm going to keep the root device with ext2 fs, it's not ISO anymore, so the grub.cfg file will be all messed up.
How is the root device going to be orgainzed? there has to be a boot sector, but also a filesystem. Where do i start managing it?
Thanks