# In UEFI mode switch partition



## kavitakr (Jun 13, 2022)

Hi

We have two partitions need to switch from 3 to 5 in UEFI mode

Ref: https://www.freebsd.org/cgi/man.cgi?query=boot.config&sektion=5&n=1

  # echo "5:da(5,a)/boot/loader" > /boot.config should switch the partition .

As anyone used the boot.config to switch partition?


----------



## tingo (Jun 13, 2022)

UEFI? And (old) slices? Not gpart?


----------



## kavitakr (Jun 14, 2022)

tingo said:


> UEFI? And (old) slices? Not gpart?


Yes UEFI..and in case of gpart  I wanted to check.

For BIOS mode *gptboot* --    GPT bootcode for UFS on    BIOS-based computers

we used gpart set -a bootme -I 5 da0 which worked
based on this Ref: https://freebsd-arch.freebsd.narkive.com/EZ767WY5/gptboot-rewrite-bootonce-etc


----------



## tingo (Jun 14, 2022)

My point being: are you sure that gptboot works on a disk drive that is *not* gpt partitioned? From gptboot(8) man page:
"gptboot is used on BIOS-based computers to boot from a UFS partition on a GPT-partitioned disk.  gptboot is installed in a freebsd-boot partition with gpart(8).".
Disks with slices (old, very old style) doesn't have freebsd-boot partition type...


----------



## kavitakr (Jun 15, 2022)

tingo said:


> My point being: are you sure that gptboot works on a disk drive that is *not* gpt partitioned? From gptboot(8) man page:
> "gptboot is used on BIOS-based computers to boot from a UFS partition on a GPT-partitioned disk.  gptboot is installed in a freebsd-boot partition with gpart(8).".
> Disks with slices (old, very old style) doesn't have freebsd-boot partition type...


No tingo, I meant in BIOS mode gpart set -a bootme -i3 da0 worked to switch partition.

We are seeing problems in UEFI mode for UFS GPT based  , I have a efi partition and which has
/efi/EFI/BOOT/BOOTX64.EFI

and rootfs  exists in partition 3 and partition 5.

I want to use boot.config to update currdev of loader to switch partition from 3 to 5, But setting the
cat /efi/boot.config

0:ad(0p5)/boot/loader

is not working

I tried setting /efi/freebsd/loader.env , this also is not updating the currdev
cat /efi/freebsd/loader.env 

"rootdev=disk0p5:"

Like eg: https://nofu.jp/wiki/en/blog/2021/2021-01-09


----------



## T-Daemon (Jun 15, 2022)

kavitakr said:


> I tried setting /efi/freebsd/loader.env , this also is not updating the currdev
> cat /efi/freebsd/loader.env
> 
> "rootdev=disk0p5:"



Set in efi/freebsd/loader.env

```
currdev=disk0p5:
```


----------



## kavitakr (Jun 15, 2022)

T-Daemon said:


> Set in efi/freebsd/loader.env
> 
> ```
> currdev=disk0p5:
> ```


T-Daemon  I tried this not working ...Am I missing anything?


Just for more Information. I am using FreeBSD 13.0-RELEASE-p11


----------



## cmoerz (Jun 15, 2022)

Did you remove the old "rootfs" label from partition 3? I understand, you want to move your root partition from 3 to 5. If you have more than one gpt label named "rootfs", the boot process will likely not work out in the end.

Just use `gpart modify` to set a different label or remove the one on partition 3.


----------



## kavitakr (Jun 15, 2022)

cmoerz said:


> Did you remove the old "rootfs" label from partition 3? I understand, you want to move your root partition from 3 to 5. If you have more than one gpt label named "rootfs", the boot process will likely not work out in the end.
> 
> Just use `gpart modify` to set a different label or remove the one on partition 3.


 gpart show -l

=>        40  1048575920  da0  GPT  (500G)

          40        2008       - free -  (1.0M)

        2048         128    1  (null)  (64K)

        2176        1920       - free -  (960K)

        4096     2097152    2  (null)  (1.0G)

     2101248     8388608    3  (null)  (4.0G)

    10489856    16777216    4  (null)  (8.0G)

    27267072     8388608    5  (null)  (4.0G)

still not working


----------



## T-Daemon (Jun 15, 2022)

T-Daemon said:


> currdev=disk0p5:





kavitakr said:


> _*[FONT=monospace]T-Daemon[/FONT]*_ I tried this not working ..


Indeed, I've checked in a VirtualBox VM, 13.0-RELEASE-p11 seems not to read the disk environment from loader.env.

"currdev=" works as expected when set at the loader prompt (Boot menu -> Escape to loader prompt).

On 13.1-RELEASE however it works fine:




I suggest you upgrade the system to 13.1-RELEASE as 13.0-RELEASE will be EoL August 31, 2022 anyway and chances of the error to be corrected in 13.0 are not likely.


----------



## grahamperrin@ (Jun 15, 2022)

> … We have two partitions need to switch from 3 to 5 in UEFI mode …



I can't visualise what you want to achieve, but GPT fdisk can transpose partition table entries, and so on. 

sysutils/gdisk

gdisk(8)


----------



## kavitakr (Jun 16, 2022)

T-Daemon said:


> Indeed, I've checked in a VirtualBox VM, 13.0-RELEASE-p11 seems not to read the disk environment from loader.env.
> 
> "currdev=" works as expected when set at the loader prompt (Boot menu -> Escape to loader prompt).
> 
> ...


Yes setting from loader prompt is working but from the loader.env it is not.
 Will check in FreeBSD 13.1. Thanks


----------



## kavitakr (Jun 20, 2022)

T-Daemon said:


> Indeed, I've checked in a VirtualBox VM, 13.0-RELEASE-p11 seems not to read the disk environment from loader.env.
> 
> "currdev=" works as expected when set at the loader prompt (Boot menu -> Escape to loader prompt).
> 
> ...


T-Daemon Like you said works well in  13.1-RELEASE,   I did copy the loader from  13.1-RELEASE to  13.0-RELEASE but I dont see currdev /rootdev being respected. Ideally the changes should have gone in loader, why it is still not working ? Any suggestions what all to copy to make it work


----------



## T-Daemon (Jun 20, 2022)

kavitakr said:


> I did copy the loader from 13.1-RELEASE to 13.0-RELEASE ...


I assume you copied the loader to efi/boot/bootx64.efi.  Is there a efi/freebsd/loader.efi UEFI kernel loader?

If there is, change the loader there to  v13.1 as well.

Also, are there UEFI boot entries? If there are, check the FreeBSD entries kernel loader path (`efibootmgr -v`), it should point to /efi/boot/bootx64.efi. If that's not the case, delete the entry, create a new one.


----------



## T-Daemon (Jun 23, 2022)

If somebody stumbles over this thread looking for a solution to a same or similar case, there is a better solution than discussed above, set `currdev=` in /boot/loader.conf, no matter if BIOS or UEFI.

loader(8):

```
currdev   Selects the default device to loader the kernel from.  The
               syntax is:
                     loader_device:
               or
                     zfs:dataset:
               Examples:
                     disk0p2:
                     zfs:zroot/ROOT/default:
```
(loader_device -> UFS2)

See also post on thread setting root filesystem in kernel .


----------

