Nighpher, I'll try to answer your question, but for a more comprehensive description of boot process, try this article at IBM.
Ok, I assume, that you are using GRUB or GRUB2 as your bootloader for explanation. First off, when BIOS accesses your disk to load the bootloader, it makes use of its built-in routines for disk access, which are stored in the famous 13h interrupt. Bootloader (and kernel at setup phase) make use of those routines when they access disk. Note that BIOS runs in real mode (16-bit mode) of the processor, thus it cannot address more than 2^20 bytes of RAM (2^20, not 2^16, because each address in real mode is comprised of segment_address*16 + offset, where both segment address and offset are 16-bit, see "x86 memory segmentation" at Wikipedia). Thus, these routines can't access more than 1 MiB of RAM, which is a strict limitation and a major inconvenience.
BIOS loads bootloader code right from the MBR – the first 512 bytes of your disk – and executes it. If you're using GRUB, that code is GRUB stage 1. That code loads GRUB stage 1.5, which is located either in the first 32 KiB of disk space, called DOS compatibility region, or from a fixed address of the file system. It doesn't need to understand the file system structure to do this, because even if stage 1.5 is in the file system, it is "raw" code and can be directly loaded to RAM and executed: See "Details of GRUB on the PC" at pixelbeat.org, which is the source for the below image. Load of stage 1.5 from disk to RAM makes use of BIOS disk access routines.
Stage 1.5 contains the filesystem utilities, so that it can read the stage 2 from the filesystem (well, it still uses BIOS 13h to read from disk to RAM, but now it can decipher filesystem info about inodes, etc., and get raw code out of the disk). Older BIOSes might not be able to access the whole HD due to limitations in their disk addressing mode – they might use Cylinder-Head-Sector system, unable to address more than first 8 GiB of disk space: http://en.wikipedia.org/wiki/Cylinder-head-sector.
Stage 2 loads the kernel into RAM (again, using BIOS disk utilities). If it's 2.6+ kernel, it also has initramfs compiled within, so no need to load it. If it's an older kernel, bootloader also loads standalone initrd image into memory, so that kernel could mount it and get drivers for mounting real file system from disk.
The problem is that the kernel (and ramdisk) weigh more than 1 MiB; thus, to load them into RAM you have to load the kernel into the first 1 MiB, then jump to protected mode (32-bit), move the loaded kernel to high memory (free the first 1 MiB for real mode), then return to real (16-bit) mode again, get ramdisk from disk to first 1 MiB (if it's a separate initrd and older kernel), possibly switch to protected (32-bit) mode again, put it to where it belongs, possibly get back to real mode (or not: https://stackoverflow.com/questions/4821911/does-grub-switch-to-protected-mode) and execute the kernel code. Warning: I'm not entirely sure about thoroughness and accuracy of this part of description.
Now, when you finally run the kernel, you already have it and ramdisk loaded into RAM by bootloader, so the kernel can use disk utilities from ramdisk to mount your real root file system and pivot root to it. ramfs drivers are present in the kernel, so it can understand the contents of initramfs, of course.
From https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Reference_Guide/s1-grub-whatis.html
US/Red_Hat_Enterprise_Linux/3/html/Reference_Guide/s1-grub-whatis.html
GRUB loads itself into memory in the following stages:
The Stage 1 or primary boot loader is read into memory by the BIOS
from the MBR[1]. The primary boot loader exists on less than 512 bytes
of disk space within the MBR and is capable of loading either the
Stage 1.5 or Stage 2 boot loader.
The Stage 1.5 boot loader is read into memory by the Stage 1 boot
loader, if necessary. Some hardware requires an intermediate step to
get to the Stage 2 boot loader. This is sometimes true when the /boot/
partition is above the 1024 cylinder head of the hard drive or when
using LBA mode. The Stage 1.5 boot loader is found either on the
/boot/ partition or on a small part of the MBR and the /boot/
partition.
The Stage 2 or secondary boot loader is read into memory. The
secondary boot loader displays the GRUB menu and command environment.
This interface allows selection of the kernel or operating system to
boot, pass arguments to the kernel, or look at system parameters.
It seems rather obvious stage 2 is the actual grub binary. In fact, the documentation states grub 2 is loaded by name.
I would try to do:
dd if=/dev/zero of=/boot/stage2
Additional data:
Inspecting /boot/grub:
copy of stage1 bootloader:
stage1
Files for stage1_5:
e2fs_stage1_5
fat_stage1_5
jfs_stage1_5
minix_stage1_5
reiserfs_stage1_5
xfs_stage1_5
File for stage2:
stage2
Link to grub image:
Best Answer
That's a somewhat simplified view, but the basic idea is right. Typical initialization code actually consists of several successive pieces.
That's a legacy BIOS. Modern PC BIOS has a standardized bootloader interface: UEFI. Non-PC platforms don't call their manufacturer-provided bootloader “BIOS”.
Yes. There is no other memory that can be written to (under normal operation).
No. No architecture that I know of has a magnetic storage that's addressable by the CPU. It always takes some code in the operating system to access the hard disk.
That would depend on the hardware. Some code in ROM or flash memory can be executed directly from ROM. Usually, apart from some initial bootloader code executed from ROM (or EEPROM on PC hardware I think), the code would be copied into RAM first, because RAM is faster.