Booting from Memory Stick

Walker zflyer at
Sun Mar 2 16:37:59 UTC 2008

On Sat, Mar 1, 2008 at 4:23 PM,  <jhall at> wrote:
> I am working on getting a FreeBSD system to boot from a USB memory stick.

FWIW, my cut/paste script for installing 7.0 to a USB flash drive.
This is adapted from a post by Ceri Davies (thank you!).

** This assumes the drive is at /dev/da0 and that /dev/md0 is not in use **

# set these; the two mount points should not exist
export ISOFILE='/tmp/7.0-RELEASE-i386-disc1.iso'
export ISOMNT='/a'
export USBMNT='/b'

# zero the device for better compression when were done (optional)
dd bs=10m if=/dev/zero of=/dev/da0

# mdconfig and mount the media
mkdir -m 555 ${ISOMNT} ${USBMNT}
mdconfig -a -t vnode -u 0 -f ${ISOFILE}
mount -t cd9660 /dev/md0 ${ISOMNT}

# label and newfs the flash drive
fdisk -BI /dev/da0
bsdlabel -B -w da0s1
newfs -U -L FBSDusb /dev/da0s1a
mount /dev/da0s1a ${USBMNT}

# install the OS
cd ${ISOMNT}/*RELEASE/base

# install the generic kernel
cd ${ISOMNT}/*RELEASE/kernels
DESTDIR=${USBMNT} ./ generic
rmdir ${USBMNT}/boot/kernel
mv ${USBMNT}/boot/GENERIC ${USBMNT}/boot/kernel

# set boot0 options
boot0cfg -v -B -o noupdate -t 90 da0

# install a fstab; adjust as needed (like /tmp size)
cat >> ${USBMNT}/etc/fstab << EOF
# Device Mountpoint FStype Options Dump Pass
/dev/ufs/FBSDusb / ufs rw,noatime 1 1
md /tmp mfs rw,-s150M,nosuid,noatime 0 0
md /var/run mfs rw,-s4M,nosuid,noatime 0 0
md /var/log mfs rw,-s16M,nosuid,noatime 0 0
/dev/acd0 /cdrom cd9660 ro,noauto,nosuid 0 0
/proc /proc procfs rw,noauto 0 0
/tmp /var/tmp nullfs rw 0 0

# install an rc.conf
cat >> ${USBMNT}/etc/rc.conf << EOF

# set root password and timezone (optionally add users here as well)
chroot ${USBMNT} /bin/sh
passwd root

# clean up
cd /
umount ${ISOMNT} ${USBMNT}
rmdir ${ISOMNT} ${USBMNT}
mdconfig -d -u 0

# backup and compress (~ 84MB) (optional)
dd bs=10m if=/dev/da0 of=usbflash-freebsd_7.0.img
nice bzip2 usbflash-freebsd_7.0.img

# done

More information about the freebsd-questions mailing list