# Switch boot order



## Ajax (Apr 1, 2015)

I have a regular non-EFI PC with BIOS which boot order is SATA0, SATA1 and so on set in BIOS.
On this PC there are two hard disks SATA0 and SATA1. The first disk (SATA0) keep running 10.0 with all bells & whistles. However disk seems to start failing so I did install 10.1 in a second disk (SATA1) via chroot and did transfer all needed data. Both disks are GPT partitioned.
Currently `gpart show -p` gives me

```
=>       34  156301421    ada0  GPT  (75G)
         34        128  ada0p1  freebsd-boot  (64K)
        162  148897664  ada0p2  freebsd-ufs  [bootfailed]  (71G)
  148897826    7403628  ada0p3  freebsd-swap  (3.5G)
  156301454          1          - free -  (512B)

=>       34  312581741    ada1  GPT  (149G)
         34          6          - free -  (3.0K)
         40        128  ada1p1  freebsd-boot  (64K)
        168    8388602  ada1p2  freebsd-swap  (4.0G)
    8388770  304193005  ada1p3  freebsd-ufs  [bootonce,bootme]  (145G)
```
However after restart ada0p2 looses _bootfailed_ and system still booted from the first disk.
So here is the question: how do I force PC to skip first disk (SATA0) upon next boot and try to boot from SATA1? Is this possible at all without physical switching SATA ports on a hardware (with further swapping ada1 <> ada0)?
Would appreciate any help.


----------



## tingo (Apr 1, 2015)

What you have already done should be all that needs to be done. But since it doesn't work you might have to try more things.
You can try to unset the boot flag (ok, attribute) on ada0 if it has one. 
Or you could try to change boot order in the BIOS.


----------



## Ajax (Apr 1, 2015)

How do I unset boot flag from a disk? Didn't find such option in `fdisk`, only how to set one.


----------



## tingo (Apr 1, 2015)

You are using the wrong utility. Check out gpart(8).


----------



## Ajax (Apr 1, 2015)

Well, the command `gpart unset -a active -i 1 /dev/ada0p1` didn't work with 
	
	



```
gpart: attrib 'active': Device not configured
```
 while `gpart unset -a active /dev/ada0` worked but didn't help.


----------



## SirDice (Apr 1, 2015)

Boot order needs to be changed in the BIOS. The BIOS always loads the first disk and from there the first UFS partition. So you need to swap disks physically or try and change the order in the BIOS.


----------



## wblock@ (Apr 1, 2015)

See gptboot(8) for the definitions of the attributes.  But that is secondary.  Continuing to use a failing disk is risking data loss.


----------



## Ajax (Apr 1, 2015)

Well, that is a just router with simple config (which is more important — with a backup ). So I did try to solve this problem just because of my curiosity, it takes few minutes to go and swap connectors 
Sure I did check gptboot(8) and gpart(8) but they aren't clear about pMBR + GPT disks on non-EFI machines. I do assume it is just impossible then to make such operation with current config. But do I understand right that on a motherboard with proper UEFI support it will be possible to use pure GPT (without pMBR) thus control boot order exclusively via gptboot(8) and partition attributes?


----------



## wblock@ (Apr 1, 2015)

I don't know about pure UEFI, but those attributes work on GPT disks booted from BIOS or UEFI in the BIOS/legacy/CSM mode.


----------



## Ajax (Apr 1, 2015)

I can't then understand what's wrong in my partition scheme and attributes? These are GPT disks being loaded from BIOS but documentation doesn't say anything about different disks, only about different partitions on a single disk.


----------



## SirDice (Apr 1, 2015)

Yes, but the gptboot(8) man page talks about booting the first partition with the bootonce and/or bootme attribute. So the PMBR loads whatever is in freebsd-boot, which in turn loads the first bootme partition. However it doesn't state if it checks _all_ available harddisks or just the one it booted from. I'm going to assume it's the latter.


----------

