Solved Cannot install BIOS and/or efi bootcode

Greetings all,

I seem to have a problem as per the subject line. Since I need to install the bootcode on a USB flash drive, I have the following code running from a shell:
Code:
#!/bin/sh
# Instal bootloader only on flash drive (da*)

# Set boot disk:
DISK="da0"

echo "Destroying old partitions on the destination drive"
gpart destroy -F $DISK

# Create the gpt structure on the drive for both BIOS and UEFI boot.
echo "Partitioning the destination drive using gpt"
gpart create -s gpt $DISK
gpart add -t freebsd-boot -l gpboot  -b 40 -s 512K  $DISK
echo "Writing BIOS bootcode"
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK

gpart add -t efi -l efiboot -a 4k -s 200M $DISK

# Format the efi partition to hold the the small MS-DOS efifilesystem for UEFI bootcode.
echo "Preparing the efi partition"
newfs_msdos -F 32 -c 1 $DISKp2
mount -t msdosfs $DISKp2 /tm
mkdir -p /tmp/EFI/BOOT

# Copy the FreeBSD /boot/loader.efi bootcode file into the efi filesystem.
echo "Copying loader.efi"
cp /boot/loader.efi /tmp/EFI/BOOT/BOOTx64.efi

umount /mnt

echo "Script finished"

The first problem is an error:
Code:
gpart: /boot/gptzfsboot: Device not configured

The second is similar:
Code:
cp /boot/loader.efi: Device not configured

It seems that I am following wiki:
(1) https://wiki.freebsd.org/UEFI
(2) https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot

I do not believe that anything is misspelled, so I do not know what the problem may be.

Kindest regards,

M
 
Don't mount over /tmp though, it's actually in use on a running system. You could get some weird results. Use /mnt for temporary mounts, that's what it's for.

As for the errors, make sure da0 is the correct drive.
 
Code:
gpart add -t freebsd-boot -l gpboot -b 40 -s 512K $DISK
Not important, but there's a typo here too. The label is supposed to be named gptboot. Although that shouldn't cause any problems as you're not actually using the label anywhere.
 
Code:
newfs_msdos -F 32 -c 1 $DISKp2

Tried your code on my computer, variable $DISKp2 is misinterpreted by the shell (or maybe working as intended :)) , i.e. doesn't concatenate the string as expected. Had to replace it with: $DISK"p2"

Code:
mount -t msdosfs $DISKp2 /tm

Furthermore, mount expects a full path, so replace $DISKp2 with "/dev/"$DISK"p2"
 
Hi Remy,

thank you for pointing out the errors. Yes, originally, the script used /mnt. But upon running it, I received an error
Code:
umount: /mnt: not a file system or root directory

, so I re-read the FreeBSD install documents and it stated that /mnt/, /tmp, /var are mountable, writable, and readable. So, I - obviously only partially - changed it, due to my tiredness of not being able to install.

Hi SirDice,

thank you for your response. Regarding the error in the "gplabel", I though that I can use any term for labeling. However, I looked at some other documents, and yes, most of themuse the term "gptlabel", which makes sense, so I will correct it.

Regarding using /mnt, I can, of course, change it back. da0 is definitely a correct drive.

Thank you for the correct variable concatenation.

Hi Misirca,

thank you for catching the error and suggesting the correction.

On a different note, the script corrected in accordance with your suggestions now works, so now onto installing the OS onto an NVMe drive and attempting to make the installation work.

Thank you all once again.

Kindest regards,

M
 
Corrected and edited code file from above
Code:
#!/bin/sh
# Install bootloader only on flash drive (da*)

# Set boot disk:
DISK="da9"
echo "Destroying old partitions on the destination drive /dev/${DISK}  !!  Are you sure? Ctrl-c to exit now!  "
sleep 12
gpart destroy -F $DISK

# Create the gpt structure on the drive for both BIOS and UEFI boot.
echo "Partitioning the destination drive /dev/${DISK} using gpt"
gpart create -s gpt $DISK
gpart add -t freebsd-boot -l gptboot  -b 40 -s 512K  $DISK
echo "Writing BIOS bootcode"
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK

gpart add -t efi -l efiboot -a 4k -s 200M $DISK

# Format the efi partition to hold the the small MS-DOS efi filesystem for UEFI bootcode.
echo "Preparing the efi partition"
newfs_msdos -F 32 -c 1 "/dev/${DISK}p2"
mkdir /mnt/tmp2
mount -t msdosfs  "/dev/${DISK}p2" /mnt/tmp2
mkdir -p /mnt/tmp2/EFI/BOOT

# Copy the FreeBSD /boot/loader.efi bootcode file into the efi filesystem.
echo "Copying loader.efi"
cp /boot/loader.efi /mnt/tmp2/EFI/BOOT/BOOTX64.EFI

umount /mnt/tmp2

echo "Script finished.  /mnt/tmp2 unmounted"

diskinfo -v da9
diskinfo -v da9p2

Other newfs_msdos parameters for 4K SSD drive

usage: newfs_msdos [ -options ] special [disktype]
where the options are:
-@ Offset in device
-A Attempt to cluster align root directory
-B Bootstrap file
-C Create file
-F FAT type (12, 16, or 32)
-I Volume ID
-L Volume Label
-N Don't create filesystem, print params only
-O OEM string
-S Bytes per sector
-T Timestamp
-a Sectors per FAT
-b Block size
-c Sectors per cluster
-e Directory entries
-f Standard format floppies (160,180,320,360,640,720,1200,1232,1440,2880)
-h Drive heads
-i Info sector
-k Backup sector
-m Media descriptor
-n Number of FATs
-o Hidden sectors
-r Reserved sectors
-s File System size
-u Sectors per track

Using different cluster sizes: 1 or4 or 8
fred@fredTC93-pc /media [1]> newfs_msdos -F 32 -c 1 -L ESP -N /dev/da1p1
/dev/da1p1: 10324368 sectors in 10324368 FAT32 clusters (512 bytes/cluster)
BytesPerSec=512 SecPerClust=1 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=10485720 FATsecs=80660 RootCluster=2 FSInfo=1 Backup=2
fred@fredTC93-pc /media> newfs_msdos -F 32 -S 512 -c 4 -L ESP -N /dev/da1p1
/dev/da1p1: 10444884 sectors in 2611221 FAT32 clusters (2048 bytes/cluster)
BytesPerSec=512 SecPerClust=4 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=10485720 FATsecs=20401 RootCluster=2 FSInfo=1 Backup=2

fred@fredTC93-pc /media> newfs_msdos -F 32 -S 512 -c 8 -L ESP -N /dev/da1p1
/dev/da1p1: 10465248 sectors in 1308156 FAT32 clusters (4096 bytes/cluster)
BytesPerSec=512 SecPerClust=8 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=10485720 FATsecs=10220 RootCluster=2 FSInfo=1 Backup=2
fred@fredTC93-pc /media>


newfs_msdos -F 32 -S 512 -c 8 -L ESP /dev/da1p1
/dev/da1p1: 10465248 sectors in 1308156 FAT32 clusters (4096 bytes/cluster)
BytesPerSec=512 SecPerClust=8 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=10485720 FATsecs=10220 RootCluster=2 FSInfo=1 Backup=2
 
A couple very good scripts, I came across for using a USB Flash drive to perform a root installation on an empty SSD drive. Check the links below for the original scripts and source explanations: Fred Finster

ZFS FreeBSD Root Install script for a USB Flash drive.
https://calomel.org/zfs_freebsd_root_install.html
https://calomel.org/zfs.sh

using the memstick image and a script to do a root ZFS install​

ZFS on FreeBSD is an incredible file system. It is fast, secure and flexible which makes it a pleasure to use. One of the current limitations when installing FreeBSD 9 is you can not install the OS to a ZFS root pool from inside the default installer. Using the guide from aisecure we were able to get the ZFS root install working by manually typing commands. What we really wanted was the script on the FreeBSD 9 install media. Our goal was to boot the install media, execute the script and have the script do the FULL FreeBSD install for us without user intervention. We are happy to say we have a solution.

On this page we are going to take a look at the script itself and then explain the simplest method we found to install a FreeBSD memstick image to a USB key and run our install script from the key. At that point you can complete a full install of FreeBSD on a ZFS root in around 2 minutes. Speed is neat, but the real advantage is you can do an install, play with the image for a while and re-install without worrying about wasting a lot of time reinstalling. Lets take a look at the script first.

ZFS Root Install Script for FreeBSD 12.0​

You can copy and paste the following script if you like or download the same script from calomel.org : zfs.sh. The script is called "zfs.sh", but you can use any name you wish. Make sure to set the file to be executable or use "sh zfs.sh" to execute. We commented every section so take a look at the script before using it and make any changes you feel necessary for your environment. After this section we explain how to do the memstick install and how to use the fully operational memory USB stick.




ZFS Health Check and Status​

monitor for degraded or over capacity volumes and disk errors​

ZFS on FreeBSD is one of the best file systems we have ever used. But, once we setup the machine we asked the same question every other ZFS admin has asked themselves. How do we tell when there is a problem with our ZFS volumes? To monitor the ZFS filesystems we wrote the following shell script.

The ZFS Health shell script will use standard zpool arguments to look at the state of the volumes and drives. We currently check for the following default conditions:

https://calomel.org/zfs_health_check_script.html
 
Back
Top