| Feature | .img (memstick) | .iso (CD/DVD) |
|---|---|---|
| Primary Media | USB Flash Drives, SD Cards | CDs, DVDs, Virtual Machines |
| Internal Format | Raw disk image with partition table | ISO 9660 filesystem |
| Virtualization | Harder to use in some VM software | Standard for most hypervisors |
| Content | Typically a "middle-ground" installer | Ranges from "bootonly" to full "dvd1" |
#!/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"
#!/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"
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
I'm not trying to create a FreeBSD boot img, I'm trying to convert a ThinkPad BIOS update ISO into an img that I can boot from via PXE.FreeBSD comes with a set of scripts to convert ISO <--> IMG images.
I looked at that before but couldn't make it work.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 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.
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
gpart show da0 (on FreeBSD) does work with the stick I created - there is one FAT32 partition, with 41M of data on it. geteltorito -o bios.img Downloads/r0iur44w.iso
dd if=bios.img of=/dev/sdb bs=1M && sync
/run/media/paul/16EE-3664/
├── EFI
│ └── BOOT
│ └── BootX64.efi
├── FLASH
│ ├── R0IET73W
│ │ ├── $0AR0I00.FL1
│ │ └── $0AR0I00.FL2
│ └── SHELLFLASH.EFI
└── System Volume Information
├── IndexerVolumeGuid
└── WPSettings.dat
cat bios-updategpart 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.
camcontrol rescan all
sysctl kern.disks | grep da0
camcontrol devlist | grep da0
gpart create -s GPT da0
dd if=bios.img of=/dev/da0 bs=1M status=progress
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.well, you go through all the effort of partitioning the device, and then after yougeteltorito, youddover all of that with the resulting image, rendering all the preceding commands null and void. did you mean to useof=/dev/da0s1to get the image onto the partition instead of the device?
One way to find out isn't it ?What should I expect to see after running this?
In my opinion, the img file should bewell, you go through all the effort of partitioning the device, and then after yougeteltorito, youddover all of that with the resulting image, rendering all the preceding commands null and void. did you mean to useof=/dev/da0s1to get the image onto the partition instead of the device?
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? geteltorito -o bios.img r0iur44w.iso
dd if=bios.img of=/dev/da0 bs=1M
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.gpart show da0 did list the partition layout as I saw on the original stick in FreeBSD.mount_msdosfs /dev/da0s1 /media/usb and tree /media/usb showed the contents as above.There's only one step that really matters once you have downloaded the iso, namelytry and understand what is being done in each step
dd if=bios.img of=/dev/da0 bs=1M mount -t msdos /dev/da0s1 /mnt/usb