How to put a FreeBSD installation ISO onto a USB Flash Drive
Assumes USB drive uses device da0, which is usually the case. Modify device names as needed. Unless special permissions have been set up, the commands usually need to be run as root.
- ./fbsd-install-iso2img.sh ./7.2-RELEASE-i386-bootonly.iso ./7.2-RELEASE-i386-bootonly.img
- Use fbsd-install-iso2img.sh scriptto convert the ISO into an appropriate disk image. (Paths assume script and all files are in the current directory; modify paths as appropriate.)
NOTE THAT MEMORYSTICK IMAGES ARE NOW AVAILABLE FOR FREEBSD STARTING WITH VERSION 8, SO THE ISO-TO-IMG CONVERSION STEP ABOVE IS NOT NEEDED. Just download and use the memorystick image with the steps below.
- fdisk -BI /dev/da0
- Create a bootable BSD slice on the USB flash drive, using the entire disk. THIS DESTROYS ALL DATA ON THE FLASH DRIVE! (Ignore the "Geom not found" warning.)
- bsdlabel -B -w da0s1
- Put a BSD label on the flash drive and copy bootstrap code to it.
- newfs -U -L FreeBSDboot /dev/da0s1a
- Create a FreeBSD file system on the flash drive.
- dd if=7.2-RELEASE-i386-bootonly.img of=/dev/da0 bs=10240 conv=sync
- Copy the image file to the USB flash drive.
File fbsd-install-iso2img.sh
#!/bin/sh # You can set some variables here. Edit them to fit your needs. # Set serial variable to 0 if you don't want serial console at all, # 1 if you want comconsole and 2 if you want comconsole and vidconsole serial=0 set -u if [ $# -lt 2 ]; then echo "Usage: $0 source-iso-path output-img-path" exit 1 fi isoimage=$1; shift imgoutfile=$1; shift export tmpdir=$(mktemp -d -t fbsdmount) # Temp file and directory to be used later export tmpfile=$(mktemp -t bsdmount) export isodev=$(mdconfig -a -t vnode -f ${isoimage}) echo "#### Building bootable UFS image ####" ISOSIZE=$(du -k ${isoimage} | awk '{print $1}') SECTS=$((($ISOSIZE + ($ISOSIZE/5))*2)) # Root partition size echo "Initializing image..." dd if=/dev/zero of=${imgoutfile} count=${SECTS} ls -l ${imgoutfile} export imgdev=$(mdconfig -a -t vnode -f ${imgoutfile}) bsdlabel -w -B ${imgdev} newfs -O1 /dev/${imgdev}a mkdir -p ${tmpdir}/iso ${tmpdir}/img mount -t cd9660 /dev/${isodev} ${tmpdir}/iso mount /dev/${imgdev}a ${tmpdir}/img echo "Copying files to the image..." ( cd ${tmpdir}/iso && find . -print -depth | cpio -dump ${tmpdir}/img ) #bzcat ${tmpdir}/iso/dist/root.dist.bz2 | mtree -PUr -p ${tmpdir}/img 2>&1 > /dev/null #echo "/dev/ufs/${UFS_LABEL} / ufs ro 1 1" > ${tmpdir}/img/etc/fstab if [ ${serial} -eq 2 ]; then echo "-D" > ${tmpdir}/img/boot.config echo 'console="comconsole, vidconsole"' >> ${tmpdir}/img/boot/loader.conf elif [ ${serial} -eq 1 ]; then echo "-h" > ${tmpdir}/img/boot.config echo 'console="comconsole"' >> ${tmpdir}/img/boot/loader.conf fi cleanup() { umount ${tmpdir}/iso mdconfig -d -u ${isodev} umount ${tmpdir}/img mdconfig -d -u ${imgdev} rm -rf ${tmpdir} ${tmpfile} } cleanup ls -lh ${imgoutfile}