Creating a bootable USB drive from an .iso file for Ultimate Boot CD (UBCD, not UBCD Live)

Source file: ubcd538.iso from https://www.ultimatebootcd.com/download.html

On Windows, I can get a good end result with Rufus.

On FreeBSD, I'm struggling.

I tried gdd, for example:

Code:
root@momh167-gjp4-8570p:~ # gpart show /dev/da0
gpart: No such geom: /dev/da0.
root@momh167-gjp4-8570p:~ # time gdd if=/home/grahamperrin/Documents/IT/UBCD/ubcd538.iso of=/dev/da0 bs=10M conv=sync status=progress
734003200 bytes (734 MB, 700 MiB) copied, 110 s, 6.7 MB/s
69+1 records in
70+0 records out
734003200 bytes (734 MB, 700 MiB) copied, 110.053 s, 6.7 MB/s
0.000u 1.566s 1:50.08 1.4%      97+171k 5570+5600io 2pf+0w
root@momh167-gjp4-8570p:~ # gdisk /dev/da0
GPT fdisk (gdisk) version 1.0.4

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): p
Disk /dev/da0: 3913728 sectors, 1.9 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): BA51C333-76EB-4B92-BBA4-DCB5163954F2
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 3913694
Partitions will be aligned on 2048-sector boundaries
Total free space is 3913661 sectors (1.9 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): q
root@momh167-gjp4-8570p:~ #

– the resulting drive is not bootable.

I see this, from a 2016 topic about attempts to write a FreeBSD ISO to a flash drive:

ISO9660 CD images use 2K blocks and have a special filesystem. Some computers can boot from those images when they are copied to a flash drive, but not all. Converting an ISO9660 image to a real hard drive/flash drive image is much more complicated. …

– is that advice specific to images for FreeBSD, or is it equally complicated to convert images such as ubcd538.iso?

Might the conversion routine be something like this?

TIA
 
According to https://www.ultimatebootcd.com/forums/viewtopic.php?t=2405#p9172

inside the ISO file there is a shell script /ubcd/tools/linux/ubcd2iso/ubcd2iso.sh

Code:
#!/bin/bash
#
# Create a bootable UBCD ISO image
#
# Ultimate Boot CD (UBCD): http://www.ultimatebootcd.com/
# The Syslinux Project: http://syslinux.zytor.com
#
# Made by Gert Hulselmans
#
# Last time edited: 8 July 2009

# Define VOLUME_ID (LABEL) of the iso
VOLUME_ID="UBCD538"

# Define ISO filename (can be overridden by passing arguments to the script)
ISO_FILENAME="ubcd538-custom.iso"

echo
echo 'UBCD2ISO: Creating bootable UBCD ISO image ...'
echo

# Check how many arguments are passed to the script
case "${#@}" in
    0)
        ROOT_OF_ISO_PATH=`cd "$(dirname "$0")/../../../../"; echo "${PWD}"`
        ISO_FILENAME=`echo "${ROOT_OF_ISO_PATH%/*}/${ISO_FILENAME}"`

        echo '  USAGE: ubcd2iso.sh [path-to-extracted-UBCD-iso] [new-ubcd.iso]'
        echo
        echo '  Example: ubcd2iso.sh ~/ubcd-extracted/ ~/ubcd50-custom.iso'
        echo "             UBCD extracted to '~/ubcd-extracted/',"
        echo "             ISO image written to '~/ubcd50-custom.iso'"
        echo
        echo 'UBCD2ISO: No arguments are given, use default values.'
        echo
        ;;
    1)
        if [ "${1:0:1}" == '~' ]; then
            ROOT_OF_ISO_PATH="`echo ~`"${1:1}""
        else
            ROOT_OF_ISO_PATH="$1"
        fi

        if [ -d "$ROOT_OF_ISO_PATH" ]; then
            ROOT_OF_ISO_PATH=`cd "$ROOT_OF_ISO_PATH"; echo "${PWD}"`
            ISO_FILENAME=`echo "${ROOT_OF_ISO_PATH%/*}/${ISO_FILENAME}"`
        else
            ROOT_OF_ISO_PATH=''
            echo "UBCD2ISO ERROR: \"$1\" isn't a directory."
        fi
        ;;
    2)
        if [ "${1:0:1}" == '~' ]; then
            ROOT_OF_ISO_PATH="`echo ~`"${1:1}""
        else
            ROOT_OF_ISO_PATH="$1"
        fi

        if [ -d "$ROOT_OF_ISO_PATH" ]; then
            ROOT_OF_ISO_PATH=`cd "$ROOT_OF_ISO_PATH"; echo "${PWD}"`
        else
            ROOT_OF_ISO_PATH=''
            echo "UBCD2ISO ERROR: \"$1\" isn't a directory."
        fi

        if [ "${2:0:1}" == '~' ]; then
            ISO_FILENAME="`echo ~`"${2:1}""
        else
            ISO_FILENAME="$2"
        fi

        if [ -d `cd "/${ISO_FILENAME%/*}" /dev/null 2>&1; echo "${PWD}"` ]; then
            ISO_FILENAME=`cd "/${ISO_FILENAME%/*}" /dev/null 2>&1; echo "${PWD}/${ISO_FILENAME##*/}"`
            ISO_FILENAME=`echo "${ISO_FILENAME/\/\///}"`
        else
            echo "UBCD2ISO ERROR: '${ISO_FILENAME%/*}' isn't a directory."
            echo "                '${ISO_FILENAME}' could not be created."
        fi
        ;;
esac

# save IFS
SAVED_IFS=$IFS

# Poor man's 'which' command
MKISOFS=''
IFS=:
for i in $PATH ; do
    if [ -x "$i/mkisofs" ] ; then
        MKISOFS="$i/mkisofs"
        break
    fi
done

# Restore IFS
IFS=$SAVED_IFS

if [[ -n "$MKISOFS" && -n "$ROOT_OF_ISO_PATH" ]]; then
    if [ -f "${ROOT_OF_ISO_PATH}/boot/syslinux/isolinux.bin" ]; then
        rm -f "${ROOT_OF_ISO_PATH}/boot/syslinux/boot.catalog"
        rm -fR "${ROOT_OF_ISO_PATH}/[BOOT]/"
        rm -fR "${ROOT_OF_ISO_PATH}/boot.images/"

        # mkisofs manpage: http://linux.die.net/man/8/mkisofs
        #
        # -iso-level 4: Required for Win2K/XP booting to work
        # -l: Allow full 31 character ISO9660 filenames
        # -r: Rock Ridge Interchange Protocol allows Unix long filenames up to 255 bytes
        # -J -joliet-long: Joliet extension allows Windows long filenames up to 103 Unicode chars
        # -D: Disable deep directory relocation
        #
        # Note: UBCD2ISO_ARGS is used to pass user-specific arguments to mkisofs without modifying the script
        "$MKISOFS" -iso-level 4 -l -r -J -joliet-long -D -V "${VOLUME_ID}" \
          -o "${ISO_FILENAME}" -b "boot/syslinux/isolinux.bin" -c "boot/syslinux/boot.catalog" \
          -hide "boot/syslinux/boot.catalog" -hide-joliet "boot/syslinux/boot.catalog" \
          $UBCD2ISO_ARGS -no-emul-boot -boot-load-size 4 -boot-info-table "${ROOT_OF_ISO_PATH}"
        if [ "$?" -eq "0" ]; then
            echo
            echo "UBCD2ISO: '${ISO_FILENAME}' was successfully created."
        else
            echo
            echo "UBCD2ISO ERROR: Something went wrong, while creating '${ISO_FILENAME}'".
        fi
    else
        echo "UBCD2ISO ERROR: '${ROOT_OF_ISO_PATH}/boot/syslinux/isolinux.bin' could not be found."
        echo '                Check that you have given the correct path to the extracted UBCD iso.'
    fi
elif [ -z "$MKISOFS" ]; then
    echo "UBCD2ISO ERROR: The 'mkisofs' program could not be found. Install it and try again."
fi

echo

I couldn't say whether this would work on FreeBSD, but I may give it a try out of interest.
 
Thanks, as far as I can tell /ubcd/tools/linux/ubcd2iso/ubcd2iso.sh is essentially to produce a customised .iso (the script uses mkisofs() and so on) … this will be useful because (looking ahead) I do want to customise but for now:
  • my stumbling block is creation of a bootable USB flash drive from non-customised 5.3.8.
I did try sysutils/unetbootin but re: PR 239344 it's impossible to select a USB flash drive.

Thanks to your hint I found a nearby file,

/ubcd/tools/linux/ubcd2usb/readme.txt

– the content of which is fairly self-explanatory.

Some it's not applicable with FreeBSD (e.g. use of mkfs.vfat) but I'll probably find my way around without too much difficulty. Fingers crossed …
 
From /ubcd/tools/linux/ubcd2usb/readme.txt:

4. Now, we write the syslinux mbr to the USB drive.
The mbr.bin file is located in ./ubcd/tools/linux/ubcd2usb/ of the extracted UBCD iso.

dd if=mbr.bin of=/dev/sdX (replacing X with your USB key drive letter)

I got an Invalid argument response:

Code:
root@momh167-gjp4-8570p:~ # dd if=/usr/home/grahamperrin/Documents/IT/UBCD/ubcd538/ubcd/tools/linux/ubcd2usb/mbr.bin of=/dev/da0
dd: /dev/da0: Invalid argument
0+1 records in
0+0 records out
0 bytes transferred in 0.000480 secs (0 bytes/sec)
root@momh167-gjp4-8570p:~ #

– so I tried adding conv=sync but this invalidates the partition table.

A transcript:

Code:
root@momh167-gjp4-8570p:~ # gdisk /dev/da0
GPT fdisk (gdisk) version 1.0.4

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): z
b       back up GPT data to a file
c       change a partition's name
d       delete a partition
i       show detailed information on a partition
l       list known partition types
n       add a new partition
o       create a new empty GUID partition table (GPT)
p       print the partition table
q       quit without saving changes
r       recovery and transformation options (experts only)
s       sort partitions
t       change a partition's type code
v       verify disk
w       write table to disk and exit
x       extra functionality (experts only)
?       print this menu

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/da0. Proceed? (Y/N): y
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y
root@momh167-gjp4-8570p:~ # fdisk-linux /dev/da0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-243, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-243, default 243):
Using default value 243

Command (m for help): a
Partition number (1-4): 1

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): e
Changed system type of partition 1 to e (Win95 FAT16 (LBA))

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
root@momh167-gjp4-8570p:~ # fdisk-linux -l /dev/da0

Disk /dev/da0: 2003 MB, 2003828736 bytes
255 heads, 63 sectors/track, 243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot    Start       End    Blocks   Id  System
/dev/da0s1   *         1       243   1951866    e  Win95 FAT16 (LBA)
root@momh167-gjp4-8570p:~ # gpart show /dev/da0
=>     63  3913665  da0  MBR  (1.9G)
       63  3903732    1  !14  [active]  (1.9G)
  3903795     9933       - free -  (4.8M)

root@momh167-gjp4-8570p:~ # dd if=/usr/home/grahamperrin/Documents/IT/UBCD/ubcd538/ubcd/tools/linux/ubcd2usb/mbr.bin of=/dev/da0 conv=sync
0+1 records in
1+0 records out
512 bytes transferred in 0.062670 secs (8170 bytes/sec)
root@momh167-gjp4-8570p:~ # fdisk-linux -l /dev/da0

Disk /dev/da0: 2003 MB, 2003828736 bytes
255 heads, 63 sectors/track, 243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/da0 doesn't contain a valid partition table
root@momh167-gjp4-8570p:~ #

Should I use a different dd command? mbr.bin is 440B in size.

Or should I ignore the instruction to write the syslinux mbr to the drive?
 
Any reason you feel the need to use the ISO, in particular? The usual way to build a bootable USB memdisk image is to grab the kernel and base tarballs on FreeBSD.org, or build the source yourself. Also - there's already a number of memdisk images available next to the ISO images for each revision, as I assume you know.

Edit : this is a Linux ISO? Wrong forum for that! Never mind.
 
ronaldlees - do you have more details on building a bootable USB image that you were alluding to? I am looking at:


My goal is to build a completely customized USB so I have everything installed/configured the way I want and can take that anywhere. So, install everything, make an ISO of that then use: fbsdinstall2usb to make the USB image?
 
Edit : this is a Linux ISO? Wrong forum for that! Never mind.

The nice thing about FreeBSD is that you can use tar() to extract files from an ISO.

I managed to extract mbr.bin from ubcd539.iso using:-
tar xf ubcd538.iso --strip 4 ubcd/tools/linux/ubcd2usb/mbr.bin

... not very intuitive and maybe there is an easier way...

I was also looking at a way of trying to pipe this file via stdout into dd but couldn't find a way altough there is a '-O' option available,
 
to the OP: have you tried with dd()? Like this # dd if=./ubcd538.iso of=/dev/da0 bs=4M (change da0 to whatever you usb stick shows up as).
 
to the OP: have you tried with dd()? Like this # dd if=./ubcd538.iso of=/dev/da0 bs=4M (change da0 to whatever you usb stick shows up as).
I just tried it....

Code:
dd if=ubcd538.iso of=/dev/da0 bs=4M
173+1 records in
173+1 records out
728922112 bytes transferred in 76.522643 secs (9525574 bytes/sec)

gpart show da0
gpart: No such geom: da0.

There's no partition on it so gpart doesn't see it, and it won't boot on another system because there is no MBR.
 
… have you tried with dd()? Like this …

Some of my earlier attempts were similar to that, yes, but I never tried 4 as the bs.

… it looks like FreeBSD's dd() needs a block size of 512 when writing to /dev/da0

– for the 440B file, yes?

Refocusing on the .iso, it's unfortunate that sysutils/unetbootin is unusable. I imagine that it'll have goodness similar to the goodness of Rufus.
 
There's no partition on it so gpart doesn't see it, and it won't boot on another system because there is no MBR.
Strange. Did you unplug and replug the usb stick after writing the file to it? Sometimes it is needed in order for geom to "re-taste" the disk..
What does sysutils/disktype think about your .iso file? do disktype ubcd538.iso and report what it tells you.
 
Code:
root@momh167-gjp4-8570p:~ # disktype /usr/home/grahamperrin/Documents/IT/UBCD/ubcd538.iso

--- /usr/home/grahamperrin/Documents/IT/UBCD/ubcd538.iso
Regular file, size 695.2 MiB (728922112 bytes)
ISO9660 file system
  Volume name "UBCD538"
  Application "GENISOIMAGE ISO 9660/HFS FILESYSTEM CREATOR (C) 1993 E.YOUNGDALE (C) 1997-2006 J.PEARSON/J.SCHILLING (C) 2006-2007 CDRKIT TEAM"
  Data size 695.2 MiB (728922112 bytes, 355919 blocks of 2 KiB)
  El Torito boot record, catalog at 151
    Bootable non-emulated image, starts at 152, preloads 2 KiB
      Platform 0x00 (x86), System Type 0x00 (Empty)
      ISOLINUX boot loader
  Joliet extension, volume name "<5542><4344><3533><3820><2020><2020><2020><2020><2020><2020><2020><2020><2020><2020><2020><2020>"
  Joliet extension, volume name "UBCD538"

root@momh167-gjp4-8570p:~ #

As indicated by balanga, there's no GPT so this –

gpart bootcode -b /usr/home/grahamperrin/Documents/IT/UBCD/ubcd538/ubcd/tools/linux/ubcd2usb/mbr.bin /dev/da0

– can run only after adding a GPT, but adding a GPT makes the device no longer mountable in e.g. Nemo.

Then if the GPT is zapped the ISO9660 file system becomes readable again, however I imagine that it'll be not entirely consistent.
 
Almost cracked it!!!!


Code:
#pkg install -y syslinux
#umount /mnt/ubcd
mkdir /tmp/ubcd.iso
cd /tmp/ubcd.iso
fetch -o - http://cdn.removed.us/ubcd/ubcd538.iso | tar xf -
gpart destroy -F da0
gpart create -s mbr da0
gpart add -t fat32 da0
gpart set -a active -i 1 da0
newfs_msdos -F32 /dev/da0s1
mkdir /mnt/ubcd
mount -t msdosfs /dev/da0s1 /mnt/ubcd
mkdir -p /mnt/ubcd/boot/syslinux
cp -R /tmp/ubcd.iso/boot/syslinux* /mnt/ubcd/boot
cp /tmp/ubcd.iso/ubcd/menus/syslinux/defaults.cfg  /mnt/ubcd
sed 's%/ubcd/menus/syslinux%%' /tmp/ubcd.iso/ubcd/menus/syslinux/main.cfg  >/mnt/ubcd/main.cfg
sed 's%/ubcd/menus/syslinux%%' /tmp/ubcd.iso/boot/syslinux/syslinux.cfg  >/mnt/ubcd/boot/syslinux/syslinux.cfg
cp /tmp/ubcd.iso/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr da0

# *********************************************************

#  THIS DOES NOT WORK WITH FreeBSD's syslinux    !!!!!!

####syslinux --install -s -f -d /boot/syslinux /dev/da0s1

# *********************************************************


umount /mnt/ubcd

This:-

syslinux --install -s -f -d /boot/syslinux /dev/sdX1

does work on Linux using the syslinux which comes with UBCD.

UBCD uses Syslinux v4.07. Is that available for FreeBSD?

NB this does not create the full set of applications which UBCD provides, it only boots to the initial screen. Adding the rest should just be a matter of copying the ubcd directory tree to the USB stick.
 
Slight change so that you can actually run some of the programs...
Code:
mkdir /tmp/ubcd.iso
cd /tmp/ubcd.iso
fetch -o - http://cdn.removed.us/ubcd/ubcd538.iso | tar xf -.
gpart destroy -F da0
gpart create -s mbr da0
gpart add -t fat32 da0
gpart set -a active -i 1 da0
newfs_msdos -F32 /dev/da0s1
mkdir /mnt/ubcd
mount -t msdosfs /dev/da0s1 /mnt/ubcd
cp -R /tmp/ubcd.iso/  /mnt/ubcd/
cp /tmp/ubcd.iso/ubcd/tools/linux/ubcd2usb/mbr.bin mbr
dd if=/dev/zero of=mbr seek=440 bs=1 count=72
gpart bootcode -b mbr da0

# *********************************************************

#  THIS DOES NOT WORK WITH FreeBSD's syslinux    !!!!!!

####syslinux --install -s -f -d /boot/syslinux /dev/da0s1

umount /mnt/ubcd


#  syslinux (v4.07) from the UBCD pkg needs to be run on this USB stick under Linux

####syslinux --install -s -f -d /boot/syslinux /dev/sdX1


# *********************************************************
 
Back
Top