Klaus on Tilde Town

Installing FreeBSD 14.0 on a USB drive

A FreeBSD USB stick

Having re-discovered my love for FreeBSD on the desktop for the past month or so, I embarked in yet another adventure with it: creating a portable installation of it a USB drive so I could carry it with me on the go. This would be a great addition to my everyday carry, and would also again put the OS in test against many situations I have not had faced yet with it.

I have done portable installs of many-a-Linux distributions in the past, ranging from the classic designed for portable, run-from-RAM distros like Puppy Linux, until the more recent "frugal installs" of Alpine Linux directly on the drive. However, none of them ever counted on a BSD, so this was going to be a new experience, even though I thought it shouldn't be too difficult. After all, I've already mastered the art of FreeBSD installation, and this is just another install medium, right?

While that was certainly true (and the installation was indeed smooth as butter) the problem happened after the install. Once the installer gave me the green light to wrap it all up and reboot, I happily did, yanking out the installer drive from the port, and leaving the one with the frugal install plugged.

Case in point, I immediately faced an error the likes of which I have never heard of, and at a very early stage of boot nonetheless (a scary, scary prospective!). The bootloader splash appeared alright, but shortly afterwards it would fail. The message in question was something like this:

...
Trying to mount root from ufs: /dev/da1p2 [rw]
mountroot: waiting for device /dev/da1p2
Mounting from ufs: /dev/da1p2 failed with error 19.

Loader variables:
vfs.root.mountfrom=ufs:/dev/da1p2
vfs.root.mountfrom.options=rw
...

This was intriguing. I've never had a failure happen so early in the boot process on a fresh system, and yet, this was not a catastrophic kernel crash or something like that. One interesting thing was that by pressing ?, I was able to see a few devices listed that looked familiar:

<snip> da0p1 da0p2 da0p3 ... <snip>

Wait a second, I thought. Aren't these devices respectively mapped to my USB drive's partitions? I decided to try mounting the root partition:

> ufs:/dev/da0p2 rw

And it seemed to have worked for a while, with the process continuing for a second or two, until a similar wall was hit, and I would be dropped again to a recovery shell.

Unable to proceed after this, I went ahead and searched for the problem online. The closest I could find for this message was this forum post, but the people trying to troubleshoot the solution seemed to be firing in all directions without a clear strategy.

I was about to give up when I read this second to last reply, which was solid gold:

You had that problem for reason probably you removed the installation USB drive after installation and cause after reboot your main USB drive shifted down from /dev/da1... to /dev/da0...

Bingo: the reason why this happened was that my USB device count was one unit higher during the install, since I had USB drive 0 as the install medium and USB drive 1 as the "disk." This is what got written to fstab and all. Then, when I'm booting from the only USB around, the "disk" becomes USB 0, and fstab is completely lost.

And so, the solution: boot from a live medium, or mount the USB drive you've installed on another computer, then edit that disk's /etc/fstab file to change:

... /dev/ada1p2 ...

To

... /dev/ada0p2 ...

And so on throuh any other references you might have in that file. Save it, close and reboot normally with the frugal media. FreeBSD should start again, normally this time, and voilĂ : you're ready to rock with the Daemon to go \,,/

Conclusion

After a certain shenanigan of counting USB disk indices, FreeBSD 14.0-RELEASE works very well as a to-go OS for me - on par with my already existing bug-out USB sticks containing a portable Alpine Linux install.

In hindsight, however, it was really quite weird that this problem even happened in first place. I've been installing Linux distributions into removable media for a few years now, and it hasn't ever had such problem. I wonder if this happens because the FreeBSD folks don't think of their OS as worthy of portability (similar to a shenanigan with Gajim earlier this year)? At any rate, I'm glad it's easy to fix, and in fact you can do it straight from the installer - just choose LiveCD at the end of the installation and perform the aforementioned substitution in the fstab file of the chrooted environment.

Since learning this trick, I've prepared two removable drives with FreeBSD for me to test-drive; a plain flash drive and an external SSD. I'm already enamoring the idea of changing my daily driver machine to FreeBSD from Debian, and perhaps will do a little more testing with this drive before taking the plunge.


Have you ever had FreeBSD installed in an external medium for "everyday carry" or rescue purposes? What do you think of it? Let me know on Mastodon!


This post is number #48 of my #100DaysToOffload project.


Last updated on 12/18/23