$Id: buildingImage.txt,v 1.5 2012/06/09 06:22:27 guru Exp $ Some ideas are stolen from: http://bsdimp.blogspot.com/2007/10/building-bootable-freebsdi386-images.html Building bootable FreeBSD/i386 USB keys If you want to build world and kernel out of SVN in 'src' and into 'obj', but in some other place as /usr/[src|obj], for example in /home/guru/head/[src|obj] use this procedure: # mkdir -p /home/guru/head/obj # MAKEOBJDIRPREFIX=/home/guru/head/obj ; export MAKEOBJDIRPREFIX # cd /home/guru/head # svn checkout svn://svn.freebsd.org/base/head src # cd /home/guru/head/src # make buildworld # make buildkernel KERNCONF=GENERIC ... or do the above just in the normal /usr/src (see kernel.txt); How to install a booting FreeBSD onto an USB key as /dev/da0: File operations, esp. of a large amount of small files, are very SLOW on USB keys. That's why we use in general the following procedure: 1. dd(1) the complete /dev/da0 to a plain file, an image of the USB key; 2. use mdconfig(8) to make a memory disk of this file and mount(8) it; 3. do everything of the formatting and installation in this virtual disk; 4. unmount(8) it and dd(1) it back to the USB key; here we go (use for /dev/da0 what your key is in /var/log/messages): # dd if=/dev/da0 of=da0.r250588 bs=8m note: this step is essential to get an image which later fits again to the real USB key; attach the file da0.r250588 as memory disk: # mdconfig -a -t vnode -f da0.r250588 md0 wipe out all blocks to zero on the memory disk: # dd if=/dev/zero of=/dev/md0 bs=1m dd: /dev/md0: end of device 14785+0 records in 14784+0 records out 15502147584 bytes transferred in 1459.484517 secs (10621659 bytes/sec) now use the normal procedure to create a bootable UFS on it: # fdisk -I md0 # fdisk -B md0 # bsdlabel -w md0s1 auto # bsdlabel -B md0s1 # bsdlabel -e md0s1 # edit the disk label and change partition "a" from "unused" to "4.2BSD" build the file system: # newfs /dev/md0s1a # mount /dev/md0s1a /mnt if you have built the kernel and world in some other place as /usr/src: # MAKEOBJDIRPREFIX=/home/guru/head/obj ; export MAKEOBJDIRPREFIX # cd /home/guru/head/src or just run 'make' from the default place /usr/src # cd /usr/src since 20121201 (see src/UPDATING) the system where the build is done needs a new user 'auditdistd'; we add this with: # pw useradd -n auditdistd -g audit -c "Auditdistd unprivileged user" -d /var/empty -s /usr/sbin/nologin now we can install world an kernel: # make installworld DESTDIR=/mnt # make installkernel DESTDIR=/mnt KERNCONF=GENERIC INSTALL_NODEBUG=t # make distrib-dirs DESTDIR=/mnt # make distribution DESTDIR=/mnt # echo /dev/da0s1a / ufs rw 1 1 > /mnt/etc/fstab # cp /etc/wpa_supplicant.conf /mnt/etc # cat < /mnt/etc/rc.conf wlans_ath0="wlan0" ifconfig_wlan0="WPA DHCP" ifconfig_bge0="DHCP" hostname=tinyCaracas sshd_enable="YES" keymap="german.iso" EOF # cat < /mnt/boot/loader.conf kern.cam.boot_delay="10000" kern.cam.scsi_delay="3000" EOF to use the above created USB key to install a 2nd system (the EeePC for example, or the Acer) we need 'src' and 'obj' as well on the key: # cd /home/guru/head/ # mkdir -p /mnt/home/guru/head/ we could do (to avoid copy of .svn dirs): # rsync -av --cvs-exclude src /mnt/home/guru/head/ # rsync -av --cvs-exclude obj /mnt/home/guru/head/ or (this worked fine every time): # cp -Rp src /mnt/home/guru/head/ # cp -Rp obj /mnt/home/guru/head/ or from the normal place as: # cd /usr # cp -Rp src /mnt/usr # cp -Rp obj /mnt/usr add an unpriv user (for beeing able to SSH-in): # chroot /mnt /usr/sbin/adduser umount the key, detach the memory disk and dd(1) the image to the USB device: # umount /mnt # mdconfig -d -u md0 # dd if=da0.r250588 of=/dev/da0 bs=8m