# Multiboot USB allowing installation of various FreeBSD versions



## balanga (Aug 15, 2019)

Here is a script to create a Multiboot USB which has options for installing various versions of FreeBSD along with booting already installed versions. The script is work-in-progress and more options can easily be added.


```
pkg install -y grub2
gpart destroy -F da0
gpart create -s gpt da0
gpart add -t freebsd-boot -l MBboot -b 40 -s 512k da0
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0

gpart add -t freebsd-ufs -l 12.0-RELEASE-amd64-rootfs -s 2G da0
newfs /dev/da0p2
mkdir /mnt/mb
mount /dev/da0p2 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/base.txz | tar xSf -
fetch -o - https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/kernel.txz | tar xSf -
echo '/dev/da0p2 / ufs rw 1 1' > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 12.0-RELEASE-i386-rootfs -s 2G da0
newfs /dev/da0p3
mkdir /mnt/mb
mount /dev/da0p3 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/i386/12.0-RELEASE/base.txz | tar xSf -
fetch -o - https://download.freebsd.org/ftp/releases/i386/12.0-RELEASE/kernel.txz | tar xSf -
echo '/dev/da0p3 / ufs rw 1 1' > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 12.0-RELEASE-amd64-installation -s 1G da0
newfs /dev/da0p4
mount /dev/da0p4 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.0/FreeBSD-12.0-RELEASE-amd64-bootonly.iso | tar zxf -
echo '/dev/da0p4 / ufs rw 1 1' > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 9.3-RELEASE-i386-installation -s 1G da0
newfs /dev/da0p5
mount /dev/da0p5 /mnt/mb
cd /mnt/mb
fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/i386/ISO-IMAGES/9.3/FreeBSD-9.3-RELEASE-i386-bootonly.iso | tar zxf -
echo '/dev/da0p5 / ufs rw 1 1' > etc/fstab
cd ..
umount /mnt/mb

gpart add -t bios-boot -s 500K da0
mount /dev/da0p2 /mnt/mb
grub-install --root-directory=/mnt/mb /dev/da0
cat <<_GRUB_CFG >>/mnt/mb/boot/grub/grub.cfg

set timeout=10

set default 0

set menu_color_normal=white/black
set menu_color_highlight=white/cyan

menuentry "FreeBSD 12.0-RELEASE amd64" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,2)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 12.0-RELEASE i386" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,3)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 12.0-RELEASE amd64 installation" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,4)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 9.3-RELEASE i386 installation" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,5)
    kfreebsd /boot/loader
}

_GRUB_CFG

cd
umount /mnt/mb
rmdir /mnt/mb
```


Any feedback welcomed.


----------



## balanga (Aug 17, 2019)

```
pkg install -y grub2
USB=da0
gpart destroy -F $USB
gpart create -s gpt $USB
gpart add -t bios-boot -l Grub -s 128K $USB

gpart add -t freebsd-ufs -l 12.0-RELEASE-amd64-rootfs -s 2G $USB
newfs /dev/${USB}p2
mkdir /mnt/mb
mount /dev/${USB}p2 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/base.txz | tar xSf -
fetch -o - https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/kernel.txz | tar xSf -
echo "/dev/${USB}p2 / ufs rw 1 1" > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 12.0-RELEASE-i386-rootfs -s 2G $USB
newfs /dev/${USB}p3
mkdir /mnt/mb
mount /dev/${USB}p3 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/i386/12.0-RELEASE/base.txz | tar xSf -
fetch -o - https://download.freebsd.org/ftp/releases/i386/12.0-RELEASE/kernel.txz | tar xSf -
echo "/dev/${USB}p3 / ufs rw 1 1" > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 12.0-RELEASE-amd64-installation -s 1G $USB
newfs /dev/${USB}p4
mount /dev/${USB}p4 /mnt/mb
cd /mnt/mb
fetch -o - https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.0/FreeBSD-12.0-RELEASE-amd64-bootonly.iso | tar zxf -
echo "/dev/${USB}p4 / ufs rw 1 1" > etc/fstab
cd ..
umount /mnt/mb

gpart add -t freebsd-ufs -l 9.3-RELEASE-i386-installation -s 1G $USB
newfs /dev/${USB}p5
mount /dev/${USB}p5 /mnt/mb
cd /mnt/mb
fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/i386/ISO-IMAGES/9.3/FreeBSD-9.3-RELEASE-i386-bootonly.iso | tar zxf -
echo "/dev/${USB}p5 / ufs rw 1 1" > etc/fstab
cd ..
umount /mnt/mb

mount /dev/${USB}p2 /mnt/mb
grub-install --root-directory=/mnt/mb /dev/$USB
cat <<_GRUB_CFG >>/mnt/mb/boot/grub/grub.cfg

set timeout=10

set default 0

set menu_color_normal=white/black
set menu_color_highlight=white/red

menuentry "FreeBSD 12.0-RELEASE amd64" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,2)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 12.0-RELEASE i386" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,3)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 12.0-RELEASE amd64 installation" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,4)
    kfreebsd /boot/loader
}

menuentry "FreeBSD 9.3-RELEASE i386 installation" {
    insmod part_gpt
    insmod ufs2
    set root=(hd0,5)
    kfreebsd /boot/loader
}

_GRUB_CFG

cd
umount /mnt/mb
rmdir /mnt/mb
```
Just a quick change since the freebsd-boot partition is not really required. Also the variable USB introduced so that the user can easily change the name of the target USB device.


----------



## badbrain (Aug 19, 2019)

I tried to search for `grub2` on freshports.org but found nothing but sysutils/grub2-bhyve. I can only locate sysutils/grub2 with the help of Google. It turns out sysutils/grub2 is deprecated. How could you install a binary package of it? `pkg` doesn't found any `grub2` package at all.


----------



## balanga (Aug 19, 2019)

I just ran `pkg install grub2` and it was located. I thought maybe it had been removed in the last couple of weeks, but it is still there. Which version of FreeBSD are your running? I have 12.0-RELEASE amd64.


----------



## Alain De Vos (Aug 19, 2019)

grub2 compiles without error.  Weird there is no maintainer.
Question : Are there other options then using grub ?


----------



## itstmyi (Nov 22, 2019)

I have the same problem . sysutils/grub2 is deprecated in latest FreeBSD R12.1 . If I choose a non-UEFI installation , I have to run "gpart bootcode -b /boot/boot0 ada0" to support multi-boot . Any better solutions ?


----------

