Custom Kernel to Memory Stick

Giorgos Keramidas keramida at
Tue Mar 30 17:08:38 UTC 2010

On Mon, 29 Mar 2010 10:49:08 -0500, Jay Hall <jhall at> wrote:
> Ladies and Gentlemen,
> I have been asked to explore the possibility of booting FreeBSD from a
> memory stick.  This was not a problem; worked great when installed  from
> the distribution CD.
> What would be the best way to get our custom configuration onto the
> memory stick?

The fastest way I know is to create an image to an 'image' file stored
on disk or ramdisk and then dd the image to the USB disk.  You can
create a suitably large image with truncate(1), e.g.:

    truncate -s 1g /var/tmp/image.bin

Then attach the image to an mdconfig device:

    mdconfig -a -t vnode -u 20 -f /var/tmp/image.bin

Create a filesystem on it, and install everything from your buildworld
and buildkernel run:

    fdisk -BI /dev/md20
    bsdlabel -w -B /dev/md20s1
    newfs -U /dev/md20s1a

Mount the new image partition before installkernel+installworld:

    mount -t ufs /dev/md20s1a /mnt

Then you sould be able to install with DESTDIR pointing to the image

    cd /usr/src
    env DESTDIR=/mnt make installkernel installworld

Don't forgte to use mergemaster with -D /mnt to install the /mnt/etc
files from /usr/src/etc.  Then tweak the /mnt/etc/fstab file to point at
the USB disk as the root filesystem.

Finally detach the image and write it on a USB disk:

    umount /mnt
    mdconfig -du 20
    dd if=/var/tmp/image.bin of=/dev/da0 bs=4m

One of the nice tricks you can use for the root filesystem of the USB
disk is to add a UFS label to the USB root filesystem.  This way you
don't have to assume that the USB root filesystem is called da0s1a but
you can use /dev/ufs/LABELNAME in the fstab file of the image partition.

More information about the freebsd-questions mailing list