# USB memstick installation mini-HOWTO



## free-and-bsd (Nov 17, 2022)

[_Mod: Discussion split off here: Thread usb-memstick-installation-mini-howto-discussion.87142_]

In this mini-HOWTO I will describe how I created a USB memstick based FreeBSD installation and what solutions it seemed logical and practical to implement.

1. Don’t use ZFS – use UFS instead. Reasonably, it's about speed, nothing more. And the possible data loss which is kind of less likely with ZFS? Well, as explained below, a good idea with USB drive installation is to mount as much as possible _read-only_. That would diminish the amount of writes to the disk.

2. To make that possible it’s necessary to create _dedicated partitions_ for /, /usr, /var on the disk. OK, /var is not necessary, as explained below.
From these, only root / needs be mounted rw. Trying to keep root size at minimal, I came by the figure of 2G. At that, there is no much writing to / partition anyway. But it has to be mounted rw, or else all the mounted stuff will be read-only.

Correct me, please, if I am mistaken.

3. The partitions to be written to by the running system are /var and /tmp, so it's best to mount them as a memory disks, to improve speed while still keeping disk writes at a minimum. And mount_mfs(8) handles this, but it makes sense to populate mfs-based /var from our existing /var.
This is solved by using a file-backed, or vnode-backed mfs, where a dd-created img file contains the existing UFS file system with /var dirs & subdirs copied there from the initial /var. 

As a result, important system data (about pkg installation etc) will reside on that img file while /var will be just a mount point. And if you need to install / configure additional software, which would write things to /var, then instead of mfs the img can be mounted to /var as a rw md device. So when you remount it again as mfs afterwards, /var will contain all the changes...

5. Do we need swap? Well, reasons in favor of it explain the need by the possible situation when system becomes unresponsive for some reason, so the dump then would be saved on swap… Do you need THAT for your USB flash based system? Given that simple reboot will bring the system back online, in this particular case swap would seem to be not so critical.

To be continued...


----------



## free-and-bsd (Nov 18, 2022)

Cut short


----------

