# Fresh install doesn't boot without USB inserted



## glitchcowboy (Mar 11, 2013)

I just did a fresh install of 9.1.0 using memstick.img on an install disk.  When I boot (i386 on Dell Latitude d810) I get to 

```
Can't work out which disk we are booting from.
Guessed BIOS device 0xffffffff not found by probes, defaulting to disk0
```

If I plug in the USB disk that I installed from, then the internal disk boots successfully. I'm guessing I need some boot-time configuration.  I'm an RHCE and AIX admin by trade, but I'm green to FreeBSD.


----------



## glitchcowboy (Mar 11, 2013)

Update:: Now I get past the splash screen and no matter what options I choose (no acpi, verbose, safe, etc)  I get no output and system immediately reboots.

Even more interesting is this new fact. I threw in the towel and figured I'd use something more friendly and put a Debian image on my USB disk (`dd if=x.img of=/dev/myusbdisk`). My Debian image didn't work, but then freebsd FreeBSD booted fine.  ONLY because there was a USB disk attached.  Nothing useful on the USB disk, just a USB disk that was present.  

As long as I have a garbage USB disk installed, FreeBSD boots.


----------



## Beeblebrox (Mar 14, 2013)

My immediate guess would be that when the bootcode was written to your HDD, it wrote the address of the USB device port, instead of the HDD's. Post your output of gpart so we can tell you how to re-write the bootcode to your present HDD.
`# gpart show`
Also check your bios boot order & look through the logs to be sure. If you want to go at it yourself, for a GPT partitioned HDD you have to do:
`# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i <indexnumber> <geom_device>`
Read gpart(8)()


----------



## blackout24 (Mar 15, 2013)

I have the same problems. I reinstalled FreeBSD 9.1-RELEASE and this time used the shell for partitioning also to get proper alignment.


ada0 is my single SSD. ada0p1 is my first partition with freebsd-boot. I managed to finish the installation and rebooted.
Again I can only get to the loader menu. When I press 1 or [Enter] for a normal boot the laptop restarts before I can see anything on the screen.
When hit [Esc] during my POST routine and select "Hard Drive" as boot device I also get to the loader but this time I can boot. I tried changing the boot device sequence in BIOS but it does not have any effects.

Is there a logfile for the loader? I searched for /var/log/loader.log but couldn't find something like that.


----------



## blackout24 (Mar 15, 2013)

`# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0`

This was what I used to install the bootcode. Since it does boot from my hard drive (kind of) and doesn't give me "Missing Operating System" I don't think this is the problem.


----------



## wblock@ (Mar 15, 2013)

What model of machine is this on?  Does FreeBSD 9.0 do the same thing, or is this a new regression?


----------



## kpa (Mar 15, 2013)

Beeblebrox said:
			
		

> My immediate guess would be that when the bootcode was written to your HDD, it wrote the address of the USB device port, instead of the HDD's.



The bootcode is always the same regardless of which device it gets written to. In case of MBR there are differences in actual contents of the first 512 bytes of the disk but that is because of the embedded partition table at the end of those 512 bytes.


----------



## Beeblebrox (Mar 15, 2013)

> The bootcode is always the same regardless of which device it gets written to


I disagree. If you had 3 HDD's - one with the bootcode and the two others had different root systems - how will the bootcode know which root to boot into?

Answer: It will boot into whichever root system wrote the bootcode to begin with. My guess is, the root.mountfrom= info gets written with the bootcode when the gpart command is invoked.


----------



## wblock@ (Mar 15, 2013)

The boot device is not hardcoded into the bootcode.  There are loader settings, but those happen long after the bootcode.  AFAIK, bootcode only pertains to the device it is on.


----------



## Beeblebrox (Mar 15, 2013)

> bootcode only pertains to the device it is on


My system has two HDD's. HDD1 is a partitioned SSD (has ccache, ZIL, and the freebsd-boot partition) while HDD0 is spindle-type, RAW partition managed by ZFS. At boot, BIOS first goes to the SSD, gets the bootcode, then goes to the normal HDD to boot root from ZFS.

I'll bet you anything you want that if I connect a second HDD hosting a different root (say on ufs) to the board, chroot into that root-fs then run gpart bootcode, the result will be that at next boot you will find root to be from the second HDD.


----------



## wblock@ (Mar 15, 2013)

The example is too complicated to really see what you are trying to demonstrate.

The BIOS decides which device to try to boot.
Bootcode is loaded from that device.  It looks on that device for bootable partitions.  How it searches varies between MBR, GPT, and ZFS.

If I understand you correctly, you are suggesting that the bootcode hardcodes the device from which it was installed as the device to boot from later.  It does not do that.  root.mountfrom tells the loader which device to mount as /, but by that time the system has already booted.


----------



## Beeblebrox (Mar 15, 2013)

Look at it this way:

* A system has 3 disk-devices and only device A has the bootcode.
* The other two (B&C) have root+kernel which make them bootable, but those two have no bootcode.
* Which device will get booted as default, if no menu-selection interface is used?

This is totally a dual-boot problem. Once the bootcode has been loaded, the bootloader can select the next-device. In the OP's question, the "next-device" has been mis-configured as the USB device.

How is BTX able to boot (albeit very painfully) both FreeBSD and Windows? The only difference is "selection menu" vs "default".


----------



## kpa (Mar 15, 2013)

The boot order set in the BIOS settings determines the boot order if no boot menu provided by the BIOS is used. In your example only the 1st disk A would be bootable to the BIOS. The 2nd and 3rd disks would not be bootable at all unless the first stage boot loader is interrupted by pressing shift and the boot device is set to a different disk. 


From boot(8):



> After the boot blocks have been loaded, you should see a prompt similar
> to the following:
> 
> >> FreeBSD/i386 BOOT
> ...



This is the part of the loading process where the location where loader(8) is loaded from could be changed to a different disk.


----------



## blackout24 (Mar 15, 2013)

wblock@ said:
			
		

> What model of machine is this on?  Does FreeBSD 9.0 do the same thing, or is this a new regression?



I tried FreeBSD 9.0 and a snapshot for 10-CURRENT both do the same.

My machine is this. 
http://h10025.www1.hp.com/ewfrf/wc/document?docname=c01095159&tmp_task=prodinfoCategory&cc=de&dlc=de&lc=de&product=3444032

I installed 2 GB RAM and a Crucial M4 64 GB SSD into this laptop.

Unfortunately I have no experience with FreeBSD on earlier versions and I don't have a CD/DVD-R to find out if it also fails to boot without this workaround when installed from optical medium.

I would love find out the source of this problem and report it as bug. Does the loader create logs in /var/log?


----------



## Beeblebrox (Mar 15, 2013)

> The boot order set in the BIOS settings determines the boot order. In your example only the 1st disk A would be bootable to the BIOS


I stated that, and that's not what I'm talking about.



> The 2nd and 3rd disks would not be bootable at all unless the first stage boot loader is interrupted by pressing shift and the boot device is set to a different disk.


In the absence of a menu-driven bootloader like grub, that's exactly what needs to be done to solve OP's problem. That, or re-write the bootcode with the new root info.

Let's simplify this to extreme.  glitchcowboy: please try this and inform us of the result? Thanks.


----------



## kpa (Mar 15, 2013)

Let me repeat, the bootcode does not contain the root device information. It is either autodetected from the boot device (the BIOS sets it in such a way that the boot code knows it) and the partition information or set manually like I showed in my previous post.


----------



## wblock@ (Mar 15, 2013)

@blackout24, looking back at your initial message, I see no mention of a USB memory stick.  Please verify that your system only boots FreeBSD when a USB stick is attached.  Otherwise, we're talking about two different problems.


----------



## blackout24 (Mar 15, 2013)

wblock@ said:
			
		

> @blackout24, looking back at your initial message, I see no mention of a USB memory stick.  Please verify that your system only boots FreeBSD when a USB stick is attached.  Otherwise, we're talking about two different problems.



I started a thread a few days ago, because I couldn't find a related thread first. OP joined in and affirmed that we have the same issue.

http://forums.freebsd.org/showthread.php?t=38381

Maybe both threads should be merged. I'm willing to try anything to solve this and report back if someone can point me in the right direction. Right now I'd like to see what goes in the background from the moment I press [Enter] in the loader menu to the moment the laptop restarts.


----------



## wblock@ (Mar 15, 2013)

Okay, next question: does it have to be a particular memory stick?  My guess is that the contents of the memory stick do not matter, or whether it is bootable.  Or possibly whether it is some other form of USB device.

That would make this an HP BIOS problem.  There may be settings that would make a difference, like legacy USB emulation.


----------



## blackout24 (Mar 16, 2013)

OK, I did some more testing. First I upgraded from 9.1-RELEASE to 9.1-STABLE R248326. Maybe I should not have done that, because it means the test case has changed now but I found out something interesting. I will stay at that revision until I can solve this issue from now. What I found is that after the upgrade, when I boot without USB stick I can't even get to the loader menu. This reminded me that it was same I experienced, when trying a FreeBSD 10-CURRENT snapshot memstick.img.

I posted about this here: http://forums.freebsd.org/showpost.php?p=212831&postcount=5

First conclusion: It has nothing to do with having any kind of USB-Stick attached (it booted with the stick used in the installation and any other stick). What made me think this is the case was, because inserting a stick means I have to get into the BIOS boot menu and select "Boot from Hard Drive" otherwise it would have booted from the USB-Stick (first boot device) automatically.

Second conclusion: Something between 9.1-RELEASE and 9.1-STABLE R248326 must have changed that doesn't like my hardware even more then before. 9.1-RELEASE doesn't start without directly telling it to boot from hard drive, which strangely isn't the same as having it as first boot device. The 9.1-RELEASE USB-Stick in fact doesn't boot, without telling the laptop "Boot from USB". Again having it as first boot device is not enough. 9.1-STABLE doesn't even get to loader menu, unless I use the "Boot from Hard Drive" work around again.

Why is still think this is relevant to the OPs problem: He does not say what he did to get to loader menu, where his laptop reboots no matter which options he toggles. Which is the same thing I have. It could be that he uses the same workaround I do. It would be good if @glitchcowboy could come back and tell us what he did between his first and second post.

Is there some kind of traceback or debugging mode for the early boot so I can provide output that might be relevant?


----------

