# /boot/boot1 and boot/boot2



## Niatross (Mar 4, 2014)

I am a little confused with the following link:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/boot-blocks.html

The handbook says:


```
"Conceptually, the first and second stages are part of the same program, on the same area of the disk. Because of space constraints, they have been split into two, but are always installed together. They are copied from the combined /boot/boot by the installer or bsdlabel(8)."
```

My question is this:

Does the installer or `bsdlabel` use /boot/boot and split that file into two different files (ex:/boot/boot1 and /boot/boot2 during the installation process?

or

Does it take /boot/boot1 and /boot/boot2 and install them separately?

...and what does this mean:


```
Because of space constraints, they have been split into two, but are always installed together
```

Why are there space constraints?

Why doesn't the installer or `bsdilabel` just install /boot/boot? Why do you have three different files in the /boot directory (ex: /boot/boot, /boot/boot1 and /boot/boot2).

I'm not even concerned with /boot/boot0 in this question. That's a whole 'nother subject.

PS: Is the /boot/boot file just an *image* that contains /boot/boot1 and /boot/boot2? Is that what this file is?

I'm confused. Can somebody put it in layman's terms for me so that I can understand it?


----------



## wblock@ (Mar 4, 2014)

Sergio Andrés Gómez del Real contributed vastly more detail about this for the Architecture Handbook: http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/boot.html.

Well, that's not layman's terms, but it does tell what is going on with those files.


----------



## Niatross (Mar 4, 2014)

...so (from what I read), its all about boot1 fitting in the first sector (512 bytes) of the MBR partition (AKA: slice). The FreeBSD installer or `bsdlabel` takes the /boot/boot1 and concatenates it with the /boot/boot2 file and installs the result (AKA: /boot/boot) to the beginning of the MBR partition (AKA: slice).

My question is:

Why not concatenate the two files  (/boot/boot1 and /boot/boot2) from the very beginning and not bother the FreeBSD installer or `bsdlabel`?  What I mean by this is.............include a concatenated file (/boot/boot with every FreeBSD operating system) and remove boot1 and boot2 from the boot directory.

Wouldn't you end up with the same result?  I would think that the /boot/boot1 would be at the beginning (ex: the first 512 bytes) of the /boot/boot file.

Maybe I don't understand how the concatenation process occurs and the end result wouldn't allow the /boot/boot1 to fit in the first sector (512 bytes) of the MBR partition (AKA: slice)


----------



## kpa (Mar 4, 2014)

I can't exactly explain why /boot/boot1 and /boot/boot2 are kept separate until writing the boot code but their sizes give some clues:


```
freebsd10 ~ % ls -l /boot/boot1 /boot/boot2
-r--r--r--  1 root  wheel   512 Jan 20 10:29 /boot/boot1
-r--r--r--  1 root  wheel  7680 Jan 20 10:29 /boot/boot2
freebsd10 ~ %
```


The first one matches exactly a standard MBR block, in fact if a "dangerously dedicated" is used the /boot/boot1 will become the MBR of the disk with a fake MBR slice table. If you combine them together the end result is 8192 bytes that is exactly the amount of space reserved for the bsdlabel(8) partition table at the beginning of a FreeBSD slice. The fact that they are separate sections of the bootcode is probably the reason why they are kept apart until using them to create the boot blocks on disk.


----------

