|Zap's Digital Lighthouse|
Sun, 08 Nov 2015
(I think that the stuff below is accurate, but do proceed with care if you're going to try it out... I could have made a mistake writing down the list of steps. Let me know if you spot any issue.)
I would like to add a new USB disk to my FreeBSD 10 machine. In the olden days, I used to use sysinstall, but that doesn't seem to be the modern way to do things these days.
Notably, I would like to "label" the drive, so that I can mount it with its logical name rather than its physical device name... this is particularly important for USB disks, as plugging and unplugging USB device ports may cause changes in device names, which could cause really annoying issues if fstab mounts the wrong device (as I've already written about on Feb 20th, 2012).
So, here is what one must do to set up a new disk for use on FreeBSD...
1) First of all, decide how you're going to name your device. Using volume names instead of just raw device names is highly desirable if you're in a dynamic environment (e.g. if you're going to be adding disks to the computer in the future -- including USB storage, devices may end up being renamed).
For USB disks, choosing good label names is important: you may want to replace a disk at some point if one crashes (so do not use the /dev/ufsid/... names) and/or you may have a CPU crash and you'd like to mount your disk onto some other FreeBSD system (so do not use the same names for your bootdisks on all computers, unless they are truly meant to be considered identical clones). This means that 'bootdisk' is probably not a great label, in case you ever need to mount it on another machine that also boots from a 'bootdisk'... 'myhostname-bootdisk' might be better, albeit a bit verbose.
I'm not sure if there are canonical policies for that sort of thing, but I'd be interested in hearing about recommendations in this area.
Now, getting to the actual set up of the drive.
2) connect the disk to the USB port, and check out the dmesg log to find out the correct device name, something like da0 or da1 (depending on whether it's your first USB or SCSI disk, or your second one, or ...)
In this case, it's da0 and it's connected to a USB3 port (so it can do 400 MB/s rather than 40 MB/s for USB2).
As always: make sure you select the right device name, because formatting the wrong drive is bad and will cause your data to go away. If you want to check out which disks are present, you can type:
You can also use the usbconfig command to see what USB hubs and devices are present on your system:
You may also want to use the 'mount' command to check which disks are currently mounted, but with volume labels being used instead of phycical device names, you may not see the 'real' devices names in there (e.g. /dev/ufs/bootdisk instead of /dev/da1 or something similar).
3a) Once certain which disk to use, if a UFS filesystem is desired, proceed thusly (if a ZFS filesystem is desired, move on to step 3b):
(note: /dev/XXX represents the new disk, such as /dev/da0 or /dev/ada1)
This creates a whole disk for FreeBSD (such as a data disk). If you want to set up a disk with multiple filesystems, you can do something like:
(This creates a 'USB boot disk')
Et voilą, finished. You may want to add a line to /etc/fstab to have /dev/ufs/myvolume mounted automatically at boot time. Always use volume label names instead of physical disk drive names, especially for USB drives where the disk drive name may change across reboots depending on what USB devices are plugged into the computer's ports and USB hubs.
3b) If a ZFS filesystem is desired instead, skip step 3a and proceed thusly (with /dev/XXX representing the new disk, such as /dev/da0 or /dev/ada1 once again):
(Once again, this creates a 'USB boot disk')
Et voilą, finished.
4) At this point, your disk is up and running. Do not forget to use mount to make it available under FreeBSD, and to umount it before unplugging it.
You may want to check out http://www.macfreek.nl/memory/FreeBSD9withZFSbootdisk for more info. Furthermore, http://www.macfreek.nl/memory/FreeBSD9onSoekrisnet6501 may also be pertinent. And about ZFS, do check out: http://nex7.blogspot.ca/2013/03/readme1st.html and of course this: http://www.solarisinternals.com/wiki/index.php/ZFSEvilTuning_Guide