# Non-system disk on non-UEFI systems when booting from USB



## EoflaOE (Mar 2, 2019)

I would like to try FreeBSD after I tried out Linux. I have tested FreeBSD earlier on VirtualBox, and it succeeded. I have created my FreeBSD USB using dd as my first attempt on Kali Linux, following the tutorial. I have used FreeBSD-13.0-CURRENT 2019/2/28 memstick.img as my release for testing purposes. 

Now here comes the problem. When attempting to boot to USB on my old computer that only supports BIOS, it tells me that the disk that I am booting from isn't a system disk, and to restart, I have to press any key, which leads to booting to the HDD. Output:


```
Non-system disk
Press any key to reboot
```

I thought that was the dd problem, but before doing it in win32diskimage on my Windows XP, I checked the partition table on Kali, and saw that there are 2 partitions: EFI, and FreeBSD. I then tried to make my bootable USB using the app aforementioned after I wiped every partition out using Rufus, and I even checked the SHA256 sum, and they're the same as one provided in the website. 

I rebooted to my USB, and it still yields the same error as described. Could it be that my memstick.img doesn't support BIOS? Or can I build the memstick.img with BIOS support without going to FreeBSD? I need suggestions to get it to work on my PC.


----------



## Emrion (Mar 2, 2019)

Hi,

Recheck the image you downloaded and commands you used to transfert on your USB stick.

As far as I know, memstick images are bootable under BIOS.

I would have tested the 12.0-RELEASE... The latest CURRENT is highly experimental and can lead to numerous problems.


----------



## Emrion (Mar 2, 2019)

Just tested FreeBSD-13.0-CURRENT-amd64-20190221-r344398-memstick.img under bhyve. It boots under legacy BIOS (and under UEFI as well).


----------



## EoflaOE (Mar 2, 2019)

Thanks Emrion! So, what is the best USB creation tool that makes FreeBSD boot under legacy BIOS? Thanks for suggestion Wozzeck.Live!


----------



## Emrion (Mar 2, 2019)

I think you have read the handbook (if not, do it): https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/bsdinstall-pre.html

The advised means are: `dd` for UNIX-like systems and  https://sourceforge.net/projects/win32diskimager/  for Windows.


----------



## EoflaOE (Mar 3, 2019)

Yes, I have read the handbook, and the dd command that I used is the same as one described in a handbook. But how can I make it work under legacy BIOS?


----------



## mickey (Mar 3, 2019)

Has your "old computer" ever successfully booted anything from a USB stick or that particular USB stick? Just asking cause I already encountered two old-ish mainboards who would not only refuse to boot from an USB stick but where the BIOS also completely froze when a USB stick was plugged in when booting. The same USB stick booted just fine on two other machines though. After having tried two different USB sticks (USB 3.0 / 2.0) and a myriad of BIOS settings, I finally had to revert to lending my other machine's CD drive and boot FreeBSD 12.0 install from CD.


----------



## EoflaOE (Mar 3, 2019)

It can boot USB successfully. I have tested several Linux distros and it worked. In order for the USB to show on Boot Menu, the following conditions should be met for my PC:

The USB stick should be on the front side
And for the USB to boot correctly, below criteria should be met:

USB should be formatted using FAT32 and have a valid boot sector
The partition table should be MBR


----------



## Emrion (Mar 3, 2019)

In the 13-CURRENT memstick image you have:

- MBR scheme:
---- [slice1] efi partition (which is a FAT partition but used only for UEFI booting as the name suggests).
---- [slice2 - active] freebsd:
---------- (a) freebsd-ufs (where lies all the system)

 I don't see why a BIOS would search a FAT partition before to load the MBR. It just verifies if the MBR has the magic number at its end and sometimes checks if there is an active partition.

The partition scheme (MBR) has nothing to do with file system. Normaly MBR has to be loaded in memory and its boot program executed. Then this code looks for the active partition, load the boot code it finds inside and execute it.

I'm afraid I'm as lost as you.


----------



## EoflaOE (Mar 3, 2019)

Thank you! I did a partition table listing the last time, and the boot flag was set to UEFI partition. Could setting the boot flag on the freebsd partition help?


----------



## Emrion (Mar 3, 2019)

Yes, and that is maybe the trick. The message you get seems to come from the efi partition.


> Non-system disk
> Press any key to reboot


As I dump the memstick image, I can see it in the second sector of the disk. I think this is a sort of MBR that prevent to go further in such a case.

That said, if you'd dd'ed the image, you would have the freebsd partition active.


----------



## EoflaOE (Mar 3, 2019)

OK. I will try to make my FreeBSD partition active after a test. Thank you so much! I will tell you the results.


----------



## EoflaOE (Mar 4, 2019)

I have set the boot flag as FreeBSD instead of UEFI partition, and it worked *on my alternative laptop which is newer (2009)*, but my old computer still can't boot FreeBSD from USB! It says:


```
Non-system disk
Press any key to reboot
```


----------



## Emrion (Mar 4, 2019)

Maybe it's your old computer which activate the efi partition. After a try on this computer, does the USB stick boot well on your laptop?


----------



## EoflaOE (Mar 5, 2019)

Yes. It boots well. It shows me the FreeBSD boot screen and when I press Enter, the kernel starts and everything is probed, then it shows me whether to choose Install, or Live CD. The mouse even worked and it showed me a cursor, so my Wireless Mouse is detected. But my main goal is booting FreeBSD on my old PC.

Should I try to boot FreeBSD if the boot flag is set to FreeBSD partition with Plop Boot Manager?


----------



## Emrion (Mar 5, 2019)

You can.  But until we understand what your old PC does or expects, it's probably in vain.

I installed FreeBSD 12-RELEASE on a Pentium-II 266 based PC (which can't even boot on USB) and it was funny. Once the install done (via cd-rom), the machine didn't allow the hdd to boot because its "MBR" did not have an active partition. In fact, it was the protective MBR of a GPT scheme which actually expose one fake partition but that one hasn't the active flag set. I was obliged to use `fdisk` in order to make things eventually work.

In your case, it's difficult to guess what your PC does. If I had such a problem, I will modify the MBR program of the USB stick to print something on the screen (or simplier: make the computer hang). Then I will know for sure if it loads the MBR or not.

After that, I will have more ideas about what happen.


----------



## EoflaOE (Mar 5, 2019)

Thank you! I have installed Plop Boot Manager alongside the Windows XP, and tried to boot from USB using the EHCI driver, but that made Plop freeze, so I tried to force USB 1.1 drivers to load, and it booted successfully, just to find that I have reached to the point where the loading animation, before the FreeBSD intro screen before boot selection, spins for a bit and then freezes. I checked if my entire PC was frozen using Numlock key, and the LED turns on and off normally. Why woud it freeze? 

I think the suspect is my BIOS itself. My laptop has detected my USB flash drive as USB *HDD* (Hard Disk Drive), whereas my PC detects the USB flash drive in the front side as USB RMD-*FDD* (*Floppy *disk drive) and if I try to put my USB on the back side, even with non-essential USB devices connected, the BIOS can't see my flash drive with the *Legacy USB storage *enabled, so I think that's why my laptop would display the FreeBSD installation screen whereas my PC would only tell me that:


```
Non-system disk
Press any key to reboot
```

I will debug the problem if it worked or not using Plop. Which tool allows me to modify the MBR program on the USB flash drive to add some printing codes to see if my PC would load MBR or not?


----------



## Emrion (Mar 5, 2019)

I don't know how Plop Boot Manager works, so I can't answer to your question.

Modify the mbr program of the image file is trivial under FreeBSD. But a disk editor under Windows is more convenient.

Let's hang the mbr code by inserting an infinite loop at the beginning. The assembly is `jmp -2`. The corresponding machine codes are 0xEB, 0xFE. Simply replace the first two bytes of the memstick image file with 0xEB, 0xFE. Then, you flash your USB key with the modified file.

Under FreeBSD this would be:`printf '\353\376' | dd of=image.img bs=2 count=1 conv=notrunc`

\353\376 are the octal writings of hexadecimal bytes 0xEB, 0xFE.
bs=2 count=1 for transfering 2 bytes.
conv=notrunc to avoid the ouput file from being truncating after the two bytes.

If your PC displays nothing but a blinking cursor when it tries to boot the modified key, that means it really loads and executes the mbr code. Otherwise, if the output remains the same, this comes from the BIOS.


----------



## EoflaOE (Mar 6, 2019)

About the Plop Boot Manager thing, I will do some troubleshooting after the hanging one.

About the hanging thing, I made this image using the command that is provided using my Android in Termux because Android is based on Linux. It has all necessary commands like printf, dd, etc. 

I burned this image to my USB so the first 2 bytes are modified, retaining the FreeBSD and UEFI partitions, and when I tried to boot from it on my laptop (USB *HDD*), it only shows the white blinking underscore and hangs. However, I tried to boot from it using my PC (Using both USB RMD-*FDD* and Plop Boot Manager), it only shows the white blinking underscore and hangs.


----------



## Emrion (Mar 6, 2019)

EoflaOE said:


> I burned this image to my USB so the first 2 bytes are modified, retaining the FreeBSD and UEFI partitions, and when I tried to boot from it on my laptop (USB *HDD*), it only shows the white blinking underscore and hangs. However, I tried to boot from it using my PC (Using both USB RMD-*FDD* and Plop Boot Manager), it only shows the white blinking underscore and hangs.


 
Very interesting. That means we can have a control on what happens. 

But I have to suppose the BIOS is setting as active the efi partition on the MBR image in memory (and deactivate the freebsd one)... Weird.

I can verify what occurs if I set manually the efi partition as active. I think I will reproduce what you get.

More than that, it's possible to modify the MBR boot code to make it load the freebsd partition no matter if it is active or not. I will try this.


----------



## EoflaOE (Mar 6, 2019)

Thank you! But, how can I modify the MBR boot code so it will load the FreeBSD partition, no matter if it's active or not? and what is a command to do so?


----------



## Emrion (Mar 6, 2019)

I will, if you leave me some hours / days. Then, I'll give you the new MBR in binary form, so you can patch your memstick image file with `dd` or the like.


----------



## EoflaOE (Mar 6, 2019)

OK. Thanks so much! BTW if the new MBR file is finished, should I run like this? Suppose that my USB flash drive is located in /dev/sdb:
`dd if=/path/to/mbr.bin of=/dev/sdb`
Or should I add extra arguments?


----------



## SirDice (Mar 6, 2019)

Be extra careful with that. The partition table sits right after the MBR code (offset 446). The first 512 bytes of the disk contains both the MBR and your partition tables. Screw up the partition table and your data is gone. Not entirely gone, if you can restore the partition table everything would still be there. But still a pain to have to go through, especially if you don't have a backup of the original partition tables. 






						Master boot record - Wikipedia
					






					en.wikipedia.org
				




Unfortunately UEFI hasn't been added yet but the classic BIOS boot (CSM) is described in the handbook: Chapter 12. The FreeBSD Booting Process.
You will also find lots of information in boot(8), gptboot(8), loader(8) and UEFI(8).

Mandatory reading regarding -CURRENT: Topics about unsupported FreeBSD versions


----------



## EoflaOE (Mar 6, 2019)

I will try to be extra careful. Also, I have a backup of the memstick.img so that anything goes wrong, I will use it to restore the stick to its original state. Once I finish the Live USB that has CURRENT, I will immediately move to STABLE or RELEASE.


----------



## SirDice (Mar 6, 2019)

EoflaOE said:


> I will immediately move to STABLE or RELEASE.


I would suggest starting with a -RELEASE version. You can easily keep it up to date using freebsd-update(8). Updating a -STABLE requires you to build from source. While the process is fairly straightforward it does require a bit of know-how and it's quite easy to end up with a broken or unstable system, especially if you're unfamiliar with how the FreeBSD code is managed.

Get your feet wet first on a -RELEASE. Once you've learned how to stay afloat you can have a go at -STABLE.


----------



## EoflaOE (Mar 6, 2019)

OK Thanks! I will try out both versions starting with RELEASE after the new MBR binary file has came to flash it with `dd`.


----------



## Emrion (Mar 6, 2019)

Ok. Don't worry *SirDice*, I well know this domain.

It was easier than I believed. The code source lies in /usr/src/stand/i386/mbr/mbr.s (12-0-RELEASE). In italic the removed instructions, in bold the text I added or modified:

```
# Scan the partition table looking for an active entry.  Note that %ch is
# zero from the repeated string instruction above.  We save the offset of
# the active partition in %si and scan the entire table to ensure that only
# one partition is marked active.
#
main:   xorw %si,%si            # No active partition
        movw $partbl,%bx        # Partition table
        movb $0x4,%cl           # Number of entries
main.1: *cmpb $0xA5,4(%bx)       # Type = FreeBSD?*
        *jne main.2              # No*
_#jg err_pt             # If 0x1..0x7f
#testw %si,%si         # Active already found?
#jnz err_pt            # Yes_
        movw %bx,%si            *# Point to FreeBSD partition*
        jmp main.3
main.2: addb $0x10,%bl          # Till
        loop main.1             #  done
_#testw %si,%si         # Active found?
#jnz main.3            # Yes_
        int $0x18               # BIOS: Diskless boot
#
# Ok, we've found a possible active partition.  Check to see that the drive
# is a valid hard drive number.
#
main.3:  cmpb $0x80,%dl         # Drive valid?
```
Now, the mbr code doesn't verify anymore if there is one or more activated partition. It just searches for a BSD one and boots it.

A `make` inside /usr/src/stand/i386/mbr/ compiles and creates the new mbr in /usr/obj/usr/src/amd64.amd64/stand/i386.

As SireDice stated, you must replace only the 446 first bytes of the original mbr because there is the partition table behind. The file I attach here is the compiled mbr but just the first 446 bytes.

You can't directly fill /dev/sdb. Instead, you have to do that on the image file:
`dd if=boot-mbr.txt of=image.img bs=446 count=1 conv=notrunc`
After the image has been updated, you can flash your device. Just rewrite the first sector, the rest remaining the same:
`dd if=image.img of=/dev/sdb bs=512 count=1`

Let me know if this works or not.

PS: I activated the efi partition and got exactly the message you have. I patched the memstick image and it worked (in a VM).


----------



## EoflaOE (Mar 7, 2019)

Thanks for the MBR file! I have currently patched it, but I can't test at this moment because my electricity is off and I have school, and when I return back home, I only have a bit of time which I think is enough for testing before the electricity is off. 

I will let you know, when I have tested it.


----------



## EoflaOE (Mar 7, 2019)

I tested this on my laptop, and it worked fine. It shows me the FreeBSD installation screen.

However on my PC, I performed the following tests:

With Legacy USB Support:

- *USB RMD-FDD:* Refuses to boot and prints this message:


```
Non-system disk
Press any key to reboot
```

Without Legacy USB Support:

- *USB RMD-FDD:* Although recognized, it will go straight to HDD.

I made sure that I have followed every single step correctly. Is the MBR file that is attached modified to reflect such changes? And why would my PC do the above?


----------



## Emrion (Mar 7, 2019)

I'm out of idea now. Try to repeat the procedure.
Compare the md5 of the modified mbr and the original one to be sure you have altered it.

`dd if=original-image.img of=mbr.ori bs=512 count=1`
`dd if=modified-image.img of=mbr.mod bs=512 count=1`
`md5 mbr.ori && md5 mbr.mod`


----------



## EoflaOE (Mar 7, 2019)

Ooops. It looks like that was _my _fault, because I assumed that we're going to create a *new *image which will overwrite my stick's MBR. I'm sorry.

I used the following commands on my rooted Android, assuming that FreeBSD13.0.img is the FreeBSD memstick image file:

`busybox dd if=boot-mbr.txt of=FreeBSD13.0.img bs=446 count=1 conv=notrunc`

and verified the MD5 checksums between the original and the modified images (md5sum on Android Termux), and the result is (Assume that original.img is the original image):


```
$ md5sum -b FreeBSD13.0.img
173f18f6d83c6099a49813e31f76950e  FreeBSD13.0.img
$ md5sum -b original.img
323e7035c1ed22e1912ce07b7671c583  original.img
```

and they were different, so I prepared the USB stick for my computer, because my electricity was off at the moment, by using this command on my rooted Android tablet that supports OTG:

`busybox dd if=FreeBSD13.0.img of=/dev/block/sda bs=512 count=1`

I checked the partition table, and saw that the efi partition has a boot flag.

Am I doing the whole procedure right?


----------



## Emrion (Mar 7, 2019)

It seems. If your Android commands do the same things than FreeBSD.

It's not normal that the efi partition is active. In the original image, it's the freebsd one which have the boot flag. I have not the same md5 as you but I understand why: I took the 2019/02/21 snapshot and not the 2019/02/28 one. But this makes no difference for this matter.

The important thing is the md5 of the mbr which you didn't give...

Finally, we proved that your PC loads and executes the mbr from the USB key. So there is no reason you get the same message as before.


----------



## EoflaOE (Mar 7, 2019)

Sums:

```
2dcc42bc849e871fdb4113bdc8ccdf18 boot-mod.txt
27534479da407e4a65db6f96f44715ff boot-orig.txt
```


----------



## Emrion (Mar 7, 2019)

This is actualy the boot code I provided (md5 correct) but I mean:


> dd if=original-image.img of=mbr.ori bs=512 count=1
> dd if=modified-image.img of=mbr.mod bs=512 count=1
> md5 mbr.ori && md5 mbr.mod


----------



## EoflaOE (Mar 7, 2019)

I have deleted the post which only shows the boot-mbr.txt's sum and made a post with the information that you need. Refresh the page to see.


----------



## Emrion (Mar 7, 2019)

Lol. Still not the same md5. Maybe due to snapshot difference. Just verify that the mbr on the USB key has the same md5 as boot-mod.txt.
`dd if=/dev/block/sda of=mbr.real bs=512 count=1`


----------



## EoflaOE (Mar 7, 2019)

```
2dcc42bc849e871fdb4113bdc8ccdf18  boot-mod.txt
2dcc42bc849e871fdb4113bdc8ccdf18  boot-usb.txt
```


----------



## Emrion (Mar 7, 2019)

Ok. Just try on your old PC then.


----------



## EoflaOE (Mar 7, 2019)

Message that I got when I tried to boot from USB in my old PC:

```
Non-system disk
Press any key to reboot
```


----------



## EoflaOE (Mar 8, 2019)

I have removed the EFI partition and set the FreeBSD one as bootable, but when I reboot and boot to USB (USB RMD-FDD), it only shows me a blinking underscore. 

My BIOS has detected my flash drive as USB RMD-FDD, and when I looked at the documentation of my motherboard, it says that there are available USB boot modes:


USB HDD
USB FDD
USB CD/DVD
USB RMD-FDD
USB RMD-HDD


----------



## EoflaOE (Mar 8, 2019)

I looked at Unetbootin, and I made my USB using it for the last time, and it booted, until it stops on the message attached below





Not only FreeBSD doesn't boot on my old PC, but the same message has appeared in *my alternative laptop! *


----------



## alx741 (Jul 24, 2019)

EoflaOE I'm having the exact same issue, did you manage to get it to boot up?


----------

