Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

HOWTO: build a custom image using crochet

Sat Nov 01, 2014 6:47 pm

Building your own FreeBSD image for Raspberry Pi has a few advantages over using an official image. For one thing it allows you to pick up the latest fixes since official images aren't created very often. It also allows you to customize the image for your own needs. For example you can configure SSH to allow remote login after the first boot so you don't need a keyboard or monitor. Below are step by step instructions for setting up a virtual machine and building a FreeBSD image.

Caveat: these instructions allow root access with a blank password over SSH to your virtual machine. I set it up this way for convenience since it is only a temporary virtual machine used for building images. But in general this is not a good security practice.

Step 37 downloads the FreeBSD sources using svn. In these instructions I am using the "-r 273702" option to pull down a specific version that I have tested. You will probably want to remove that parameter to pull down the latest version.

Step 40 is where you customize the image. I have selected AutoSize which will enable automatic resizing of your image to use the entire capacity of your SD card during the first boot. There are other options you can choose (these are documented in the various readme files packaged with crochet). I also made several customizations using the customize_freebsd_partition() routine which runs after the image is created:

- set the root account password to root
- permit root login over SSH
- set static IP to (netmask
- set gateway to
- enable time daemon to set your date/time
- set name server to
- disable high speed mode for SD card (I needed this to get my Transcend 16GB SD card to work)
- set time zone to Mountain Standard Time

You'll probably want to make changes here. For example, allowing root access over SSH is not a recommended security practice. Another option is to set up a user account that is a member of the wheel group (which can su as root). Look at the crochet documentation for instructions.

Code: Select all

 1) download a FreeBSD virtual machine image here:

    (get a vmdk file which is a virtual disk to use with VMware Player)

 2) download and install VMware Player
 3) launch VMware Player and click on the Home icon
 4) select "Create a New Virtual Machine"
 5) select "I will install the operating system later" and click "Next"
 6) for OS select "Other" and "FreeBSD 64-bit" and click "Next"
 7) choose a location to store the virtual machine files and click "Next"
 8) select "Store virtual disk as a single file" and click "Next"
 9) click "Finish" to create the virtual machine
10) select the virtual machine and click "Edit virtual machine settings"
11) select "Hard Disk" and click "Remove" (it is empty and not needed)
12) click "Add", select "Hard Disk", and click "Next"
13) leave the type as "SCSI" and click "Next"
14) select "Use an existing virtual disk" and click "Next"
15) point it to the vmdk file you downloaded earlier and click "Finish"
16) select "Memory" and set it to 1GB
17) select "Network Adapter" and set it to "Bridged"
18) click "OK" and click "Play virtual machine"
19) wait for FreeBSD to boot and login as "root"
20) ifconfig (to get the name of your network adapter - probably em0)
21) echo 'ifconfig_em0="DHCP"' >> /etc/rc.conf
22) echo 'sshd_enable="YES"' >> /etc/rc.conf
23) sed -i -e 's/^#PermitRootLogin.*/PermitRootLogin yes/'           /etc/ssh/sshd_config
24) sed -i -e 's/^#PermitEmptyPasswords.*/PermitEmptyPasswords yes/' /etc/ssh/sshd_config
25) sed -i -e 's/\(^auth.*pam_unix.*\)/\1 nullok/'                   /etc/pam.d/sshd
26) reboot
27) login as root
28) ifconfig (note IP address to use for remote login over SSH)
29) login as root to the virtual machine using an SSH client (ie. putty)
    (so you don't have to use the tiny screen at the local terminal)
30) pkg install git
31) pkg install devel/subversion
32) pkg install python
33) pkg install devel/gmake
34) pkg install textproc/gsed
35) git clone git://github.com/kientzle/crochet-freebsd.git /root/crochet
36) git clone git://github.com/gonzoua/u-boot-pi.git        /root/crochet/u-boot-rpi
37) svn checkout https://svn0.us-west.freebsd.org/base/head /usr/src -r 273702
39) cd /root/crochet
40) cat > config.sh

board_setup RaspberryPi
option AutoSize
customize_freebsd_partition () {
    pw moduser root -V ${BOARD_FREEBSD_MOUNTPOINT}/etc/ -w yes
    sed -i '' 's/^#PermitRootLogin.*/PermitRootLogin yes/' ${BOARD_FREEBSD_MOUNTPOINT}/etc/ssh/sshd_config
    sed -i '' '/^ifconfig_ue0/d' ${BOARD_FREEBSD_MOUNTPOINT}/etc/rc.conf
    echo 'ifconfig_ue0="inet"' >> ${BOARD_FREEBSD_MOUNTPOINT}/etc/rc.conf
    echo 'defaultrouter=""' >> ${BOARD_FREEBSD_MOUNTPOINT}/etc/rc.conf
    echo 'ntpd_enable="YES"' >> ${BOARD_FREEBSD_MOUNTPOINT}/etc/rc.conf
    echo 'ntpd_sync_on_start="YES"' >> ${BOARD_FREEBSD_MOUNTPOINT}/etc/rc.conf
    echo 'nameserver' >> ${BOARD_FREEBSD_MOUNTPOINT}/etc/resolv.conf
    echo 'hw.bcm2835.sdhci.hs="0"' >> ${BOARD_FREEBSD_MOUNTPOINT}/boot/loader.conf
    cp ${BOARD_FREEBSD_MOUNTPOINT}/usr/share/zoneinfo/America/Denver ${BOARD_FREEBSD_MOUNTPOINT}/etc/localtime

41) ./crochet.sh -c config.sh
42) you can grab the image file from the VM using an SSH tool (ie. scp):

    scp [email protected]:/root/crochet/work/Free*.img .

Posts: 1
Joined: Wed Mar 25, 2015 9:46 pm

Re: HOWTO: build a custom image using crochet

Wed Mar 25, 2015 10:03 pm

trying to build img using ur guide however during the step 15, when downloaded VMDK file is selected, "Not virtual file" error msg populates.

Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: build a custom image using crochet

Wed Apr 15, 2015 12:43 am

Did you decompress it first? You can use 7-zip for that.

Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: build a custom image using crochet

Tue May 12, 2015 1:32 am

It looks like there was a regression regarding the VM disk images and that is why you were getting the error attempting to load it. This will be fixed during the next release but for now you can use the last working image:

http://ftp.freebsd.org/pub/FreeBSD/snap ... 81.vmdk.xz

Posts: 2
Joined: Fri Jan 08, 2016 9:17 pm

Re: HOWTO: build a custom image using crochet

Fri Jan 08, 2016 10:31 pm

This doesn't work anymore with latest sources.

Posts: 5
Joined: Thu Apr 28, 2016 11:24 am

Re: HOWTO: build a custom image using crochet

Wed May 04, 2016 6:39 am

Same here..

>>> Building an up-to-date bmake(1)
--- obj ---
make[2]: make[2]: don't know how to make arch.c. Stop

make[2]: stopped in /usr/src/usr.bin/bmake
*** [bmake] Error code 2

make[1]: stopped in /usr/src
1 error

make[1]: stopped in /usr/src
*** [upgrade_checks] Error code 2

make: stopped in /usr/src
1 error

make: stopped in /usr/src

Return to “FreeBSD”