Implementing a file-system(questions)
Implementing a file-system(questions)
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.
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)
1) If you have lets say 3 drives, you choose the one you like the most. Simple.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.
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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: Implementing a file-system(questions)
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.
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)
Hey.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.
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)
The filesystem is stored on your CD/DVD/USB.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
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)
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.Ch4ozz wrote:The filesystem is stored on your CD/DVD/USB.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
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 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)
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.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.
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)
@Sourcer
Yes thats right.
Yes thats right.
Too bad Im not that familar with linux, thanks for the explanationKevin 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.
Re: Implementing a file-system(questions)
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.
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.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Implementing a file-system(questions)
/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.
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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Implementing a file-system(questions)
Hey, thank you.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.
Can you answer my last question too?
- sleephacker
- Member
- Posts: 97
- Joined: Thu Aug 06, 2015 6:41 am
- Location: Netherlands
Re: Implementing a file-system(questions)
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.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.
Re: Implementing a file-system(questions)
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
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