PC-BSD install without a bootable DVD

Recently, I tried to get PC-BSD onto an older system. This system didn't support booting off of USB, nor did it support swapping in a DVD player for the CD player that was shipped with the system. The computer seemed to be fast enough to support PC-BSD. Since all I really wanted was something that could play some games that my 4-year-old wanted, I wasn't willing to spend a ton of money on a new computer just yet. Better to wait a year or two until we really needed something better.

PC-BSD only installing off a memory stick or off a DVD these days. I opted to go the DVD route because this computer didn't support booting off USB media as far as I could tell (I tried it on two machines: an old HP eVectra 933MHz box, and a slightly newer Dell Optiplex GX270).

The summary of this hack is 'Copy all the files from /boot on the ISO image onto a hard disk that has been made bootable and use a USB expansion box to store the real DVD'.

First, I needed to create a bootable hard disk. I put the hard disk that was going to be installed into the system info a USB expansion box and plugged it into my FreeBSD system. This gave me a disk as 'da0'. This disk had an old Windows installation on it. All commands are run as root. You are advised to triple check your typing, as transposed letters and such might have adverse effects.

Relabeling the Disk

Since I had an old windows install on the disk, I just needed to delete the old windows partition and create a FreeBSD one.
  1. gpart delete -i 1 da0
  2. gpart add -t \!165 da0
  3. gpart create -s bsd da0s1
  4. gpart add -t \!7 da0s1
Did the trick. Your milage may vary at this stage. I've also used "gpart delete -i X da0" and "gpart destroy da0" to totally wipe a GPT scheme off the disk in the past. If you do that, you'll also need "gpart create -s mbr da0" before proceeding to step 2 above. There's lots of other ways to skin this cat too involving dd, but since gpart has been added to the system, its so easy to use I prefer it for quick tasks like this so I don't have to remember "do I need to blank the front of the disk, or the end of the disk..."

Making the disk bootable

Next we need to make the disk bootable. This is a lot easier than it used to be in days of yore:
  1. gpart bootcode -b /boot/boot0 da0
  2. gpart bootcode -b /boot/boot da0s1
We have to make it bootable twice due to the multi-stage boot-loader that FreeBSD has (other systems are likely similar). "boot0" just prompts for which partition to boot (doing the first one by default). "boot" will then load /boot/loader to finish out the booting process and hand control over to FreeBSD's kernel.

Copying The Files

The pc-bsd installer for the DVD just loads a ram disk, and then runs off that. All the early stages of the boot loader need are contained in /boot. This includes the kernel, the third stage boot loader and various config files and scripts. So the next steps are to copy these files from the cd onto the bootable hard disk we just made. This assumes that the mdconfig command below prints "md0" for unit 0. If it prints anything else, you'll need to adjust accordingly. Also, if you are reading this in the future, you may need to change the PCBSD iso name.

  1. newfs /dev/da0s1a
  2. mount /dev/da0s1a /mnt
  3. mdconfig -f PCBSD8.1-x86-DVD.iso
  4. mount -t cd9660 /dev/md0 /cdrom
  5. mkdir /mnt/boot
  6. cd /cdrom/boot
  7. tar cf - . | (cd /mnt/boot; tar xvf -)
  8. cd /
  9. umount /mnt
  10. umount /cdrom
  11. mdconfig -d -u 0

Moving the disk

At this point, I had to unplug the USB expander from the first system, remove the hard drive and install it into my target box. I also grabbed my UBS DVD player and connected it to the box with a copy of the DVD I burned from the above file. I selected hard disk as the boot media in the bios and let the system boot. It booted off the hard disk, but then started looking for the proper cd device. Luckily for me, it found the DVD on cd1 instead of cd0 (which is what was built-in to the Dell I was booting off of). It then became a 'normal' PC-BSD installation, which is described in detail elsewhere.

Hopefully, people find these instructions useful. Since I only had one of these systems, I didn't create any kind of script to make it easier. Sorry.

[[ Updated to fix problem noted in the comments ]]


Anonymous said...

Alain B. from Paris.

Very usefull !

gpart tool was frightened me...

I learn with you, simply by example, essentials about using gpart.

Bye Bye fdisk and disklabel :-)

you have a little typo that's everyone had noticed:

gpart create -s bsd da0
gpart add -t \!7 da0

should be read as:

gpart create -s bsd da0s1
gpart add -t \!7 da0s1

Some others funny things can be done for the old or embedded world:

Nothing new there but it just can save your life :-)

Here, we can always use 'glabel create' on da0,
and adjust fstab in order to always
boot on everything that look like of a disk,
no matters if it's da0, ad4 or ada0.
Same CF can be booted either from USB adapter or SATA to CF converter.
Even if it's an hd image an iSCSI lun booted via gpxe and isboot
(see istgt project).

Yet another idea taken from the BSDRP projet:
in order to properly boot on cheap USB key you should increase the probe delay.

echo 'kern.cam.boot.delay=10000' >> ${IMGROOT}/boot/loader.conf

And the last one...

If you create a customised ISOLIVE CD or read only CF but you still want to alter
the configuration "write on it" at run time:

echo 'mkdir -p /var/fs/etc' >> $CDROOT/etc/rc.local
echo 'mount_unionfs -o noatime /var/fs/etc /etc ' >> $CDROOT/etc/rc.local

with /var as mdmfs(8) will do the trick.

FreeBSD: No limits !

Thank's again for your blog !

alain AT bsdgate.org

Warner Losh said...

Thanks for the tips Alain...

I use ufs labels now in FreeNAS (and added it to nanobsd in the base) so that /dev/ufs/mumble will find the right file system to boot off of. I got the idea from bsdrp. I know that PC-BSD uses glabel to actually label the partitions, but I guess I'm a sucker for booting the filesystem that I tagged as Blah, rather than the partition tagged as Blah. A subtle difference, to be sure.

I have the usb kludge from bsdrp in freenas right now. I hate it. It is just so wrong. IMHO, we should poll for new devices once we drop into the prompt for devices. So it would say 'oh, the specified thing turned up after all, continuing with it' if you didn't type anything...

I think we're using similar tricks for the forth-coming FreeNAS installer...

Now, I wonder, is it worth it to teach nanobsd how to make GPT partitioned devices...

Anonymous said...

Alain B.


I just switched some custom scripts to use UFS label instead of whole disk label.

This make it now more easy to have 2 freebsd partition on a single CF to have a rescue partition.
No more need to tweak loader.conf.

And with gpart, i no more need to create fdisk template for each kind of CF in order to always boot.
It just work's, and i don't know why :-)

Since i know nearly nothing about GPT,
i cannot pronounce me.

Thank's again.


Kalle said...

At www.plop.at there is free software that will let you boot off of usb even though you hardware doesn't support it directly.


nixil said...


I think teaching nanobsd how to make GPT partitioned devices would be worth while. (if you haven't already that is) I've been using GPT exclusively for a while now and would rather not switch back.