Other Converting ISO to img

  • img (Memory Stick Images): These are raw disk images designed specifically for USB flash drives (memory sticks). They contain an exact 1:1 sector-level copy of a bootable drive, including a partition table and a filesystem compatible with flash storage.
  • .iso (Optical Disc Images): These are images designed for CDs, DVDs, or virtual machines. They use the ISO 9660 filesystem standard. While recent FreeBSD amd64 ISOs are "hybrid" and can sometimes boot from USB, the .img format remains the most reliable for physical USB sticks.
Key Differences at a Glance
Feature .img (memstick).iso (CD/DVD)
Primary MediaUSB Flash Drives, SD CardsCDs, DVDs, Virtual Machines
Internal FormatRaw disk image with partition tableISO 9660 filesystem
VirtualizationHarder to use in some VM softwareStandard for most hypervisors
ContentTypically a "middle-ground" installerRanges from "bootonly" to full "dvd1"
Which one should you choose?
  • Use .img if you are installing on physical hardware from a USB thumb drive.
  • Use .iso if you are installing FreeBSD as a Virtual Machine (e.g., VirtualBox, VMware) or burning a physical DVD.
 
2. Third-Party Tools (Available via pkg or Ports)
You can install these using pkg install <toolname>.
  • xorriso: A powerful tool that can create, load, and manipulate ISO 9660 filesystems. It is the modern standard for creating bootable ISOs that also work on USB (hybrid ISOs).
  • ccd2iso: Specifically for converting .img files (in CloneCD format) into standard .iso files.
  • iat (Iso9660 Analyzer Tool): A multi-purpose tool used to detect and convert many image formats (like BIN, MDF, IMG) into ISO.
  • cdrtools: Includes mkisofs, the classic tool for generating ISO images from a directory of files.

3. Specialty Scripts
  • mfsBSD: A set of scripts available in the ports (sysutils/mfsbsd) that automates the creation of bootable FreeBSD images in both .iso and .img formats.
  • fbsd-install-iso2img.sh: A community-maintained shell script specifically designed to convert a standard FreeBSD installation ISO into a bootable USB image.

Summary Recommendation
  • To write to USB: Use dd. Most modern FreeBSD ISOs are "hybrid" and do not need conversion to work on a flash drive.
  • To create an ISO from files: Use xorriso or mkisofs.
  • To convert a specific .img to .iso: Try iat or ccd2iso.
 
ISO to IMG:
Code:
#!/bin/sh
# iso2img.sh - Converts a FreeBSD installation ISO to a bootable .img
# Usage: ./iso2img.sh input.iso output.img

if [ "$(id -u)" -ne 0 ]; then
    echo "Error: This script must be run as root."
    exit 1
fi

ISO_FILE=$1
IMG_FILE=$2

if [ -z "$ISO_FILE" ] || [ -z "$IMG_FILE" ]; then
    echo "Usage: $0 <input.iso> <output.img>"
    exit 1
fi

# 1. Mount the ISO via mdconfig
echo "Mounting ISO..."
MD_ISO=$(mdconfig -a -t vnode -f "$ISO_FILE")
mkdir -p ./iso_mnt
mount -t cd9660 /dev/"$MD_ISO" ./iso_mnt

# 2. Calculate required size and create a blank .img file
# Size is roughly ISO size + 50MB overhead
ISO_SIZE=$(stat -f %z "$ISO_FILE")
IMG_SIZE_MB=$(( (ISO_SIZE / 1024 / 1024) + 50 ))
echo "Creating ${IMG_SIZE_MB}MB blank image..."
dd if=/dev/zero of="$IMG_FILE" bs=1M count="$IMG_SIZE_MB" status=none

# 3. Configure the image as a disk and partition it
MD_IMG=$(mdconfig -a -t vnode -f "$IMG_FILE")
gpart create -s mbr /dev/"$MD_IMG"
gpart add -t freebsd /dev/"$MD_IMG"
gpart set -a active -i 1 /dev/"$MD_IMG"
gpart bootcode -b ./iso_mnt/boot/mbr /dev/"$MD_IMG"

# 4. Create BSD label and format with UFS
gpart create -s bsd /dev/"${MD_IMG}s1"
gpart add -t freebsd-ufs /dev/"${MD_IMG}s1"
gpart bootcode -b ./iso_mnt/boot/boot /dev/"${MD_IMG}s1"
newfs -U /dev/"${MD_IMG}s1a" > /dev/null

# 5. Copy files from ISO to the new Image
echo "Copying files (this may take a few minutes)..."
mkdir -p ./img_mnt
mount /dev/"${MD_IMG}s1a" ./img_mnt
tar -cf - -C ./iso_mnt . | tar -xf - -C ./img_mnt

# 6. Cleanup
echo "Cleaning up..."
umount ./img_mnt
umount ./iso_mnt
mdconfig -d -u "$MD_IMG"
mdconfig -d -u "$MD_ISO"
rmdir ./img_mnt ./iso_mnt

echo "Success! Image created: $IMG_FILE"
 
IMG to ISO:
Code:
#!/bin/sh
# img2iso.sh - Converts a FreeBSD .img to a bootable .iso
# Usage: sudo ./img2iso.sh input.img output.iso

if [ "$(id -u)" -ne 0 ]; then
    echo "Error: This script must be run as root."
    exit 1
fi

IMG_FILE=$1
ISO_FILE=$2

if [ -z "$IMG_FILE" ] || [ -z "$ISO_FILE" ]; then
    echo "Usage: $0 <input.img> <output.iso>"
    exit 1
fi

# 1. Mount the .img file
echo "Mounting IMG..."
MD_IMG=$(mdconfig -a -t vnode -f "$IMG_FILE")
# FreeBSD .img files usually have partitions. We mount the main UFS slice.
# Note: This assumes standard FreeBSD layout (s1a)
mkdir -p ./img_mnt
mount /dev/"${MD_IMG}s1a" ./img_mnt 2>/dev/null || mount /dev/"${MD_IMG}" ./img_mnt

# 2. Create the ISO
# -R -J: RockRidge and Joliet extensions for long filenames
# -b: Specifies the boot image for BIOS booting
# -no-emul-boot: Required for modern FreeBSD bootloaders
echo "Generating ISO (this may take a few minutes)..."
mkisofs -R -J -no-emul-boot -b boot/cdboot -o "$ISO_FILE" ./img_mnt

# 3. Cleanup
echo "Cleaning up..."
umount ./img_mnt
mdconfig -d -u "$MD_IMG"
rmdir ./img_mnt

echo "Success! ISO created: $ISO_FILE"
 
FreeBSD comes with a set of scripts to convert (actually to create them) ISO <--> IMG images.

Installation of the source code is required.
Code:
IMG
# mkdir  release-media
# tar  xfC  FreeBSD.iso  release-media

# sh  /usr/src/release/amd64/make-memstick.sh  release-media  FreeBSD.img

ISO

# sh  /usr/src/release/amd64/mkisoimages.sh  -b '15_0_RELEASE_AMD64_CD'  FreeBSD.iso  release-media
See bsdinstall(8) "BUILDING AUTOMATIC INSTALL MEDIA".
 
This is covered in this blog post I found a few days ago and shared in this thread: https://forums.freebsd.org/threads/updating-bios-from-usb.101334/post-739256
The purpose of the post is to show how to change the slash image (if you wish), but it works without doing that, and is quite straight forward. I have done three of my old Lenovo laptops so far!

edit: Not sure if this makes it work with PXE - I used a memory stick and did it from there...
I looked at that before but couldn't make it work.

If you got it to work I'll try again.
 
I looked at that before but couldn't make it work.

If you got it to work I'll try again.
I followed Justine's instructions exactly, but didn't do the stuff with the splash screen change. Full disclosure - I made my USB stick on a Linux system, but using geteltorito as instructed. I believe Justine is using FreeBSD on her laptop.
 
I followed Justine's instructions exactly, but didn't do the stuff with the splash screen change. Full disclosure - I made my USB stick on a Linux system, but using geteltorito as instructed. I believe Justine is using FreeBSD on her laptop.

This is my interpretation of the instructions. Can someone tell me where I have gone wrong. gpart show does not recognise da0


sh:
gpart show da0
BIOSFILE='upgrade.iso'
fetch -o $BIOSFILE https://download.lenovo.com/ibmdl/pub/pc/pccbbs/mobiles/7nuj22uc.iso
#pkg install -y geteltorito
geteltorito -o bios.img $BIOSFILE
dd if=bios.img of=/dev/da0 bs=1M status=progress
gpart show da0

The bios.img file produced is actually pxe-bootable but none of the BIOS update files are visible.
 
(rider - this is from my Linux experience). Generally, you should `sync` before removing the memory stick. It shouldn't matter too much in this case, because you are not putting much on the memory stick, but if you pull it before dd finishes and everything is moved across by the system, then the stick will be corrupt. I am just booting up a FreeBSD laptop to see what happens if I try here...

OK, so gpart show da0 (on FreeBSD) does work with the stick I created - there is one FAT32 partition, with 41M of data on it.
These are the commands I issued to create the stick:
geteltorito -o bios.img Downloads/r0iur44w.iso
dd if=bios.img of=/dev/sdb bs=1M && sync

The contents of the stick (viewed under Linux):
Code:
/run/media/paul/16EE-3664/
├── EFI
│   └── BOOT
│       └── BootX64.efi
├── FLASH
│   ├── R0IET73W
│   │   ├── $0AR0I00.FL1
│   │   └── $0AR0I00.FL2
│   └── SHELLFLASH.EFI
└── System Volume Information
    ├── IndexerVolumeGuid
    └── WPSettings.dat
Maybe try again, with the sync?

edit: I have now checked the stick under FreeBSD - the output is (not unexpectedly) the same.
 
I can't think what I'm doing wrong...

cat bios-update
sh:
gpart destroy -F da0

gpart create -s mbr da0
gpart add -t fat32 da0

gpart show da0

geteltorito -o bios.img upgrade.iso
dd if=bios.img of=/dev/da0 bs=1M && sync

gpart show da0

sh -x bios-update

+ gpart destroy -F da0
gpart: arg0 'da0': Invalid argument
+ gpart create -s mbr da0
da0 created
+ gpart add -t fat32 da0
da0s1 added
+ gpart show da0
=> 63 61439937 da0 MBR (29G)
63 61439937 1 fat32 (29G)

+ geteltorito -o bios.img upgrade.iso
Booting catalog starts at sector: 20
Manufacturer of CD:
Image architecture: x86
Boot media type is: 1.44meg floppy
El Torito image starts at sector 28 and has 2880 sector(s) of 512 Bytes

Image has been written to file "bios.img".
+ dd 'if=bios.img' 'of=/dev/da0' 'bs=1M'
1+1 records in
1+1 records out
1474560 bytes transferred in 0.113449 secs (12997533 bytes/sec)
+ sync
+ gpart show da0
gpart: No such geom: da0.
 
Code:
camcontrol rescan all
sysctl kern.disks | grep da0
camcontrol devlist | grep da0

If no da is found it could be due to the absence of a partition table,
Tro create one
Code:
gpart create -s GPT da0

Now everything should be fine.
Code:
dd if=bios.img of=/dev/da0 bs=1M status=progress
 
well, you go through all the effort of partitioning the device, and then after you geteltorito, you dd over all of that with the resulting image, rendering all the preceding commands null and void. did you mean to use of=/dev/da0s1 to get the image onto the partition instead of the device?
 
well, you go through all the effort of partitioning the device, and then after you geteltorito, you dd over all of that with the resulting image, rendering all the preceding commands null and void. did you mean to use of=/dev/da0s1 to get the image onto the partition instead of the device?
I'm only trying to following instructions without really knowing what to expect.

I thought I had followed the instructions here explicitly but my results don't match the ones that other people get.
 
well, you go through all the effort of partitioning the device, and then after you geteltorito, you dd over all of that with the resulting image, rendering all the preceding commands null and void. did you mean to use of=/dev/da0s1 to get the image onto the partition instead of the device?
In my opinion, the img file should be dd to the device, not the partition. When I did it, I did not do any partitioning of the device at all. I did it on linux, but later, I will do it again on my FreeBSD laptop and report back what happened. I know it shouldn't make any difference, but balanga - do you have another usb stick you can try?

Edit: I realised "later" will be this evening, and I really wanted to know the answer! So I took another memory stick out of my drawer, booted up my FreeBSD laptop, logged in as root, and did this after copying over the file from my Linux desktop:
geteltorito -o bios.img r0iur44w.iso
dd if=bios.img of=/dev/da0 bs=1M

I didn't do any work to prepare the stick before issuing the dd command. My understanding is that dd will simply overwrite any partition structure which is already on the disk, so there is no need for preparation activity.
Anyway, gpart show da0 did list the partition layout as I saw on the original stick in FreeBSD.
I mounted the /dev/da0s1 partition with mount_msdosfs /dev/da0s1 /media/usb and tree /media/usb showed the contents as above.
I didn't remove the stick, but rebooted, then <Enter> to interrupt normal start up, <F12> to select the boot options and selected the memory stick which was at the bottom of the list of options. This booted into the screen which manages the bios upgrade process. Since the Bios on this laptop is up to date, I didn't trigger the upgrade, but I have no reason to believe it won't work.
I really wonder if you have a faulty stick!
 
try and understand what is being done in each step
There's only one step that really matters once you have downloaded the iso, namely
dd if=bios.img of=/dev/da0 bs=1M

When I try to boot from this USB stick I get:

Non-System disk or disk error

I have tried several disks.

According to the instructions I should be able to

mount -t msdos /dev/da0s1 /mnt/usb

but there are no partitions on the device.
 
Back
Top