Solved How to restore EFI partition after replace disk

Hello everyone
I am new to zfs and i tried to build zfs mirror with 2 disks . All went Ok including resilvering and etc.. only problem comes when i pull one of the disks and server complains that it cant find efi bootable device. The disk wich i try to boot from has been deleted and resilvered i have done the partition table with
Code:
gpart backup /dev/ada0 > ada0.backup
gpart -F restore ada1 < ada0.backup

i have found this site where someone suggested this method to copy the efi partition

Code:
mkdir /mnt/ada0
newfs_msdos ada0p1
mount -t msdosfs /dev/ada0p1 /mnt/ada0
mkdir -p /mnt/ada0/efi/boot
cp /boot/boot1.efi /mnt/ada0/efi/boot/BOOTx64.efi
mkdir -p /mnt/ada0/boot
cat > /mnt/ada0/boot/loader.rc << EOF
unload
set currdev=zfs:sys/ROOT/default:
load boot/kernel/kernel
load boot/kernel/zfs.ko
autoboot
EOF

but is there any short method to copy the efi partition ??
 
You can copy it, but more important for you is to know, what kind of bootcode you boot from...
Then you are able to create it whenever you want and you learn how it works.

You just create a partition and add the appropriate bootcode using gpart.
Please post the output from gpart show (or gpart show -l if you use labels) and zpool status
 
Hello here is some info about the system:
Code:
# gpart show
=>        34  1953525101  ada0  GPT  (932G)
          34           6        - free -  (3.0K)
          40      409600     1  efi  (200M)
      409640        2008        - free -  (1.0M)
      411648     8388608     2  freebsd-swap  (4.0G)
     8800256  1944723456     3  freebsd-zfs  (927G)
  1953523712        1423        - free -  (712K)

=>        34  1953525101  ada1  GPT  (932G)
          34           6        - free -  (3.0K)
          40      409600     1  efi  (200M)
      409640        2008        - free -  (1.0M)
      411648     8388608     2  freebsd-swap  (4.0G)
     8800256  1944723456     3  freebsd-zfs  (927G)
  1953523712        1423        - free -  (712K)

after vanilla install of FreeBSD 10.4 i have pulled out ada0 and i have resilvered with new disk in place of ada0 :
Code:
zpool attach -f zroot ada1p3 ada0p3
zpool detach zroot 6101475656683286139

now this is the situation :

Code:
  pool: zroot
state: ONLINE
status: One or more devices has experienced an unrecoverable error.  An
    attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
    using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://illumos.org/msg/ZFS-8000-9P
  scan: resilvered 40K in 0h0m with 0 errors on Tue Apr 17 11:46:06 2018
config:

    NAME        STATE     READ WRITE CKSUM
    zroot       ONLINE       0     0     0
      mirror-0  ONLINE       0     0     0
        ada1p3  ONLINE       0     0     4
        ada0p3  ONLINE       0     0     0

i also tried to rewrite the boodcode of ada0 with this command :
Code:
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

but the result is that if i pull out ada1 and leave only ada0 the machine can't boot complaining about efi bootable device (only boots from ada1) . Please i appreciate any help on how to correct the boot partition
 
The gptzfsboot(8) is for the "traditional" boot (CSM) and should be written to a freebsd-boot partition. EFI boots differently, it uses the efi partition (which is actually FAT32). The easiest is to dd(1) the /boot/boot1.efifat file to it.

Edit: Fixed man page reference.
 
Thank you SirDice . Copying one boot partition over the other boot partition with dd did the trick,
 
Err, yes. I always mix up section 1 and 8 when I do it from the top of my head.
 
Back
Top