# Create a bootable UBCD USB stick using FreeBSD



## balanga (Jul 28, 2019)

Here it is...  my attempt to create a UBCD bootable USB stick using FreeBSD, should you ever want to...
You may want to change the variables UBCDDIR - (UBCD work directory),  UBCDSRC - (source location for ISO), USB (USB device)


```
export UBCDDIR="/tmp/ubcd.iso"
export UBCDSRC="http://cdn.removed.us/ubcd/ubcd538.iso"
export USB="da0"
if ! [ -d $UBCDDIR ]; then
  mkdir $UBCDDIR
fi
cd $UBCDDIR
if ! [ -d $UBCDDIR/boot ]; then
  fetch -o - $UBCDSRC | tar xf -.
fi
gpart destroy -F $USB
gpart create -s mbr $USB
gpart add -t fat32 $USB
gpart set -a active -i 1 $USB
newfs_msdos -F32 /dev/${USB}s1
mkdir /mnt/ubcd
mount -t msdosfs /dev/${USB}s1 /mnt/ubcd
cp -R $UBCDDIR/  /mnt/ubcd/
cp $UBCDDIR/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr $USB
umount /mnt/ubcd
rmdir /mnt/ubcd
if ! [ -f $UBCDDIR/bin/syslinux ]; then
  fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/9.1-RELEASE/packages/All/syslinux-4.05.tbz | tar jxf -
fi
$UBCDDIR/bin/syslinux --install -s -f -d /boot/syslinux /dev/${USB}s1
```


----------



## grahamperrin@ (Jul 28, 2019)

If I use sysutils/diskimage-tools with a previously downloaded .iso e.g. 

`mount_image cd9660 /home/grahamperrin/Documents/IT/UBCD/ubcd538.iso /media/ubcd`

– then what variable should I set for `UBCDSRC`?


----------



## balanga (Jul 28, 2019)

The script is meant to *retrieve* and *extract* the iso.

If you already have the *iso* on your disk change the *export UBCDSRC * line to point at the appropriate location on your filesystem like so:-


```
export UBCDSRC="file:///tmp/ubcd538.iso"
```


----------



## balanga (Jul 28, 2019)

Just added the ability to boot FreeBSD from a bootable UBCD USB stick!

There is now an option to boot mfsBSD from UBCD. login is *root* password is *mfsroot*


```
[*][X]
export UBCDDIR="/tmp/ubcd.iso"
export UBCDSRC="http://cdn.removed.us/ubcd/ubcd538.iso"
export USB="da0"
if ! [ -d $UBCDDIR ]; then
  mkdir $UBCDDIR
fi
cd $UBCDDIR
if ! [ -d $UBCDDIR/boot ]; then
  fetch -o - $UBCDSRC | tar xf -.
fi
gpart destroy -F $USB
gpart create -s mbr $USB
gpart add -t fat32 $USB
gpart set -a active -i 1 $USB
newfs_msdos -F32 /dev/${USB}s1
mkdir /mnt/ubcd
mount -t msdosfs /dev/${USB}s1 /mnt/ubcd

# add mfsBSD

fetch -o mfsbsd.iso https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-mini-12.0-RELEASE-amd64.iso

chmod +w $UBCDDIR/ubcd/menus/syslinux/main.cfg
sed -i '' '7 i\
LABEL mfsBSD\
MENU LABEL ^mfsBSD\
   kernel memdisk\
   initrd /mfsbsd.iso\
   append iso raw\
   '  $UBCDDIR/ubcd/menus/syslinux/main.cfg

cp -R $UBCDDIR/  /mnt/ubcd/
cp $UBCDDIR/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr $USB
umount /mnt/ubcd
rmdir /mnt/ubcd
if ! [ -f $UBCDDIR/bin/syslinux ]; then
  fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/9.1-RELEASE/packages/All/syslinux-4.05.tbz | tar jxf -
fi
$UBCDDIR/bin/syslinux --install -s -f -d /boot/syslinux /dev/${USB}s1
```


----------



## Alain De Vos (Jul 29, 2019)

What is the advantage of using version syslinux-4.05 instead of syslinux-6.03 ?


----------



## grahamperrin@ (Jul 29, 2019)

`fetch -o - $UBCDSRC | tar xf -.`

Missing white space at the tail there?



Alain De Vos said:


> What is the advantage of using version syslinux-4.05 instead of syslinux-6.03 ?



I'm curious, too. 

I see that the original .iso uses 4.07 in places, 


```
root@momh167-gjp4-8570p:~ # mount_image cd9660 /home/grahamperrin/Documents/IT/UBCD/ubcd538.iso /media/ubcd
Be sure to unmount using umount_image, not umount, or the memory disk
will not be detached.
root@momh167-gjp4-8570p:~ # find /media/ubcd -name "syslinux*" | grep usb
/media/ubcd/ubcd/tools/linux/ubcd2usb/syslinux
/media/ubcd/ubcd/tools/linux/ubcd2usb/syslinux64
/media/ubcd/ubcd/tools/win32/ubcd2usb/syslinux.exe
root@momh167-gjp4-8570p:~ # strings /media/ubcd/ubcd/tools/linux/ubcd2usb/syslinux | grep 4.0
%s 4.07  Copyright 1994-2013 H. Peter Anvin et al
MSWIN4.0
SYSLINUX 4.07
SYSLINUX 4.07 2013-07-25
MSWIN4.0
root@momh167-gjp4-8570p:~ # strings /media/ubcd/ubcd/tools/linux/ubcd2usb/syslinux64 | grep 4.0
%s 4.07  Copyright 1994-2013 H. Peter Anvin et al
MSWIN4.0
SYSLINUX 4.07
SYSLINUX 4.07 2013-07-25
MSWIN4.0
root@momh167-gjp4-8570p:~ # strings /media/ubcd/ubcd/tools/win32/ubcd2usb/syslinux.exe | grep 4.0
SYSLINUX 4.07
SYSLINUX 4.07 2013-07-25
MSWIN4.0
%s 4.07  Copyright 1994-2013 H. Peter Anvin et al
MSWIN4.0
root@momh167-gjp4-8570p:~ # umount_image /media/ubcd
root@momh167-gjp4-8570p:~ #
```


----------



## balanga (Jul 29, 2019)

Alain De Vos said:


> What is the advantage of using version syslinux-4.05 instead of syslinux-6.03 ?



 

You could try this and you'll see...

```
export UBCDDIR="/tmp/ubcd.iso"
export UBCDSRC="http://cdn.removed.us/ubcd/ubcd538.iso"
export USB="da0"
if ! [ -d $UBCDDIR ]; then
  mkdir $UBCDDIR
fi
cd $UBCDDIR
if ! [ -d $UBCDDIR/boot ]; then
  fetch -o - $UBCDSRC | tar xf -
fi
gpart destroy -F $USB
gpart create -s mbr $USB
gpart add -t fat32 $USB
gpart set -a active -i 1 $USB
newfs_msdos -F32 /dev/${USB}s1
mkdir /mnt/ubcd
mount -t msdosfs /dev/${USB}s1 /mnt/ubcd

# add mfsBSD & mfslinux

if ! [ -f $UBCDDIR/mfsbsd.iso ]; then
  fetch -o mfsbsd.iso https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-mini-12.0-RELEASE-amd64.iso
fi
if ! [ -f $UBCDDIR/mfslinux.iso ]; then
  fetch -o mfslinux.iso https://mfsbsd.vx.sk/files/iso/mfslinux/mfslinux-0.1.5-20a000a.iso
fi

chmod +w $UBCDDIR/ubcd/menus/syslinux/main.cfg
sed -i '' '7 i\
LABEL mfsBSD\
MENU LABEL ^mfsBSD\
   kernel memdisk\
   initrd /mfsbsd.iso\
   append iso raw\
\
LABEL mfslinux\
MENU LABEL ^mfslinux\
   kernel memdisk\
   initrd /mfslinux.iso\
   append iso raw\
   '  $UBCDDIR/ubcd/menus/syslinux/main.cfg


cp -R $UBCDDIR/  /mnt/ubcd/
cp $UBCDDIR/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr $USB
umount /mnt/ubcd
rmdir /mnt/ubcd
#if ! [ -f $UBCDDIR/bin/syslinux ]; then
#  fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/9.1-RELEASE/packages/All/syslinux-4.05.tbz | tar jxf -
#fi
#$UBCDDIR/bin/syslinux --install -s -f -d /boot/syslinux /dev/${USB}s1
pkg install -y syslinux
syslinux -V
syslinux --install -s -f -d /boot/syslinux /dev/${USB}s1
```


----------



## balanga (Jul 29, 2019)

grahamperrin said:


> `fetch -o - $UBCDSRC | tar xf -.`
> 
> Missing white space at the tail there?
> 
> ...



Not sure where that '.' came from but it shouldn't have been there.

I know UBCD uses syslinux 4.07 but I couldn't find a FreeBSD version of it - I did spend quite a while searching for it and 4.05 was the closest I found and fortunately it works.


----------



## balanga (Mar 15, 2021)

Just a quick update using a newer version of UBCD and mfsBSD.....

Remember to adjust the value of *$USB* to suit. 


```
export UBCDDIR="/tmp/ubcd.iso"
export UBCDSRC="http://cdn.removed.us/ubcd/ubcd539.iso"
export USB="da*"

gpart destroy -F $USB
gpart create -s mbr $USB
gpart add -t fat32 -s 1G $USB
gpart set -a active -i 1 $USB
newfs_msdos /dev/${USB}s1

if ! [ -d $UBCDDIR ]; then
  mkdir $UBCDDIR
fi
cd $UBCDDIR
if ! [ -d $UBCDDIR/boot ]; then
  fetch -o - $UBCDSRC | tar xf -
fi

mkdir /mnt/ubcd-usb
mount -t msdosfs /dev/${USB}s1 /mnt/ubcd-usb

# add mfsBSD

fetch -o mfsbsd.iso https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-mini-12.2-RELEASE-amd64.iso

chmod +w $UBCDDIR/ubcd/menus/syslinux/main.cfg
sed -i '' '7 i\
LABEL mfsBSD\
MENU LABEL ^mfsBSD\
   kernel memdisk\
   initrd /mfsbsd.iso\
   append iso raw\
   '  $UBCDDIR/ubcd/menus/syslinux/main.cfg


cp -R $UBCDDIR/  /mnt/ubcd-usb/
cp $UBCDDIR/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr $USB
umount /mnt/ubcd-usb
rmdir /mnt/ubcd-usb
if ! [ -f $UBCDDIR/bin/syslinux ]; then
  fetch -o - http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/9.1-RELEASE/packages/All/syslinux-4.05.tbz | tar jxf -
fi
$UBCDDIR/bin/syslinux --install -s -f -d /boot/syslinux /dev/${USB}s1
```


This works fine for a USB stick, although I'm hoping to adapt to it run from a partition on a multiboot drive eventually when I figure out how.


----------

