My Short Experience Using FreeBSD

FreeBSD is a less known and less common operating system amonst regular users. But it exists for a long time. Unfortantely, it is mainly used as a
server and doesn't focus on desktop environment as much. That doesn't mean it won't work as a desktop. About seven months ago, I switched
from Gentoo to FreeBSD as my daily desktop. And I have mixed feeling about that.

It is pretty smooth to install it. I won't repeat how to do it. The handbook includes everything you need to install and how to set up the desktop environment. Everything, including X11, works out of box. The handbook is all I need to get FreeBSD running.

There are two ways of installing applications. First, install pre-built binaries from FreeBSD repository. Second, build it locally and install it. I've been using Gentoo many years. So I don't hesitate to build all the applications.

An illustration about choosing between building or downloading applications

There are a few things I hope we can improve the experience of building the application.

First, the hamdbook doesn't mention where the options of the packages are. When I build some applications, it prompts me about the options for the application. How is it possible to do it on multiple machines or even after I reinstall FreeBSD? I only figured it out when I read some posts in the FreeBSD forum.

Second, it's not clear how to set options globally. It's tedious to set the same options to every applicable packages. Again, I only figured it out from the forum.

Third, it's not straightforward to find the dependencies in the port tree. It's still possible to do that before you start building the application, but I hope there is some kind of script doing that to make it more convenient.

Though there are many open source applications, not all of them support FreeBSD. Some don't have full support. For example, Firefox on FreeBSD doesn't include some features such as sandbox. I cannot open that kind of websites because of it. FreeBSD provides a Linux Compatible Layer so that we can run Linux applications on top of it. It, however, may be quite tricky to configure for some specific applications. I used Obsidian. It doesn't run out of box on the Linux compatible layer. There are a few questions about how to run it, and nobody knew about that. Luckily a person on the forum shared how he/she did that. But that's already been a few month since I tried to use it.

The only thing that made me give up is the graphic card driver. It's unstable. I'm using an old card, but it occasionally crashes and I have the black screen. I have no idea how to recover that. I cannot even switch to the console.

I can see that it's improving during my usage. But in the end I decide to move on. There are some maintenance here and there. I think I don't have the leisure of time to handle that. At the same time I am thinking of buying a new laptop because it's more flexible in my current stage. I cannot use FreeBSD because it doesn't support the latest wifi.

Then I will use Linux again. I don't want to use Gentoo because I don't want to deal with fixing the dependencies conflicts when I update. What's more, I don't want to build from the source or configure too much myself. I think I'll use openSUSE and use most default settings. openSUSE is my first Linux distribution, and I like YaST.

401(k) Plans And IRA

We need money all the time, from young to old, from home to abroad. Income is a critical source of money. When we work, our paycheck is the income. Then what is our income when we're retired? My focus in this post is on the retirements in the US. If we earn enough credits before retirement, we can get Social Security. But there is a limit on how much we can get. What's worse, there is news that Social Security funds are going to run out. To supplement that, there are some options to consider: 401(k) Plans and IRAs (Individual Retirement Account). In this post, I'll show you the differences among common 401(k) Plan and IRAs, and what you should consider when you make contribution and withdrawal.

The idea about 401(k) Plan and IRAs is that you contribute while you're working. Once you are retired, you withdraw from them and those are your income. You usually make investments in the 401(k) Plan and IRAs. The earnings of those investments are yours too. The more you contribute, and the more the earnings are, the more you have when you're retired. There is a risk on the investment you make in the account. If you lose money in your investments, you'll get less too. There are always one risk or another no matter how you plan your retirement.

Differences Overview

The 401(k) Plan is sponsored by an employer. That means it's the company you work for to open and administrate the plan. On the other hand, IRA is opened by you. You can have both. That is not the only difference. From tax perspective, there can be pre-tax, Roth, and after-tax. I'll compare IRAs and 401(k) in most common categories. Common IRAs include Traditional IRA and Roth IRA. Depending the source of the contribution, 401(k)'s contribution can be pre-tax, Roth, and after-tax. They can be inside the same plan.

CategoryTraditional IRARoth IRAPre-tax 401(k)Roth 401(k)After-tax 401(k)
Tax on contributionYes, maybe deductibleYes but NOT deductibleNoYesYes
Deadline to contributeTax return filing deadline (not including extensions)Tax return filing deadline (not including extensions)The calendar year endThe calendar year endThe calendar year end
Tax on qualified withdrawalYesNoYesNoYes on the earnings. No on the contribution.
Investment selectionsManyManyDepend on planDepend on planDepend on plan
Who can participateAnyoneAnyoneEmployer sponsoredDepend on planDepend on plan
Contribution limitYesYesYesYesYes
Required minimum distributionsYesNo as long as the owner is aliveYesYesYes
LoansNoNoDepend on planDepend on planDepend on plan
5-year holding period for qualified withdrawalN/ABegins January 1 of the year a contribution is made to any Roth IRAN/ASeparate for each Roth account and begins on January 1 of the year contributions made to that account. If one Roth account is rolled into another, the earlier start date applies.N/A
BeneficiaryAnyoneAnyoneAnyone but, if married, spouse must consent to non-spouse beneficiaryAnyone but, if married, spouse must consent to non-spouse beneficiaryAnyone but, if married, spouse must consent to non-spouse beneficiary

A Typical Example

The above is a quite high level overview. It may be difficult to understand how that relates to you and impacts your retirement plan. Tax is very important. Here is an example what happens in a typical and qualified scenario for each of the account.

Let's say you contribute $10K. Your balance in the account grows to $25K when you're retired and you withdraw $25K. There is $10K from the initial contribution, and $15K from the earnings of your investment. There are $10K contribution, $15K earnings, and $25K withdrawal.

When you do that in the Traditional IRA. The $10K is from your after-tax income. You may be able to deduct that from your tax return on the year you make the contribution. You should check deduction limit. That matters when you withdraw. When you withdrawal, you must pay the tax on the earnings portion which is $15K. As to the contribution portion, which is $10K, you only need to pay the tax on the amount that's deducted.

Now if you do that in the Roth IRA. That $10K is from your after-tax income. The downside is you cannot deduct that in your tax return. The upside is you don't need to pay tax when you withdraw those $25K from the account. Both the earnings ($15K) and the initial contribution ($10K) portions are not taxed.

In the case of 401(k), if you choose pre-tax (most case), That $10K is from your pre-tax income. That means that $10K isn't included when you calculate the tax you need to pay. But when you withdraw, both the earnings ($15K) and the initial contribution ($10K) portions will be taxed.

If you choose to make the Roth contribution in your 401(k), it's the same as Roth IRA. That $10K is from your after-tax income. You don't need to pay any tax on the earnings and initial contribution when you withdraw.

If you choose to make after tax contribution in your 401(k), same as Roth contribution, that $10K is from your after-tax income. You need to pay tax on the earnings portion ($15K) but you don't need to pay tax on the initial contribution portion ($10K).

What Happen in Withdrawal

It seems relative simple from the above examples. It's quite straightforward on the tax when you make the contribution. There are more to navigate when you need to withdraw. The examples above are for the qualified withdrawal. You need to pay extra attentions when they're not qualified, because you not only need to pay the tax on the withdrawal at your tax bracket, but also may need to pay additional 10% penalty tax.

Qualified Withdrawal

The details may be different in different accounts and be adjusted in future. You should check the IRS websites or other resources to get a complete list.

For the traditional IRA and pre-tax 401(k), you need to be at least 59.5 years old.

If it's Roth IRA, you need to have your account open for more than 5 years. In additional to that, you need to meet one of the criteria:

  1. You're 59.5 years old when you withdraw.
  2. You're permanently disabled.
  3. You inherit the account and take the money out.
  4. You take up to $10,000 as the first time home buyer.

If it's Roth 401(k), you need to have your Roth portion set up for more than 5 years, and you need to meet one of the criteria:

  1. You're 59.5 years old.
  2. You're permanently disabled.
  3. You inherit the account and take the money out.

Early Withdrawal

If you withdraw before you're 59.5 years old or is not qualified, you're doing early withdrawal. You need to pay the income tax on partial or whole of your withdrawal and pay additional 10% tax as the penalty. The penalty tax is only applied to the taxable portion of your non-qualified distributions.

For the pre-tax 401(k), you need to pay your regular income tax and the penalty on all your withdrawal.

For the traditional IRA, you need to pay your regular income tax on all your withdrawal and the penalty on the earnings and the contribution portion if it's deductible.

For Roth 401(k) and Roth IRA, your contribution portion will be tax free and penalty free. But the earnings portion is subject to regular income tax and penalty.

For after-tax 401(k), I don't find too much data about that. Assuming the same principal still holds, which is you only need to pay tax once, It'll be similar to Roth 401(k). That is you only need to pay the regular tax and penalty on the earnings portion.

Early Withdrawal Penalty Exceptions

But as how complicate the rules are, there are exceptions to the penalty. The rules are of course different according to the accounts.

Traditional IRA

  1. You're permanently disabled.
  2. You need to cover medical expenses when it exceeds a certain amount of your adjusted gross income.
  3. You need to cover qualified medical insurance premium during unemployment.
  4. You need to cover qualified higher education expense.
  5. You buy, build, or rebuild the first home.
  6. You inherit it and withdraw funds as beneficiary.
  7. You take a qualified reservist distribution - a distribution from a retirement account to a military reservist or member of National Guard called to active duty.
  8. You have a new baby.

Roth IRA

  1. You reach 59.5 years old.
  2. You're permanently disabled.
  3. You need to cover medical expenses when it exceeds a certain amount of your adjusted gross income.
  4. You need to cover qualified medical insurance premium during unemployment.
  5. You need to cover qualified higher education expense.
  6. You buy, build, or rebuild the first home.
  7. You inherit it and withdraw funds as beneficiary.
  8. You take a qualified reservist distribution - a distribution from a retirement account to a military reservist or member of National Guard called to active duty.
  9. It's due to IRS levy of the qualified plan.


  1. You reach 59.5 years old when you leave your job.
  2. You're permanently disabled.
  3. You need to cover medical expenses when it exceeds a certain amount of your adjusted gross income.
  4. You need to cover qualified medical insurance premium during unemployment.
  5. You inherit it and withdraw funds as beneficiary.
  6. There is an immediate and heavy financial need.
  7. You take a qualified reservist distribution - a distribution from a retirement account to a military reservist or member of National Guard called to active duty.
  8. It's due to IRS levy of the plan.

Alternatives to Early Withdrawal

Some 401(K) plan allows borrowing from it. When you take the loan, you need to pay the principal and the interest. There are two benefits though

  1. Unlike early withdrawal, you don't need to pay the income tax or the penalty.
  2. Unlike taking personal loan, the interest you pay goes back to your 401(K) account, adding to its balance.

What you lose here maybe the potential growth of your investment in your 401(K) if you didn't take a loan. The loan is counted in dollars. The growth of your 401(K) depends on the shares of your investment. So if that investment keep going up, when you pay back your loan, you'll have less shares in your investment comparing to the case if you didn't take the loan.

This is intend to be an overview of what common retirement accounts are and what you need to know when you contribute and withdraw. I encourage you to review them with a professional such as an accountant, or read the articles in IRS website. There are much more details and potentially changes at each year.

Mlterm Configuration

mlterm is a lightweight and fast terminal. You can have your own configuration and customize it as you like.

I like mlterm because it can:

  1. Display texts in non-English locales and supports input methods.
  2. Has less dependencies. Unlike Konsole or Gnome-terminal, you don't need to install the extra packages when you're not using those desktop environments.
  3. lsix to view pictures inside the terminal.


There are two ways to configure mlterm.

First, use the GUI configuration.
mlterm GUI configuration

What you need to do is to use Control + Right Click on the mlterm window to open the GUI configuration. You can make the change, apply it, and view the change. Remember to save it so that you don't lose the changes when you open mlterm later. I found it doesn't save some settings. I have to modify the configuration files.

The second way to configure mlterm is to modify the files. The configurations are in the folder $HOME/.mlterm. There are a few files.The ones I'll make changes are in main, key, and aafont. The main configuration file contains settings for mlterm in general. The key configuration file contains the key bindings. The aafont configuration file contains the font settings when you use anti-alias fonts.

Use Multiple Languages

My locale is UTF-8 and mlterm can detect it automatically. So I don't touch encoding related settings. I do change the settings for fonts and input method.

  1. Set use_aafont to true in the main configuration. Its default values is true if you run it on a desktop environment. It's false in mlterm-fb. So this is optional if you only use mlterm on a desktop environment. I explicitly set it to true in case I run mlterm-fb.
  2. Choose the font for the corresponding encodings. you can choose fonts for different encodings. Since my locale is UTF-8, I set it for the UNICODE one. In the aafont configuration file. you need to put something like this:
    UNICODE = Noto Sans Mono CJK SC 20
  3. Enable anti alias. You need to choose the font type that supports this feature. This is the setting use_anti_alias in main configuration file.
  4. Choose the input method. This is the setting input_method in the main configuration file. For example
    input_method = fcitx

Copy And Paste

It's better to understand selection on X11 before configure copy and paste. Anything you want to transfer from application to application is stored in selection. There are PRIMARY and CLIPBOARD as the destination of the selection. Anything you select or highlight will go to PRIMARY automatically. It's easy do it. You just need to use the mouse to select the text and that will go to PRIMARY. Once you select different texts, the new texts will overwrite the old ones in PRIMARY. To paste from PRIMARY, you can click the middle button or use SHIFT + INSERT. Mlterm supports it out of box. CLIPBOARD maybe is what most of us are familiar with. You copy by using Control + C and paste by Control + V. It's different from PRIMARY in that a new selection doesn't overwrite the contents in CLIPBOARD. You have to repeat the copy to clipboard action to update CLIPBOARD. I am familar with CLIPBOARD's way of copy and paste, so I configure mlterm to use it.


There is a setting to copy the selection to both PRIMARY and CLIBOARD. It's the setting use_clipboard=true in the main configuration file. Its default value is true so the setting is optional. But if you would like to separate them, as I do, you need to set use_clipboard=false to copy the selection to only PRIMARY. Then create a key binding to copy it to CLIPBOARD


exesel runs a command on the selected text. copy_to_clip is a script I create. Remember to put it in the folder that can be found from PATH.
Here is what the script copy_to_clip does:

echo $@ | xsel -i --clipboard

mlterm passes the selected text to the command copy_to_clip. What that does is to echo it to the ouput and pipe it to xsel. xsel takes the input from the pipe (-i) and copies it to CLIPBOARD (--clipboard).

Paste from CLIPBOARD

To paste from the clipboard, I configure the key bindings. The key bindings are defined in the key configuration file. The format is key=feature. The mlterm man page lists what keys can be used and what features are supported. To paste from CLIPBOARD, I use the feature proto:paste clipboard. I bind it to both right click and CTRL +SHIFT +V. The binding are

Control+Shift+v="proto:paste clipboard"
Button3="proto:paste clipboard"

There is another feature INSERT_CLIPBOARD that allows you to paste from the clipboard. But you can only assign one key binding to it. But you can have multiple bindings to the proto features. That is why I use it and bind to both Control+Shift+v and Button3.

Use lsix

Since I mentioned lsix on mlterm, I would like to add to that there is an issue with it. The pictures are not displayed at the right place on mlterm. The good news is that lsix knows about that and has a fix for that. However, it only applies the fix when it detects that the terminal is mlterm. It checks the terminal type. But mlterm reports it's xterm. To fix that, I put termtype=mlterm in the main configuration file. You can also pass it in the argument (--term=mlterm) when you starts mlterm. That tells mlterm to report itself as mlterm and lsix can apply the fix. With this change, lsix will display the pictures at the right place.
Display images using lsix

Use DisplayLink in Gentoo

I've been using Gentoo on my desktop for over five years. The computer connects to a 1080p monitor. Recently I use a DisplayLink 6xxx dock station to connect to a 4k monitor.

Current Configurations

I don't have any plans to replace the computrt. The only option is to make it work with my current configurations.

  1. The graphic card can only support 1080p.
  2. I have two monitors. One is 1080p, the other 4k.
  3. I have a Dell Universal Dock - D6000. It's using DisplayLink and can support 4K monitors.
  4. I'm using i3wm. There aren't any display managers. Instead, I start x11 when I login on console. Only i3wm is used.

Given the existing configurations, I decide to connect to the 1080p monitor from the graphic card, and connect to the 4k monitor as a second monitor via the dock.

Install the Driver

I follow Gentoo DisplayLink wiki to set up the kernel. The wiki however looks outdated in general.

The only official driver for Linux is for Ubuntu. This article suggests to adapt the script to port the driver to other distributions. It's easier said than done. There is an overlay zyrenth that has ebuilds for displaylink-driver and evdi packages. The ebuilds are solid. But there are some issues with evdi and displaylink manager themselves.

  1. evdi version 17.0 fails to compile with kernel 5.10. It's fixed in later versions.
  2. evdi version 19.0 is not compatible to Display Manager 5.3.1, which is the version from the displaylink-driver ebuild.

The only viable option is the evdi version 17.2. It's not provided in the overlay zyrenth. But build on top of others' work, I'm able to create my own ebuild. I follow the wiki custom ebuild repository to create a local repository. How to create a 17.2 ebuild? Just copy the 17.0 from overlay zyrenth and rename it 17.2. Then I have the ebuild for evdi version 17.2 and install it.

Configure HiDPI

The 4k monitor's maximium resolution is 3840 × 2160. Everything seems quite small on it. It's unpleasant to use. We need to conifure it for HiDPI. According to HiDPI document, I make this changes.

  1. Pass --dpi 196 when using xrandr.
  2. Set the xft.dpi: 196 in .Xresource and merge it with xrdb.
  3. Set the scaling factor for Gnome environment.
    gsettings set org.gnome.desktop.interface scaling-factor 2
    gsettings set org.gnome.desktop.interface text-scaling-factor 2
  4. Set the scaling factor for Qt.
      export QT_FONT_DPI=196
      export QT_SCALE_FACTOR=2
  5. Set the scaling factor for GTK based applications.
    export GDK_DPI_SCALE=2

I don't use Gnome or KDE and haven't verified how the settings for Gnome and Qt work. It seems xft.dpi setting makes the status bar in my i3wm larger and nicerr. But it doesn't make Firefox or Thunderbird or other GTK based appliations more legible. I have to use GDK_DPI_SCALE.

Probably it's because of my own configuration, I spend quite a while setting the HiDPI. I haven't tried other desktop environments. While I'm searching online, I feel like some desktop environment has the configuration from the GUI. That may make it easier for those desktop environments.

Connect to the Second Monitor

The second monitor is connected via the dock. The monitor capability in the dock isn't hotplug-able. So it's important to connect it to the computer when the system boots. After that, we can disconnect and re-connect the dock and we still can use the second monitor.

There are some extra work to connect to the second monitor. It's needed only one time when x11 starts.

  1. The displaylink-driver installs a dlm systemd service. The service has to be started after x11 starts. Since I start x11 from the console, I have to run systemctl start dlm once i3wm starts.
  2. I have to run xrandr --dpi 196 --output DVI-I-1-1 --mode 3840x2160 --rate 60 --right-of VGA-0 once after i3wm starts.

After running that, the second monitor is ready. I can disconnect and re-connect the dock at any time.

There are some research involved. It's not too difficult to find them. But overall, there are documents I can borrow to set up the DisplayLink for Gentoo.

Learning from Installing Smart Switches

I installed a few smart switches and automated my house lighting recently. It's a long journey and I've learned a lot along the way. As a software engineer, I'm surprised there are a few in common in software engineering and replacing switches. Probably those are common in tackling a problem.

Understand the Goal and Resources

In my daily job and other programming, I mostly focus on completing a product or getting a service online. They're not trivial or simple by nature. We analyze and divide that into minimum viable product, and continue to create tasks and solve the small tasks one by one. Like what we do in the software engineering, I think of what my goal is in this lighting automation project: automate the lights in my house. But it is not every light. I just need to automate lights in the dining room, kitchen, living room, garage, and the doors. This goal is clear and well scoped. It's also clear that I need to replace the existing switches with smart switches, connect the new smart switches to the hub, and configure the rules in the hub to automate the lights.

With the goal, it's also important to understand the resources and priorities. I have a full time job and I like to spend time with my family. That means I cannot devote myself to the project all the time. The good thing is there is no hard deadline. I can think of the small task and work on that one by one. For example, I can just replace one or two switches at a time. With the goal in mind, I need to be flexible and consistent.

Learn And Explore

I feel like there are much to learn in software engineering: language, design, architecture, and process, to name a few. It doesn't mean everybody has to learn all of them now. What I mean is the situations and requirements may change. We need to adapt to that and learn new technology on the way. For example, software engineers who are interested in Mac development won't ignore Apple M1 when it's released. Learning is a nonstop journey. Exploring is how to get to new and unfamiliar areas. It looks simple to replace the switches. But in the end, I need to spend some time in learning some basic wire code, understanding the differences between a regular switch and a smart switch, and understanding how that particular smart switch works in 3-way and 4-way wire. It only becomes possible after I read and explore the way to install the smart switches properly.

Don't Rush

There is always some form of design, development, testing, and release cycle. It's said that if we have a flaw at one stage and carry that down the cycle, it'll cost more to correct it. The later it's fixed, the more expensive it becomes. It's a waste of time and counterproductive if we have to re-work. It also applies when we replace the switches. If we don't get the wires connected right before putting it back, eventually we have to open the plate and correct that. Otherwise, we'll not be able to use the switches. It's important to get things right instead of done quickly. It's critical not to rush to finish it given that it's related to electricity. If we don't do our diligence in the safety, we can get shocked.

Work with the Existing System

It looks great and cool to work on something brand new. That means we have more choices to use new technology. In reality, we most likely add new features to the existing system. It doesn't sound that exciting. But we still need to weigh in how bad the existing system is, whether a from scratch new system can solve those issues, how many resources we need and we get, and whether there are other higher priorities. Replacing the switches is also working with the existing system. It's just too much work to replace the entire wiring in the house. There seems to be some wiring there I don't understand, for example, a white wire is connected to a black wire directly. It's also beyond my ability to try to make it follow the code.

It's fascinating to me that we can borrow the method and approach from one discipline to another. That reminds me that learning is a on-going journey and it can be applied to multiple areas.