The move from Linux to FreeBSD

About 2 months ago, I had a spare VPS at my host, Hetzner. So I decided to play with FreeBSD which was being offered for Hetzner servers and VPSes.
That’s how the whole thing started. I didn’t have much problems getting the concepts because it belongs to *nix family of OSes and I have been a pure Linux user since 2008.

First of all the basic difference between FreeBSD and GNU/Linux is that Linux is just the kernel and GNU is the userland. In layman’s terms, the hardware interface is called Linux, while the rest of the part: the shell, core tools, etc are GNU.It’s a piece from there, another from somewhere else and merging the whole thing into one collectively known as GNU/Linux. Linux itself cannot boot without GNU and GNU will not work without Linux (Yes, there is a GNU kernel project called GNU Hurd, but I don’t how far that went).
In FreeBSD, the whole thing is a complete unit. FreeBSD was derived from the original AT&T Unix and open sourced. You can read more about the differences at over-yonder.

So, while playing with my VPS, I found a major difference between Linux and FreeBSD: performance and memory usage. The performance was nearly same as Linux, but slightly better. Memory usage change, was drastic. FreeBSD is just too good at managing memory. My server earlier used to consume over 1 GB of memory for running PHP, MySQL and Nginx. Now, it doesn’t even touch 500 MB! It’s always less than 500 MB. Everything is just same, configuration, etc. Only OS changed.
After the trial VPS, I started moving my stuff from the Gentoo VPS to the new one. Ran it for testing few days, and it continued to amaze me. FreeBSD’s official slogan is “The Power to Serve”. So much true is that! And that ended up as migrating other VPSes to FreeBSD as well.

Meanwhile, I was facing a lot of insufficient memory issues on my desktop, which is a five year old Pentium Dual Core 2 Ghz (E2180) with 3 GB memory. It used to swap out so much; I did try tweaking vm.swappiness, but it still maxed out on memory. After the great experience on my servers, I decided to move my desktop to FreeBSD. Since my hardware doesn’t involve any crazy things like Nvidia GPU or something, it was an easy task. The problem comes with migrating data, FreeBSD <-> Linux data read/write is not so friendly. This was solved by using my external HDD as a tape drive, I just wrote the whole data as a tar archive to the disk 😀 and restored it after installing FreeBSD. Got this great tip from ##FreeBSD @ FreeNode.

Downloaded memstick image

[who uses CD/DVD these days, anyway?] of FreeBSD and it booted. It has a simple command line installer — If you’re a Ubuntu/Fedora user, please install Arch/Gentoo first to get the taste of how command line installation works. Also it is useful to have another computing device which can help you ask for issues or Google around for stuff if you get stuck. The FreeBSD handbook is quite thorough and easy to follow. In my case the another computing device was my Nexus 4. Used it to chat on the FreeBSD IRC channel to ask for help when I got stuck and also search around. 🙂

The base installation was complete within 10 minutes, if you remove the time spent in solving issues and the issues were barely because my drive configuration is bit different than normal desktop users: I have one SSD and 3 HDDs. I use SSD for the OS and put these HDD on software RAID-0 for performance, backing up data regularly to an external disk. It is not so simple to do RAID-0 striping in FreeBSD, particularly if you come from Linux background. You need to have similarly sized disks, otherwise it won’t stripe. In my case, I have 2 x 500 GB and 1 x 160 GB. So effectively I can use only two disks in stripe. But I want large storage, so the solution is using stripe and concatenate together.

 The two commands do this: Create a stripe of two disks, ada1 and ada2 which are each 500 GB and then concatenate the third disk to the raid array. The effect of this is, you get whole 1.16 TB for use, while RAID works for the first 1 TB part of the disk. Once the concat disk has been created, it can be partitioned using gpart.

Partitions done: I placed swap, /var, /usr/ports/usr/src on the initial part of the concatenated disk, i.e. /dev/concat/disk and /home with the remaining part. Reason: Those directories have large disk
accesses. Home also does, but only a small part of it would be outside the raid array. There is no filesystem confusion in FreeBSD unlike Linux: There is just one filesystem you need to use for everything: UFS2. It supports everything a modern computer would need, SSD TRIM support too. Simplicity. And there are not many parameters that can be tweaked. Just enable soft updates while formatting (enabled by default) and soft updates journal to prevent data loss in case of a power failure.

The raid array and concatenation partitions need to be done manually before installing. When the memstick boots, you’ll be greeted with the installer, with an option to exit to shell. Exit to the shell and read the manual pages (and the handbook on your another computing device, as well). Create the partitions and enter installer again by just typing the command bsdinstall.

All that stuff is not at all needed if you have a simple disk configuration.

Once base system has been installed: It’ll just give you a black screen. There is no GUI or anything. You need to install everything yourself using the package manager or ports. The FreeBSD ports system is very, very powerful. You can choose what options are enabled in a particular application and install it without unwanted dependencies. For instance, you don’t want PulseAudio, disable it. Gentoo is quite similar here (because it was developed from the idea of FreeBSD’s ports system), with every package being controlled by USE-Flags. But the difference here is, you need to compile everything on Gentoo, including the core system. In FreeBSD, you get core system updates from the community, tested
properly. All extra applications need to be installed and managed by you. Also, there is a binary package repository from where you can install packages directly, not having to compile them with manually. But in order to do that, you must not convert the package database to the next generation package manager pkgngpkgng installation repositories are not ready yet. I chose the ports way, since I like to keep my system slick and exactly what I want; which was one of my reasons why Gentoo was my favorite Linux distribution.

Configuring GUI on FreeBSD isn’t really a big deal, if you know what and where to look for. Like how to tweak fontconfig to get clean & beautiful fonts, etc.

Currently running FreeBSD 9.1-RELEASE-p3 (it has to be updated after installation of 9.1-RELEASE) with KDE. Firefox-10 tabs, Thunderbird running and KDE. Memory usage is 700M. While I did the same on Linux, memory usage used to go beyond 1 GB and no soon it’d start swapping if I launched more tabs in Firefox. To my surprise, even Chromium doesn’t seem to hog memory on this super-polished OS. Chromium with a couple of tabs, along with Firefox and Thunderbird. Memory usage never went beyond 1.5 GB. In Linux, it’d swap 50-100M there by making it ridiculously slow.

The only things I miss are: Dropbox and Android SDK (adb and fastboot to play with kernels, ROMs and stuff on my phone). Even VirtualBox works and I have got USB support working on it, so it shouldn’t be a big deal to run Arch Linux in a VM and use adb  and fastboot fastboot  from there while exporting the Dropbox folder from Arch VM and connecting it to my system folder, I’ll try that and do that as a separate post when I have time.

FreeBSD gave my computer a new life, otherwise I was nearly going to get a new desktop because of shitty performance. In other words, it saved me ₹35000+ 😀

People on the IRC are very helpful to n00bs. One guy even killed his recovery pen drive to try out the earlier mentioned tar backup system, treating a USB disk as a tape drive.

Any amount of thanks won’t be enough to @freebsdhelp on Twitter, who guided me well whenever I got stuck.

Also, if you happen to plan one such installation, do follow this guide: A FreeBSD 9 Desktop How-to

72 Replies to “The move from Linux to FreeBSD”

  1. what happened? your small ego got hurt by my comment? If you are truly a geek, you will go and find out the cause of the difference in the memory. You look like a narrow-minded, insecure Indian.

    1. Do you even understand timezones and that people aren’t awake all the time to read and approve comments, before calling me names like insecure Indian? Anyway, I don’t have any ego issues and would love to be proved wrong, I’m always open to learning new things.

      Somebody has earlier posted about Unified buffer cache (see the comment by Shane).

      If you do know the reason about the drop in memory usage please specify the same in reply. 🙂

  2. I stopped reading when he mentioned the 50% drop in memory usage. He did not mention what counters he used to measure the memory and what other differences appeared in the behaviour. Linux has unified cache since kernel version 2.4.

    I am sure that there is a perfectly logical reason behind the difference in the memory usage, but one cannot proclaim anything say anything in favour of FreeBSD or against Linux, just because a layman user thought that the superficial differences with whatever counters he used were sufficient to show one system as better from another.

  3. Hi,
    it’s not safe to use tar to transfer your data. A tar archive is not resilient if even a single byte is corrupted. Use Denis Corbin’s dar instead. It gives you the same benefits of tar with much better protection against corruption of the archive.

  4. Half the memory use does not surprise me at all and may come down to the effectiveness of FreeBSD’s Unified Buffer Cache.

    Back in 2004 I was working in computer forensics and had to very quickly provide some statistical analysis of a 500MB log file for a high profile court case. The analysis machine I had only had 1GB RAM and because my test script was not very elegant and too brute force, it was making multiple read passes over the log file, which was taking an absolute age to complete.

    I found at the time that the memory usage had maxed out and the machine started swapping. I was surprised by this, because I thought a 500MB file would be cached and so read just once into memory and then the multiple read passes would occur only in memory.

    Looking further into this I read about systems which would store the same data twice in memory, once in the buffer and once in the cache and that NetBSD’s UBC meant that such data would be stored just once.

    So I tried NetBSD at the time and the difference in memory usage and performance was stunning! With NetBSD and its UBC, memory usage was halved and the entire file was cached and read only once from disk, allowing my slow script to perform the multiple pass reads all in memory. What was going to take weeks was now taking less than an hour, essentially due to the switch from being slow disk bound to being fast memory bound.

    Yes, had I been more knowledgeable and skilled at the time my script could have been more elegant and perform a single pass regardless of the system, but in this edge case the NetBSD UBC was awesome for what I needed at the time.

    I tried various Linux distros, OpenBSD and FreeBSD at the time and although Linux apparently had a UBC implementation, it appeared to either not be working or otherwise was not enabled and I did not know how to enable it. I am now happy to see that FreeBSD’s UBC is also working well.

      1. Pertinent info on UBC and pre-UBC double caching is here:

        “file data in the buffer cache is copied into page cache pages, which are then used to satisfy page faults on the application mappings”

        “This double-caching of data is a major source of inefficiency. Having two copies of file data means that twice as much memory is used, which reduces the amount of memory available for applications. Copying the data back and forth between the buffer cache and the page cache wastes CPU cycles, clobbers CPU caches and is generally bad for performance.”

        I think this and what you and I have witnessed shows that a simple change of OS can actually double memory efficacy. I’d be really surprised if Linux is still double caching though, since such big gains can be had with the use of UBC and I think this is especially important in this age where memory performance and usage efficiency has become so important due to virtualization and cloud computing.

  5. I use FreeBSD and OpenBSD in production enviroments, Gentoo on my home computer, and Linux Mint for friends/family who want to leave windows and have it “just work”.

    The BSDs _do_ manage memory much better than Linux, along with being much more stable. However, in both cases (linux and unix) you might be better served switching to XFCE over running KDE. KDE is a memory hog no matter what system is using it :D.

    1. Nothing special. I just used the standard tools (ps, top) to measure. I don’t remember exactly, but I think I used the system monitor that comes with KDE.

  6. I fell in love with Linux and FreeBSD over ten years ago. I like to use FreeBSD on servers as it’s a lot simpler under-the-hood and Linux as a desktop. I don’t use a swap partition on either and have never run out of memory !

  7. Downloaded memstick image [who uses CD/DVD these days, anyway?] of FreeBSD and it booted. It has a simple command line installer — If you’re a Ubuntu/Fedora user, please install Arch/Gentoo first to get the taste of how command line installation works.

    So in the year 2013 you’re wondering who uses CDs or DVDs, but you’re not wondering who uses command line installers? 🙂 Red Hat Linux had a graphical installer since before 2000 (not to mention Windows 95).

    1. Nice pun there. Please explain how you’d fire up a GUI installer when installing on a server over SSH from a rescue system. I know this post is not about installing over SSH, but that’d justify the existence of CLI installers.

      1. I’m not sure I understand the setup you’re describing.

        Anyway I have triggered a remote reinstall by booting the installer and automating it with kickstart (the solution for RH based systems) and I didn’t have to care if the installer used a GUI or not. By the way, if I’m not mistaking FreeBSD didn’t have any automation until a couple of years ago.

        There is also the option of displaying remotely over VNC.

        1. You can boot an installable medium if your server provider supports that. What if the server provider provides a full linux (debian) that boots over PXE? (This is what Hetzner does, actually). Anyway, pointless discussion lol.

  8. I installed FreeBSD into my 10 years-old laptop which is 1.4 Ghz dual core. After installing Gnome 2 and Xorg, Firefox and Thunderbird work like a charm! it’s awesome. Love this.

    1. For some reason I feel the article is a bit exaggerated. While much of it could be true that it’s slower because they moved to clang. I don’t really know nor have the time to test it.

      Also, compiling Xorg on i5-4670 takes less than 10 or 15 minutes (on gentoo, which I use).

      1. Sorry for posting on a comment from three months ago. Just so you know, though, the aboutthebsds website is a troll site. Trust me, nothing on there if factually correct. For example, he says it takes at least 2 minutes to boot up just the kernel of FreeBSD 10. I’m not sure about your system, but on mine, it only takes 1 for the whole system. Another example is where he states that almost all of the money donated goes to buying beer for the developers, who become so drunk they write awful code. The foundation publishes reports of where the money goes, and beer is not on there. Plus, the code for the FreeBSD operating system is widely regarded as outstanding. I write this because I’ve seen a fairly large amount of people reading this website, and getting a completely wrong picture of the BSD ecosystem.

        1. Going by my experience when I wrote this article, I was impressed with its performance in many aspects, but the needs work more to enable the average desktop user to be able to use it easily. Ask Windows user to use Linux distribution like Ubuntu or Fedora, they’ll be able to make their way out. But FreeBSD, difficult. I had difficulties in adjusting sound jack, there was no GUI for that!

          That said, it was and still is great for servers. Best example is WhatsApp.

  9. i think FreeBSD can be good desktop for home also 🙂 had installed the system on my PC and laptop computers and all the time it worked just perfect. I met many people who would like to move to FreeBSD but all of them have the same “problem” – ain’t nothing but console just from the “box”, so i like to install different environments on the system 🙂 The most popular is Gnome.

    Here is short “how-to” about how to install Gnome 2 on FreeBSD 9.2 🙂

  10. Hmmm…nice to see a change of pace but arch wih lxde and firefox hand handbrake doing 1080p i finally break a 1GB. Did you run prelink?

  11. this looks like a very superficial review. linux has advanced a great deal in the last years and I haven’t seen any such difference in resources as you say. I use a Pentium 4 with 1GB memory at home and never had any problem with linux. this looks like a big exaggeration.

    1. This was never meant to be a review. It is just my personal experience and I don’t have anything against Linux. I have been using Linux since 2007.

      Also, I’m not exaggerating. If you can, give a try to FreeBSD on your machine. I’m sure you’d be surprised like I was (if you know your way around shell, etc).

  12. Do you expect us to believe that 3Gb of ram isn’t enough to run a Linux desktop? That’s just bullshit and you know it.

    FreeBSD is a great OS but don’t lie to us about Linux.

    1. I’m not lying lol. These days browsers have become memory hoggers. But I am still dumbfounded as to why the same browser consumes much lesser memory on FreeBSD and system doesn’t even touch swap, which used to be a frequent thing for me on Linux.

        1. Opera has been discontinued for *nix since late after they moved to Blink. Also, Chromium = Blink. Opera = Blink. I don’t see a reason to use the latter when it is a duplicate of the former plus may be some additions like a mail client and stuff.

      1. Usually the time when my Win XP 64 sux the most is when i open many pages in browser and try to save it all on hdd as .html .mht or single archive .maff or print to pdf. But ignoring security topic, i like this OS for desktop-usage, especially after putting cygwin and gnu-tools paths into PATH, so i can use many tools like ls,grep,tr, | , less just from “cmd” even without “chrooting” into cygwin.
        I did a test. All os installed on virtualbox with 1gb ram and swap 2gb or more. Everytime i used the same amount of about 50 “big” webpages (html with folder, all pages about 400-500 mb on hdd).
        Win XP 32 similar like 64 = total virtual memory used: full ram 1gb+ pagefile size increased to 2xx mb= 12xx mb (so Firefox used 12xx – 180mb of starting value used by OS.

        WinXP 32/64 = 12xx mb VMem (firefox 32 in both cases) (starting ram usage 180-2xx mb)
        Win 7 32 = 14xx mb (firefox 32) (starting ram usage 300-4xx mb) b means B (byte), not b (bit)
        Win 7 64 = 14xx mb (firefox 32) (starting ram usage 300-4xx mb)
        Win 7 64 = 18xx mb (firefox 64) (starting ram usage 300-4xx mb)
        Fedora,Ubuntu,Debian,Slackware, and few other i tested (most of them 64bit os, xfce/gnome) : about 12xx mb minimum of total ram+swap (starting value about 180-220 mb or more)
        So for all these OSes VMem usage increased quite similary by about +1GB of VMem (except Firefox64+ Win 7 64).
        FreeBSD 10 64bit = 650 mb [xfce] (on Xfce starting usage about 5x mb/1GB, on Gnome about 100mb/1GB)
        VMem usage by Firefox 27 in this case increased not by 1GB but about 600mb
        I thought maybe its because on FBSD Firefox was installed from ports with Make compile settings good for this PC. So i installed Funtoo Linux and installed Firefox from source.
        Funtoo Linux = 147x mb (xfce, starting value 13x mb)
        So, i thought, maybe its because of kernel – i tried to install Gentoo FreeBSD. OS installed, Twm works, but i had problems with emerging Firefox, Thunar and running Xfce in general.
        For all Win and Gnu/Linux OSes the VMem usage was full ram taken or 8xx – 9xx mb and 2xx-5xx of Swap. In case of FreeBSD, the final stabilised status of VMem usage was 70mb ram and 580mb Swap. I noticed difference between Ubuntu and Fedora. Ubuntu when loading pages, first used only ram, when it was about max usage its started to increase swap usage starting from 0 mb / 2GB. Fedora started loading swap earlier, when it was about 80% ram usage.
        This is interesting lol, its seems Win+Vbox_FreeBSD+Firefox is better than Win+Firefox only, maybe not in speed but in mem usage. 1gb vs ( 600mb + vbox_OS 50mb Xfce / 100mb Gnome/140 mb Kde)= 1gb vs 650-750mb. Adding Vbox program default usage still should be about 200 mb less.
        Im going to delete Gentoo-FreeBSD VMachine, if Sb can compare memory usage by Firefox (or Opera
        or other browser) between Gentoo/Funtoo Linux and Gentoo FreeBSD or knows a
        link to a site with such test im curious of results.

        1. Interesting stuff.
          When I wrote this post, I had an old E2180 machine on which I tried FreeBSD 9.1. Now I have a Haswell machine, and recently FreeBSD got Haswell gfx support. So I’m planning to try FreeBSD 10 after exams. Should be exciting :D.

      2. you ignored my post, but maybe its good. i checked screenshots from my testing again and this FreeBSD VMem value was not stabilised. i did test again. Firefox pages seemed to be loaded but swap was gradualy growing. Slowly slowly it grew from 6xx mb total, to 1050mb (ram+swap).
        DesktopBSD also +900mb
        PC-BSD = incresed by 900mb-1gb
        To be precise on gnuLinux the result several times also was about 900mb. So firefox on xNIX uses similar amount of vmemory like on Windows XP/7 (in best case its 900mb vs 1gb)

        Maybe swap usage depends also on filesystem. e.g. on Ext3/ext4 fsystems “allocation unit” is usually 1KB (minimal). In Windows XP NTFS it can be set to format disk with allocation unit (block size) 512B/1kb/2kb/4kb. Default is 4KB. When we have lots of small files on one “1KB” partition and same files on other “4KB” partition, in 2nd case space taken from disk will be bigger.

    2. It depends on what your desktop is, if you had read the article
      you would know, that the person uses KDE desktop. my laptop
      has 3GB of memory (2.85), and I can’t run KDE unless I compile
      from source (gentoo).

  13. Have you looked at FreeBSD Jails yet? On one FreeBSD server you can have many Jails which hardly use any hardware resources but give you multiple virtual servers. I use ezjail-admin and configure /etc/natd.conf so that I can access the Jails via port numbers. Fantastic technology. See my (rather messy) notes here

      1. Most providers of FreeBSD VPSs or VMs would use jails. I use them to provide FreeBSD VMs for my students so that they can learn some UNIX admin – they have root access in their jails.
        The wonderful PC-BSD provides a great tool for managing jails, have you tried PC-BSD on your desktop?

  14. why does memory usage matters so much to you?

    My system still uses only 10% of my total memory in Gnome-shell with all my desktop apps loaded(firefox, chrome, deluge, nautilus) in Fedora 19.

    FreeBSD still doesn’t support all of my hardware (AR8161ethernet, Intel Corporation Centrino Wireless-N 2200). No optimus support either from nvidia or the community.

      1. Ok. fair enough.

        I used Fedora>Arch>Debian>FreeBSD for quite some years.

        I used FreeBSD 9.0 in my old computer for more than 6 months and was experimenting all the flavors of FreeBSD to figure that
        whatever that’s given in is full of lies. Matt carefully ignores the deficiencies of FreeBSD and highlights only the features what FreeBSD can do comparably with Linux. But Linux can do hell a lot what FreeBSD can’t do. FreeBSD is stuck in the past and it can’t even have a decent binary package management yet. They barely started to have KMS now from FreeBSD 9.1. Sorry if it all sounds so negative.

        1. If you consider the number of commercial interests and sheer volume of the developers on the Linux kernel vs any BSD project, you should be impressed by how far FreeBSD has come. The only company interested in FreeBSD for the desktop right now is ixsystems. There’s a big difference in support there.

          As for package management, pngng has some promise, but there’s a reason I started working on mport for MidnightBSD years ago. This is a big defect n the BSD world.

        2. It’s not that it’s full of lies, it’s simply outdated. The guy mentions 5.2-RELEASE being the newest version, with 5.3-RELEASE on its way. Both were released in 2004.

          1. Things have changed a lot in last 10 years in linux and matt’s page exist for quite some time since 2005. It has been carefully edited in course of time , if you keenly observed over years.

    1. Only if it’s old or a desktop chip. The Optimus hybrid NVIDIA GPUs in newer laptops do not work. If you’re buying a new laptop, the only thing you can buy is Intel.

      1. Intel has open source drivers (?) which is why it works pretty good almost everywhere.. The newer Haswell iteration has even better GPUs (anyway, I’m not upgrading for at least 1.5-2 years now).

  15. Something that is missing to be sure the memory consumption thing is really relevant, you didn’t talk about flavors of Linux/FreeBSD, if by any chance one was 64bits and the other 32bits, it can make quite some difference because of the pointer size. (maybe not really 2x, but still sufficient to be notified). Do you have both linux and freebsd target architecture at hand?

  16. maybe thats why the old shared server running freebsd 4.1 on decade-old hardware could handle 100 times more traffic than my linux vps running on much newer hardware (and that old server had less total ram than the vps and was shared with lots of other users) – and I thought it was just due to virtualisation slowness and bloat in newer versions of php and apache! .. maybe its time I revisited planet freebsd!

  17. Thanks for your post. You know, I understand what you say about Dropbox, but I miss it much less now that I’ve discovered BitTorrent Sync. You should give it a try.

Discuss this