# NanoBSD with gpart



## schmurfy (Oct 7, 2010)

Hello,
I have a somewhat silly problem but I cannot find the answer alone x(

I tried to upload a new firmware to a nanobsd box (with freebsd FreeBSD 8) but running:
`$  boot0cfg -s 3 -m 6 ad0`

completely messes with the running system, most read/write operation will fail with errors and even with "reboot", it is pretty scary so I did some search and found out that boot0cfg was more or less deprecated in favor of gpart, is that correct?

I found what I think to be the equivalent of my boot0cfg line with gpart to be:

```
gpart bootcode -b /boot/mbr ad0
$ gpart bootcode -b /boot/boot ad0s3
$ gpart set -a active -i 3 ad0
```

but after a reboot the system boots the second partition (which was the partition it was running on) xD

Here is the gpart show ad0 output: (partition 1 is unused and can be ignored, partition 2 is the one the system runs on)

```
=>     63  7372449  ad0  MBR  (3.5G)
       63      945    1  freebsd  (473K)
     1008   306432    2  freebsd  (150M)
   307440   306432    3  freebsd  [active]  (150M)
   613872     4032    4  freebsd  (2.0M)
   617904  6754608       - free -  (3.2G)

=>  0  945  ad0s1  BSD  (473K)
    0   16         - free -  (8.0K)
   16  929      1  !0  (465K)

=>     0  306432  ad0s2  BSD  (150M)
       0      16         - free -  (8.0K)
      16  306416      1  !0  (150M)

=>     0  306432  ad0s3  BSD  (150M)
       0      16         - free -  (8.0K)
      16  306416      1  !0  (150M)

=>   0  4032  ad0s4  BSD  (2.0M)
     0    16         - free -  (8.0K)
    16  4016      1  !0  (2.0M)
```

I did an fsck on the 3rd partition which shown no error I just cannot manage to make freebsd FreeBSD boot it 

PS: boot0cfg still seems to work after managing to force a reboot (init 6) but I would prefer avoiding it considering the errors it causes.


----------



## aragon (Oct 9, 2010)

You can't just change which partition the boot loader chains to.  You also need to update fstab.

You should also not use /boot/mbr as your boot manager because that will prevent you from manually falling back to the previous system via the serial console.  Use boot0 rather - it follows the active partition flag too.

You can find my update script at PR misc/145961.


----------



## schmurfy (Oct 22, 2010)

Thanks for your answer, I did not think about not being able to use the serial port console. I will check your script.


----------

