Setup, and create a custom FreeBSD ISO

Prolog

I needed a quick way to create a bootable FreeBSD CD/DVD that didn't have that slow, resource hungry, DEBUG kernel that comes on the ISO's, and mem sticks that FreeBSD distributes. It's bogged down with watchdog, and invariants, and a lot of other things which allows them to discover when things go wrong on hardware that people who try it have. This isn't of any use to me. So, since I already have several machines running various versions of FreeBSD, and I have already built custom kernels for them. I'm going to whip up a custom CD/DVD with a custom kernel, to replace the one that comes on their distribution CD/DVD.

NOTE: I'm tracking CURRENT (11), as I write this article. So this is what these instructions are based on.

Preparation

We're going to need a FreeBSD distribution ISO. You can find them on ftp://ftp.freebsd.org/pub/FreeBSD/releases/

I'm on 64bit, largely AMD hardware, and as I already noted; tracking 11-CURRENT. So I grabbed the ISO image from ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/amd64/ISO-IMAGES/11.0/. You could accomplish this with any of the ISO's they provide. But for my needs, I chose the bootonly ISO. I also chose the compressed version, to save time downloading. It's compressed with the xz algorithm, so the ISO file ends with the extension iso.xz.

The ISO image I grabbed was FreeBSD-11.0-CURRENT-amd64-r283577-20150526-bootonly.iso.xz. The file name, while descriptive, is way too long, for convenience. So, before I go any further. I'm going to rename it.

# cd /tmp/ # ls 58827652 FreeBSD-11.0-CURRENT-amd64-r283577-20150526-bootonly.iso.xz # mv ./FreeBSD-11.0-CURRENT-amd64-r283577-20150526-bootonly.iso.xz ./11-bootonly.iso.xz # ls 58827652 11-bootonly.iso.xz

OK, that's better. But before I go any further, I'm going to need to unpack it.

# xz --decompress ./11-bootonly.iso.xz # ls 235651072 11-bootonly.iso

Alright, let's get down to business. We're going to need to mount the ISO image, in order to do anything with it. We'll use the memory disk utility, mdconfig.

See if there's already any memory disks in use

# mdconfig -l

good, there's not. I'll start with unit 0, then

# mdconfig -a -t vnode -f 11-bootonly.iso -u 0

now let's mount it

# mount -t cd9660 /dev/md0 /mnt

let's see whats inside that ISO image

# ls -l /mnt total 87 -rw-r--r-- 2 root wheel 950 May 26 13:53 .cshrc -rw-r--r-- 2 root wheel 242 May 26 13:53 .profile drwxr-xr-x 2 root wheel 4096 May 26 13:52 .rr_moved -r--r--r-- 1 root wheel 6190 May 26 13:53 COPYRIGHT drwxr-xr-x 2 root wheel 6144 May 26 13:53 bin drwxr-xr-x 8 root wheel 8192 May 26 13:53 boot dr-xr-xr-x 2 root wheel 2048 May 26 13:52 dev drwxr-xr-x 25 root wheel 14336 May 26 13:53 etc drwxr-xr-x 3 root wheel 8192 May 26 13:53 lib drwxr-xr-x 4 root wheel 2048 May 26 13:53 libexec drwxr-xr-x 2 root wheel 2048 May 26 13:52 media drwxr-xr-x 2 root wheel 2048 May 26 13:52 mnt dr-xr-xr-x 2 root wheel 2048 May 26 13:52 proc drwxr-xr-x 2 root wheel 2048 May 26 13:52 rescue drwxr-xr-x 2 root wheel 2048 May 26 13:53 root drwxr-xr-x 2 root wheel 18432 May 26 13:53 sbin lrwxr-xr-x 1 root wheel 11 May 26 13:52 sys -> usr/src/sys drwxrwxrwt 2 root wheel 2048 May 26 13:52 tmp drwxr-xr-x 14 root wheel 2048 May 26 13:53 usr drwxr-xr-x 24 root wheel 4096 May 26 13:52 var

Exactly what one would expect to find if they had mounted the CD/DVD itself. Good.

Now we need to create a staging area to do our work in.

NOTE: This area needs to have at least as much space as the CD/DVD we're creating, and a little extra, as well.

# mkdir /WORK # cd /WORK # rsync -a /mnt/ .

Now we have an exact copy of the CD/DVD to work with.

rsync gave us an exact copy of our working ISO rooted in /mnt/. rsync is not installed as part of the base system. If you haven't installed rsync already, you can do so, via the FreeBSD ports system:

# cd /usr/ports/net/rsync # make install clean
Or, if you don't care what options you get. You can use the pkg system:
# pkg install net/rsync

Install a custom kernel

Now it's time to install the custom kernel. In this case it's important to know the name of the kernel I'll be using (installing) onto this custom CD/DVD. You will also need to perform this from the system the kernel was built/installed on. Well, it's easier, anyway.

# uname -i DEVBOX

OK now we know the kernel name we last built on this box. So let's install it into our staging area.

# cd /usr/src # make installkernel KERNCONF=DEVBOX DESTDIR=/WORK

A couple hundred lines will scroll by, indicating what is being installed, and where. In our case here, it'll be /WORK/boot/kernel.

If you should perform an ls in the /WORK folder we made, you'll see that the date, and time of the boot folder is now the current time, and date.

Additional customizations

At this point, if we were building in any more customizations into this custom CD/DVD. This would be the time to do it. Much of that work would be accomplished in the /etc directory. Things like network, services, hostname, securelevel, and so on. But for my needs, and this example. The standard/stock bootonly setup is fine. It's just generic enough that I can use it for several boxes, without issue. I can also keep this CD/DVD around as a template, that I can continue to customize in other ways. Perhaps make it a custom install, or maybe a complete bootable Desktop CD/DVD. Who knows?

NOTE: /etc/fstab will need to be adjusted. Specifically, our mount point for root / will be different, and since that's the only mount point needed for this custom FreeBSD CD/DVD:

# echo '/dev/cd0 / cd9660 ro 0 0'>/WORK/etc/fstab

There is, however one more thing I want to do before I create the ISO image, and burn it. Nearly all my boards have nVidia video cards. So I'm going to want to load it. This will also be wanted, if I should later expand this custom CD/DVD into a Desktop on CD/DVD. Because the nVidia blob requires the Linux ABI. I'll also need to load the ABI as well. I'm also going to ensure that the boot timeout meets my wishes:

# echo 'vfs.mountroot.timeout="10"' >/WORK/boot/loader.conf # echo 'linux_load="YES"' >>/WORK/boot/loader.conf # echo 'nvidia_load="YES"' >>/WORK/boot/loader.conf

Create the custom ISO image

I'm now satisfied I've done all I need for this particular custom FreeBSD CD/DVD. So it's time to create the ISO image. First, we need to cd into root (/):

# cd /

Now we create the ISO image from our /WORK folder, and use /WORK/boot/cdboot, as the boot image.

# mkisofs -D -R -b boot/cdboot -allow-leading-dots -no-emul-boot -o 11-custom.iso WORK

Burn the custom ISO to CD/DVD

Now that our new custom FreeBSD ISO is ready. It's time to burn it to media. If you have an older version of FreeBSD. That is, older than 9. You can use the burncd utility, from the FreeBSD ports collection under sysutils/burncd. If you have it, issue something like the following:

# burncd -s 48 -f /dev/acd0 data 11-custom.iso fixate

For FreeBSD versions greater than 8, you might try cdrecord. It's part of cdrtools, in the ports tree, under sysutils. You can install it as follows:

# cd /usr/ports/sysutils/cdrtools # make install clean
If you don't care what options you get. You can use the pkg system to install it:
# pkg install sysutils/cdrtools

We can now burn the custom ISO image to CD/DVD issuing the following:

# cdrecord dev=device 11-custom.iso

To determine the value of dev in the command above, issue the following:

# cdrecord -scanbus

Which will return something similar to the following:

... Using libscg version 'schily-0.9'. scsibus0: 0,0,0 0) '' '' '' NON CCS Disk 0,1,0 1) * 0,2,0 2) * 0,3,0 3) * 0,4,0 4) * 0,5,0 5) * 0,6,0 6) * 0,7,0 7) * scsibus6: 6,0,0 600) '_NEC ' 'DVD_RW ND-2510A ' '2.04' Removable CD-ROM 6,1,0 601) * 6,2,0 602) * 6,3,0 603) * 6,4,0 604) * 6,5,0 605) * 6,6,0 606) * 6,7,0 607) *

So, the value for dev in this case would be _NEC

Frankly, I'm more inclined to use one of the GUI's available while I'm in X. There are many to choose from, k3b (KDE), brasero (Gnome), tkdvd, xfburn, etc. I'm going with one of the lightweight choices. It's equally powerful, but maintains a smaller footprint: xfburn

Xfburn screenshot (small)

Congratulations

That's it. If you've followed these instructions. You now have a custom bootable FreeBSD CD/DVD. There are some other ways to accomplish this task. But this is a really easy, and fast way to do it. I'll write about other ways to accomplish this, and post them in the articles section (if I haven't done so already).

Enjoy!

Additional FreeBSD related Articles.

See also:
BSD forge
Damn Small BSD
Man Pages