How to create a bootable FreeBSD USB

From MyWiki

Jump to: navigation, search

This was taken from freebsd-stable list. Thanks Andrew Snow for the detailed how-to!

Message: 16
Date: Wed, 11 Mar 2009 15:19:10 +1100
From: Andrew Snow
Subject: Re: Installing FreeBSD from USB flash drive - some experiments

Here's the steps I use to create a 1GB USB image:

 # dd if=/dev/zero of=bootable.image bs=1m count=1 oseek=1000 conv=sparse
 # mdconfig -a -t vnode -f bootable.image -u 0
 # newfs -m 0 -o space -n /dev/md0
 # mount /dev/md0 /mnt

 # cd /usr/src
 # make installworld DESTDIR=/mnt
 # make distribution DESTDIR=/mnt
 # make installkernel DESTDIR=/mnt
 # umount /mnt

At this point you have a file "bootable.image" but instead of actually making that a bootable dd image, 
I choose to create a dump file which is a bit more flexible as you can restore it to a USB stick of any size.

 # dump -0 -C 8 -f - /dev/md0 | gzip -9 > bootable.dump.gz
 # mdconfig -d -u 0

At this point, you have a dump file which you can use to create a bootable USB as follows:

Assuming the USB stick is /dev/da0 !

 # dd if=/dev/zero of=/dev/da0 bs=16k
 # fdisk -BI /dev/da0
 # disklabel -B -w /dev/da0s1
 # newfs -m 0 -o space -n /dev/da0s1a
 # mount -o noatime,async /dev/da0s1a /mnt
 # gzcat bootable.dump.gz | ( cd /mnt ; restore -rvf - )
 # umount /mnt


Hope that helps


- Andrew
Personal tools