Contents
Help for Switchers from Linux to FreeBSD
Linux and FreeBSD share similarities but they are different enough to throw a new user off tracks. Therefore this cheatsheet to give the switcher a helping hand.
In my experience the man pages are a lot better than in Linux and you will often reach your goal faster by reading the man pages than by googling around. When I write something like "More info in page(8)", then a "man page" will usually do.
In addition there is the Handbook which is available in several languages.
Hardware
Devices are usually called like their driver. Thus you do not have ethXXX but for example iwnX or emX. You can find more information about the drivers in their man page. The examples here would be em(4)' and iwn(4). Disks are not named
Base and Ports/Packages
In contrast to Linux FreeBSD is not a kernel and 3rd-party software combined to create a distribution. But it is split in base and ports. Base is the kernel and lots of useful tools. If you need more software than base, you need to install ports or packages.
Ports means that you get the ports tree and install from source files. It is very similar to gentoo. When you install and there are Makefile-options you get a menu that will present them to you. A faster way are packages though. Then you install from binary packages but that also means that you are bound to the dependencies bound by the packages. In my experience I cannot recommend using ports and packages together.
If you have several machines and want the best of both worlds, then use a built server like poudriere. There you can set your build options for each package, built automatically every day and update your servers with binary packages.
When you see recommendations for software, you usually see them in the style of sysutils/htop which means that it is in /usr/ports/sysutils/htop.
Run Levels, eh User Modes
Since FreeBSD does not use SysVinit there are no run levels. There is only single user mode and multi-user mode.
shutdown now will bring you from single user to multi user. More than once did I use shutdown now and wondered why my system didn't switch off.
When you want to shutdown the system, the following commands do what you want:
power off: shutdown -p now
halt: shutdwon -h now
reboot: shutdown -r now
More infos in shutdown(8)
You don't want to use reboot(8) usually. Reboot does not orderly shut down your system but sends them a SIGTERM or a SIGKILL and reboots. If you can, use shutdown -r now.
Services
If you need to enable services, you have to edit /etc/rc.conf or put a file with a name of the service in /etc/rc.conf.d. Usually it is something like service_enable="YES". If you don't know how the service can be enabled, have a look in the rc-script in /etc/rc.d or /usr/local/etc/rc.d. When you install for example spamassassin the service is called sa-spamd. You will usually find flags for services in the rc-script as well.
For dealing services you can usually use:
service servicename start
service servicename stop
service servicename restart
service servicename status
If a service is not enabled you have to prepend the action by a one:
service servicename onestart
service servicename onestop
service servicename onerestart
service servicename onestatus
Filesystem structure
The most important part to know is the following:
Binaries from base are in /bin and /usr/bin
Binaries from ports/packages are in /usr/local/bin
Settings from base-applications are in /etc
Settings from ports/packages are in /usr/local/etc
/var is for logging, temporary, transient and spool files. Therefore you won't find a "/var/www" but a /usr/local/www
More informations are in hier(7).
Useful commands:
ctrl+t: This shortcut sends in a terminal the "SIGINFO"-signal to a process. This will show what a process does. Especially useful with commands like "dd".
gstat: get you harddisk activity
Different commands
netstat -tulpn: sockstat -l
route -n: netstat -nr
lsblk: camcontrol devlist
free: There is no free: For an overview use top or top -d1. For a more detailed info use vmstat -m and swapinfo
zfs
With FreeBSD you have to possibility to use ZFS. It is a great file system that will make your life easier through check summing, snapshots, softraids etc. Just be aware that you leave 20% of free space or it might slow down to a level of being not usable anymore.
Important commands
zpool status: Get the status of your zpool - for example if a disk died
zfs list: List all the zfs present in your system
zfs list -o space: List all zfs and how much space they use, incl. the space used up by snapshots
zfs export/import: When you use ZFS on an external drive, you need to export it before you unmount. Otherwise you might have problems mounting it on another system.
zfs send/receive: You can send zfs over the network, great for backups. A helpful blogpost is here
More info in the Handbook; or in the man pages: zfs(8) and zpool(8).
If you want to use snapshotting for automated local backups, I recommend sysutils/zfsnap, sysutils/zfsnap2 or sysutils/life-preserver. When using X the Lumina Desktop from TrueOS has a file manager called Insight which will give you a slider to move the view of the current folder between snapshots. You need to install the Lumina Desktop (x11/lumina) to get it.
For having a safety net when doing upgrades or install new software I recommend sysutils/beadm which will give you boot environments. Practically you can create a new boot environment, play around with it and if it is broken, you can switch back to your old state. A useful blogpost is here.