summaryrefslogtreecommitdiff
path: root/content-org/bsd.org
diff options
context:
space:
mode:
authormms <michal@sapka.me>2024-03-04 23:23:11 +0100
committermms <michal@sapka.me>2024-03-04 23:23:11 +0100
commit3cbe80fd1738dfb896e0cefa1fc2cf0d0ea74319 (patch)
treec0c837bc1c38564060ebfd08a116199ae19cf556 /content-org/bsd.org
parent72371c30c3561b8dc5db01d19f947442e1a7ad8b (diff)
chore: bsd to org
Diffstat (limited to 'content-org/bsd.org')
-rw-r--r--content-org/bsd.org737
1 files changed, 737 insertions, 0 deletions
diff --git a/content-org/bsd.org b/content-org/bsd.org
index 386cb7f..9176f3a 100644
--- a/content-org/bsd.org
+++ b/content-org/bsd.org
@@ -372,10 +372,747 @@ But my reasoning was simple: Plausible gathers so little information that the ha
LSP for Java/Scala is still a joke, and I refuse to pollute my system with Intellij.
[[https://go.dev/][Go][, on the other hand, is a modern language designed for humans. I am not good at it, but I am infinitetly[fn:infinit] better than a week ago.
[fn:infinit] Any positive number would be infinite progress compared to zero, or as an old wise man once said: "to have a nickel and to not a nickel is already two nickles".
+** DONE OpenBSD: Live from OpenBSD in Amsterdam
+CLOSED: [2023-07-19 Mon 22:47]
+:PROPERTIES:
+:EXPORT_FILE_NAME: moved-to-openbsd
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract A short info on OpenBSD Amsterdam
+:EXPORT_HUGO_MENU: :menu bsd-openbsd :name "Forwarding requests from Relayd to a custom webserver"
+:EXPORT_HUGO_PAIRED_SHORTCODES: img-r
+:END:
+
+This site, in its infancy, was running Debian on Linode.
+Then I moved [fn:fbsd] to [[https://freebsd.org][FreeBSD]] on Vultr.
+Today marks a day of another migration:
+hello from [[https://www.openbsd.org/][OpenBSD]] running on [[https://openbsd.amsterdam/][OpenBSD Amsterdam]].[fn:bloggers]
+[fn:fbsd] [[https://michal.sapka.me/2023/early-freebsd-thoughts/][Early FreeBSD Thoughts]]
+[fn:bloggers] for technical folks, tinkering with their sites is just as fun as making them.
+I still have to create a "Yet Another Blog System", but discovering BSD was a great award in itself.
+
+*** OpenBSD
+
+#+attr_shortcode: "openbsd.png"
+#+begin_img-r
+OpenBSD Logo
+#+end_img-r
+OpenBSD is one of the three most popular BSD distributions.
+While [[https://www.netbsd.org/][NetBSD]] focuses on running on obscure hardware[fn:netbsd], and [[https://freebsd.org][FreeBSD]] has ZFS as its killer feature, OpenBSD is all about security[fn:security].
+I was very happy with FreeBSD, but at the same time, I was never fully confident in my ability to configure it securely.
+Not that my server hosts anything of real value[fn:mwl-mail], but I still wouldn't like a machine I administer to become a cog in some botnet.
+Between learning forensics and a new OS, the latter seems nicer.
+
+OpenBSD's official project goal[fn:goals] states that even though they aim to provide the most secure OS, each developer has their own goals and can freely pursue them as long as the project adheres to these goals.
+It's a very different approach to what we see anywhere else.
+There is no 10-year roadmap and constant consultations.
+Instead, we have a hacker-oriented[fn:hackathon] culture.
+This resulted in multiple projects having their inception in OpenBSD, like [[https://www.openssh.com/][OpenSSH]] or [[https://www.libressl.org/][LibreSSL]].
+
+OpenBSD ships with a secure by-default mindset.
+All non-essential services are disabled, and those running are using sensible configurations.
+For example, I had huge problems configuring a firewall on FreeBSD, especially for IPv6[fn:ipv6].
+On OpenBSD, it was much simpler.
+
+OpenBSD being a BSD, provides a complete system - system and user space are developed together.
+No GNU tools are needed, as everything comes together.
+At the same time, BSDs come with a lot of surprising things out of the box.
+FreeBSD wowed me with Jails[fn:jail].
+
+All in all, a lot of things I've learned on FreeBSD are easily transplantable to OpenBSD.
+They say that all BSDs are separate OSes, a stark difference from distributions of GNU/Linux.
+I fail to see it, as so much works the same.
+The package manager of FreeBSD may be more modern, and the separation between system space and user space[fn:hier] is not so evident here, but so many things work the same.
+I can not pretend to be a pro-BSDer, but I fail to see evidence of them diverging so narrowly to call them completely different OSes.
+But then again, maybe it's just my poor judgment and love for POSIX.
+
+And still no SystemD(1) in sight. I don't have enough willpower to learn forensics or Rust, not even to mention an OS-level complex PID1 process.
+
+## OpenBSD Amsterdam
+
+#+attr_shortcode: "openbsd-amsterdam.png"
+#+begin_img-r
+OpenBSD Amsterdam logo
+#+end_img-r
+I had a similar exodus of server providers.
+First, it was Linode, then Vultr.
+Linode became useless when I wanted to try BSD.
+Vultr was great as it provided images of FreeBSD and OpenBSD for its VMs.
+But why stop halfway?
+Vultr doesn't use BSD as the base system.
+While it may not be a big deal, I've recently learned of[[https://openbsd.amsterdam/][ OpenBSD Amsterdam]][fn:aws].
+
+OpenBSD Amsterdam is a small company based in (to the surprise of everyone reading this) Amsterdam.
+What's even better is that they serve OpenBSD VMS from OpenBSD hosts via vmm(4) and vmd(8) - a small virtualization driver baked into OpenBSD. Cool.
+
+What's even cooler is that they give a significant part of their earnings to the [[https://www.openbsdfoundation.org/][OpenBSD Fundation]].
+
+I could not resist, and a day after learning about them, I had already paid for a full year.
+
+*** Updates
+
+2023-12-12: moved info about web stack to a [[/bsd/open-bsd-web-stack][dedicated article]].
+
+[fn:mwl-mail] at least until "[[https://www.tiltedwindmillpress.com/product/ryoms-esponsor/][Run Your Own Mail Server]]" finally lands in my digital hands
+[fn:netbsd] There is a semi-widely known story about running NetBSD on a [[https://www.embeddedts.com/blog/netbsd-toaster-powered-by-the-ts-7200-arm9-sbc/][toaster]].
+It may not support a modern WiFi card, but if the device is old, you can run NetBSD on it.
+[fn:security] At least officially.
+In reality, I'm test-driving it on my laptop and have much fewer problems than with FreeBSD[fn:tphistory].
+[fn:tphistory] You may want to check my writing about this epic fight - [FreeBSD on Thinkpad X1 Extreme G2](https://michal.sapka.me/2023/freebsd-on-thinkpad-x1-extreme-g2/).
+[fn:goals]: [[https://www.openbsd.org/goals.html][OpenBSD Project Goals]]
+[fn:hackathon]: enough said that OpenBSD coined the term "Hackathon" before corporations stole it - like the internet.
+[fn:jail]: Jails are FreeBSD containerization mechanisms based solely on chroot(8). Ever since I learned how simple it can be, I started vocalizing my disgust for Docker.
+[fn:ipv6]: [[https://michal.sapka.me/2023/fixing-ipv6-and-securing-the-domain/][Fixing IPv6 and securing the domain]]
+[fn:hier]: vide hier(7)of [[https://man.openbsd.org/hier][OpenBSD]] and of [[https://man.freebsd.org/cgi/man.cgi?hier(7)][FreeBSD]]
+[fn:aws]: notice the lack of Amazon Web Services.
+Screw them.
+They have almost all of the interwebs in their server farm, but they will not have this blog!
* FreeBSD :@bsd:
+** DONE FreeBSD: examples of Jail usage
+CLOSED: [2023-12- Mon 21:29]
+:PROPERTIES:
+:EXPORT_FILE_NAME: jails-usage-examples
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract How can we use FreeBSD Jails?
+:EXPORT_HUGO_MENU: :menu bsd-freebsd :name "Some examples of using Jails"
+:END:
+Creating Jails in FreeBSD is very easy.
+It takes few minutes to follow the [[https://docs.freebsd.org/en/books/handbook/jails/][official handbook]] and voilà!
+We've a dedicated container.
+But what can we do with it?
+
+A very common use pattern on FreeBSD desktop is to use Jails to encapsulate dependencies, so they don't pollute the main OS.
+Don't want that pesky Pyton? Straight to Jail.
+Java? Straight to jail!
+
+
+*** Simple jail - Ltex-Ls
+
+I am not a native speaker, so my English skills are far from perfect.
+My terrible typing skills don't add anything good into the mix.
+Therefore, I am in need of a good grammar and spell checker.
+There is Grammarly, but it's closed source and cloud based.
+We don't want that.
+
+Luckily an alternative exist - [[https://languagetool.org/][LanguageTool]].
+It is quite good and can run locally!
+I use it via an LSP - [[https://valentjn.github.io/ltex/ltex-ls/installation.html][Ltex-Ls]].
+Technically it's aimed at Latex, but it can work with any filetype.
+
+The problem with ltex-ls is that is runs on JVM.
+I really don't need that on my system.
+Let's lock it in a jail and allow our NeoVim[^lsp] to use it.
+[^lsp]: I can, of course, run in any other editor which supports the LSP standard, be it Emacs or some bad one.
+
+First, let's create a Jail and call it `ltex`.
+For now we can allow it access to the internet, as we will download some files.
+
+#+begin_src shell
+ltex {
+ ip4 = inherit;
+ interface = em0;
+}
+#+end_src
+
+We will remove network access after we are done with the setup.
+We don't want any of our writings to leak to the web.
+
+Then, let's log into the jail
+
+#+begin_src shell
+doas jexec ltex /bin/sh
+#+end_src
+
+and add the dreaded java
+
+#+begin_src shell
+pkg install openjdk-jre
+#+end_src
+
+then, let's fetch our latex-ls
+
+#+begin_src shell
+cd /root
+wget https://github.com/valentjn/ltex-ls/releases/download/16.0.0/ltex-ls-16.0.0.tar.gz
+tar -xvf ltex-ls-16.0.0.tar.gz
+#+end_src
+
+for ease of use, let's remove the version number from the directory
+
+#+begin_src shell
+mv ltex-ls-16.0.0/ ltex
+#+end_src
+
+And our jail is ready, so let's leave it (either `exit` or the good, old Ctrl+d).
+We can now open our nvim config file.
+This is not a guide about this part, so let's just assume you have LSP and LSP-Config intalled.
+
+Our config will look like this:
+
+#+begin_src lua
+ lspconfig.ltex.setup{
+ on_attach = on_attach,
+ cmd = { "doas",
+ "jexec",
+ "ltex",
+ "/root/ltex/bin/ltex-ls" },
+ -- rest of config omitted
+ }
+#+end_src
+
+Notice, that we now run the command as root inside the Jail.
+It would make sense to allow passwordless-doas to our user due to `doas`.
+I will update this guide if I figure out if we can commit this security nightmare here.
+
+But let's go a step further.
+Ltex-Ls allows to use machine learning based grammar check based on ngram data.
+We can add it to our jail.
+Let's log back in
+
+#+begin_src shell
+doas jexec ltex /bin/sh
+#+end_src
+
+Next we need to fetch the ngram data (you can find it on [[https://dev.languagetool.org/finding-errors-using-n-gram-data.html][LanguageTool website]].
+We need to have a `ngrams` folder which contains `en` (as the language shortcut).
+The ngrams should be inside the `en`.
+
+I propose you move the files to `/var/ngrams/en` inside the Jail.
+
+We can now tell `NeoVim` to inform the `ltex-ls` runtime to use the ngrams.
+
+#+begin_src lua
+-- our old config
+lspconfig.ltex.setup{
+ on_attach = on_attach,
+ cmd = { "doas",
+ "jexec",
+ "ltex",
+ "/root/ltex/bin/ltex-ls" },
+ -- ngram settings added
+ settings = {
+ ltex = {
+ additionalRules = {
+ languageModel = '/var/ngrams/',
+ },
+ },
+ },
+ -- rest of config still omitted
+#+end_src
+
+Note that we instructed the LSP to use =/var/ngrams= folder.
+For program running inside a Jail, the Jail is full system.
+Even though we can access the ngram data on the host OS under =/jail/containers/ltex/var/ngrams= (depending on your config), for Jail, the =/jail/containers/ltex/= prefix doesn't exist as it points to root for the jail.
+
+We can now remove networking from the jail, so our Jail config just defines the existence of the jail
+
+#+begin_src shell
+ltex {
+}
+#+end_src
+
+And boom. We've got machine language grammar checking which is completely offline and does not pollute our primary system.
+Our tinfoil friends will be proud of us.
+
+[this article will be expanded with more examples in the near future]
* Thinkpad :@bsd:
+:PROPERTIES:
+:EXPORT_HUGO_SECTION: bsd/thinkpad
+:END:
+** DONE FreeBSD: Fixing ThinkPad X1 Wifi
+CLOSED: [2023-08-03 Mon 21:40]
+:PROPERTIES:
+:EXPORT_FILE_NAME: fixing-thinkpad-x1-wifi-on-freebsd
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract replacing a wificard fixes everything
+:EXPORT_HUGO_MENU: :menu bsd-thinkpad :name "Fixing WiFi for good"
+:EXPORT_HUGO_PAIRED_SHORTCODES: img-c
+:END:
+As much as I like FreeBSD, my laptop has mostly sat dormant for the last few weeks.
+It rocked an AX200, an excellent WiFi adapter unless you want to use it in FreeBSD.
+There were three reasons for this, with one primary cause:
+1. WiFi speeds up to WiFi 2,
+2. inability of the system to resume after suspend
+3. occasional kernel panics
+
+Long story short[fn:wifiart], the firmware is yet to be properly reverse-engineered, and the card is still unsupported[fn:lies].
+The team can't simply copy the Linux driver due to BSD/GPL license incompabilities[fn:openbsd], so the work needs to continue.
+
+Luckily, ThinkPads are still good laptops, and the card was not soldered.
+So, there was a way: buy a better-supported card and just replace it.
+
+Unfortunately, Lenovo is not a good company.
+You can't simply buy any random card matching the port and be sure it will work.
+The BIOS has a whitelist of supported hardware, and if it detects anything outside of this list, the machine won't boot.
+
+Lenovo's support proved itself useless.
+I tried to contact them and get the list of whitelisted WiFi adapters, but at first, they had no idea what am I talking about, and when we finally got on the same page, they started to ignore me.
+After a few nags met with silence, I just gave up and ordered a used [[https://www.intel.com/content/www/us/en/products/sku/99445/intel-wirelessac-9260/specifications.html][Intel AC 9260]].
+
+Have I mentioned that ThinkPads are still good devices? Replacing the WiFi adapter was sparkly[fn:spark] but easy.
+Just pop the two antenna connectors, unscrew a single screw, remove the card, and do the same in reverse for the new one. Try to do that with a MacBook![fn:battery]
+
+#+attr_shortcode: "intel-ac9260.jpg"
+#+begin_img-c
+Sitting and working nicely
+#+end_img-c
+Then, with a single reinstall[^reinstall] of the system, everything started working.
+I'm still limited to WiFi 2, but it works over 5GHz.
+It's a small problem because my system can finally suspend and resume.
+I no longer need to power off/power on all the time because it's no longer necessary.
+I no longer need to be annoyed by the booting speed[fn:systemd] because it will no longer be a constant sight for me.
+I also have a (not backed by any analysis) feeling that the laptop runs colder.
+
+With this, I am now a two BSD[fn:golang] guy: [[/2023/moved-to-openbsd][OpenBSD]] on the server and FreeBSD on the computer.
+Why not go fully into one?
+Mostly, BSDs are cool, and it's nice to get to know each other.
+But also each of them has its strengths and weaknesses.
+OpenBSD is secure, has httpd/relayd and modern PF[fn:pf] but a smaller number of ported software, no ZFS, and finding answers on the information highway is more difficult.
+For a server, those are non-issues, as I have no intention of installing random crap there.
+But for my computer, I want to experiment more.
+I will break the system so ZFS will be a great addition. And having more applications ready to =pkg install= will make it this much nicer.
+
+[fn:spark] don't be a moron like me and disable the internal battery in BIOS before randomly poking the motherboard with a metal screwdriver.
+[fn:battery] or with battery. I'm replacing mine in a few days. If I went with Apple, I would need to go to a service station as my ungluing skills are nonexistent.
+[fn:wifiart] Vide [FreeBSD on modern Intel WiFi cards and resume](/2023/freebsd-on-modern-intel-wifi-cards-and-resume/)
+[fn:lies] technically [it is](https://wiki.freebsd.org/WiFi/Iwlwifi), but no real use case is feasable.
+[fn:openbsd] The OpenBSD team had no such problems, and the drivers are downloaded during installation and work out of the box.
+[fn:reinstall] I'm a simple bare metal guy and was toying with OpenBSD. I don't know if a reinstall would be required if I had a working FreeBSD.
+[fn:systemd] Which is one of the few good things about [systemd](https://michal.sapka.me/2023/systemd-is-fast/)
+[fn:golang] I could have learned to Go, but I chose a totally unmarketable skill for a programmer. I think it makes it even cooler.
+[fn:pf] I am currently reading /[[https://nostarch.com/pf3][[The Book of PF]]/ so I can have any benefit. Great book. Would recommend.
+** DONE FreeBSD: Review of Thinkpad Extreme G2
+CLOSED: [2023-02-25 Mon 22:30]
+:PROPERTIES:
+:EXPORT_FILE_NAME: freebsd-on-thinkpad-x1-extreme-g2
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract it works, but there are drawbacks
+:EXPORT_HUGO_MENU: :menu bsd-thinkpad :name "Review"
+:EXPORT_HUGO_PAIRED_SHORTCODES: img-c img-r
+:END:
+My wife got a new computer, so I can easily break my laptop whenever I want - so it's time for FreeBSD!
+
+*All this applies to FreeBSD 13.1 at the time of publishing.
+I'll add links to any additions and errata in the future*
+
+*** Installation
+
+The installation process is great.
+It's more involved than something like Fedora, and some concepts were foreign to me.
+[[https://docs.freebsd.org/en/books/handbook/bsdinstall/][Handbook's chapter on installation]] guided me through every step, so there were no problems.
+Within 15 mins of booting from the USB Drive,
+I had a working hardened system running on an encrypted ZFS drive with wireless networking and essential services configured.
+
+#+attr_shortcode: "freebsd-setup-fs.png" "https://docs.freebsd.org/en/books/handbook/bsdinstall/"
+#+begin_img-c
+Partitioning
+#+end_img-c
+
+Many things worked out of the box, but not all of them.
+
+*** Hardware
+
+Setting X-Org was a breeze.
+Nvidia drivers are [[https://docs.freebsd.org/en/books/handbook/x11/#x-configuration-nvidia][available and ready to go]] no additional configuration is necessary.
+(update: I was wrong, but it is fixed now)
+
+Sound, of all things, work out of the box.
+Unfortunately, it doesn't auto-switch to headphone output, but there is [[https://freebsdfoundation.org/freebsd-project/resourcesold/audio-on-freebsd/][a known way to do this]] via device hints.
+
+The integrated camera also works after running =webcamd -d ugen0.2 -i 0 -v 0=. Tested via =pwcview=.
+
+My laptop uses AX200 wireless card, which is [[https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=244261][not yet fully supported by the system]].
+It is recognized and works, but only up to WiFi 3 (g).
+I'd be ok with WiFi 4(n), but the driver is not ready, and WiFi 5 (AC) [[https://wiki.freebsd.org/WiFi/80211ac][is not supported by the OS]] at all.
+Funny enough, it [[https://man.openbsd.org/man4/iwx.4][seems to be supported by OpenBD]].
+I have yet to learn how different BSDs intertwine and different.
+FreeBSD is supposed to be more user-friendly, but it seems not to be the case here.
+Work on [[https://wiki.freebsd.org/WiFi/Iwlwifi][fully supporting]] the card is already planned, but I have no idea when I can expect results.
+From what I've learned, the team can't reuse code from Linux due to licensing incompatibilities between [[https://www.gnu.org/licenses/gpl-3.0.html][GPL]] and [[https://docs.freebsd.org/en/articles/license-guide/][BSD license]] [update: there are more problems].
+
+#+attr_shortcode: "freebsd-beastie.png"
+#+begin_img-r
+FreeBSD Beastie
+#+end_img-r
+This is one of the few instances when I am rethinking my life choices, and I would love to be able to help with C code.
+Also, Bluetooth on this card is not supported, and there is no work done to address it - but luckily, I am already de-wirelessing my life.
+
+USB devices are detected automatically and mostly work.
+However, my monitor (Dell P2723QE) has an integrated 1000Base-T ethernet connection, but on FreeBSD, only 100Base-T worked.
+
+Another problem is Suspend/Resume.
+I can easily [[https://wiki.freebsd.org/SuspendResume][suspend]] the device, but after resuming it, the screen is still black.
+This seems to be a known problem across different OSes for this laptop and has some [[https://www.thinkwiki.org/wiki/Problem_with_display_remaining_black_after_resume#Solution_for_ThinkPads_with_Intel_Extreme_Graphics_2][known warkarounds]] for Linux, but I have no idea how to apply them to BSD. [update: there is a fix working]
+
+The biggest problem here is battery drain. I have =power= enabled, but =acpinfo= reports about over 1% per minute.
+I was getting about the same drain on Arch Linux, but Manajaro acted much better.
+
+I have not tested the fingerprint reader as I've never used it.
+
+**** Conclusion
+
+My ThinkPad is far from being a brick under FreeBSD.
+It is, however, severely hindered.
+I plan to fix the memory drain and allow for a resume after suspension.
+This will make it a proper laptop again, as there are always USB dongles when faster WiFi is needed.
+Dongle town, however, is not what I want in the long term, and I'll need to follow the progress of the driver implementation closely.
+
+It seems that for a desktop computer everything would work.
+
+I'm falling in love with the system and its simplicity and logic.
+So even if I fail at fixing the above, I'll try to stick with it.
+And even if I get fed up with the state of hardware support, I'll keep FreeBSD as a secondary system.
+
+For personal servers, however, I see no way of abandoning BSD.
+
+*** Updates
+
+- 2023-02-27: [[/2023/fixing-resume-on-thinkpad-x1-extreme-g2-on-freebsd][Fixing resume due to graphic drivers]]
+- 2023-02-04: [[/2023/freebsd-configuring-nvidia-and-xorg-on-thinkpad-x1-extreme-g2][Configuring NVIDIA]].
+- 2023-03-15: [[/2023/freebsd-on-modern-intel-wifi-cards-and-resume][Problems with WiFi after resume]]
+
+** DONE FreeBSD: Switching Between Speakers and Headphones
+CLOSED: [2023-03-16 Mon 23:02]
+:PROPERTIES:
+:EXPORT_FILE_NAME: switching-between-speakers-and-headphones-on-freebsd
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract How to change the audio sevices?
+:EXPORT_HUGO_MENU: :menu bsd-thinkpad :name "Switching beteen headphnes and speakers"
+:END:
+I want my laptop to switch to wired headphones when I attach them.
+FreeBSD has its own [[https://wiki.freebsd.org/Sound][Sound System]], so it's a great learning experience.
+I have yet to automate it (it is possible, but an attempt to do so forced me to do a complete rollback of the system state), but for now, this is working.
+
+First, check which audio outputs your device supports:
+
+#+begin_src shell
+$ cat /dev/sndstat
+#+end_src
+
+In the case of my ThinkPad, this returns
+
+#+begin_src shell
+Installed devices:
+pcm0: <NVIDIA (0x0094) (HDMI/DP 8ch)> (play)
+pcm1: <NVIDIA (0x0094) (HDMI/DP 8ch)> (play)
+pcm2: <NVIDIA (0x0094) (HDMI/DP 8ch)> (play)
+pcm3: <Conexant (0x1f86) (Analog)> (play/rec) default
+pcm4: <Conexant (0x1f86) (Left Analog Headphones)> (play)
+No devices installed from userspace.
+#+end_src
+
+The ones I care about are:
+pcm3 - the speakers
+pcm4 - the headphone jack
+
+I can now easily switch between them:
+
+#+begin_src shell
+# enable speakers
+$ sysctl hw.snd.default_unit=3
+# enable headphones
+$ sysctl hw.snd.default_unit=4
+#+end_src
+
+(replace the value with the correct id from `sndstat` file.)
+
+This, however, comes with a huge caveat.
+Some apps (khem khem, Firefox) not native to FreeBSD come configured with PulseAudio instead of FreeBSD's Sound System.
+This creates a level of indirection, and changing system output may not work instantly.
+In the case of Firefox, I need to reload the tab.
+Some apps, as I've heard, require a restart.
+** DONE FreeBSD: Fixing Resume on ThinkPad X1 Extreme G2 due to integrated graphic card
+CLOSED: [2023-03-16 Mon 23:02]
+:PROPERTIES:
+:EXPORT_FILE_NAME: fixing-resume-on-thinkpad-x1-extreme-g2-on-freebsd
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract you need to load the driver
+:EXPORT_HUGO_MENU: :menu bsd-thinkpad :name "Fixing resume due to Intel driver"
+:END:
+*This applies to FreeBSD 13.1*
+
+Recently I [[/2023/freebsd-on-thinkpad-x1-extreme-g2][posted]] about my problems with FreeBSD.
+One of them was resume.
+After installing FreeBSD, I was able to put my laptop to sleep via
+
+#+begin_src shell
+acpiconf -s 3
+#+end_src
+
+And this worked fine.
+However, I was not able to resume it back from sleep.
+After pressing the power button laptop woke, but the screen was still black.
+I could =reboot=, and it would work, so only the screen was the problem.
+
+After asking about this on [[https://forums.freebsd.org/threads/resume-on-thinkpad-x1-extreme-g2-ends-in-black-screen.88162/][FreeBSD Forums]], [[https://forums.freebsd.org/members/bsduck.61635/][bsdduck]] and [[https://forums.freebsd.org/members/smithi.71028/][smithi]] pointed me to dedicated drivers for the integrated Intel GPU.
+And it worked like a charm.
+
+All I had to do was:
+
+#+begin_src shell
+pkg install drm-kmod
+sysrc -f /etc/rc.conf kld_list+=i915kms
+reboot
+#+end_src
+(via [[https://wiki.freebsd.org/Graphics#Intel_Integrated_Graphics_.28aka_HD_Graphics.29][FreeBSD Wiki]]).
+
+Now the computer can sleep and resume without any problems. At least when using [[https://man.freebsd.org/cgi/man.cgi?acpiconf(8)][sleep mode 3]].
+The 4th doesn't work for me at all.
+
+** DONE FreeBSD: configuring Nvidia and Xorg
+CLOSED: [2023-03-16 Mon 23:02]
+:PROPERTIES:
+:EXPORT_FILE_NAME: freebsd-configuring-nvidia-and-xorg-on-thinkpad-x1-extreme-g2
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract A tutorial on making Nvidia work
+:EXPORT_HUGO_MENU: :menu bsd-thinkpad :name "Setting up Nvidia"
+:END:
+First, the bad news: I could not make FreeBSD work with Hybrid Graphics, so I use only the discrete one.
+To ensure this, open BIOS and:
+1. Configuration
+2. Display
+3. Graphics Device
+4. select `Discrete Graphics`
+
+Then, log in as root and install the drivers:
+
+#+begin_src shell
+ pkg install nvidia-driver nvidia-xconfig
+#+end_src
+
+The next step is to enable the drivers.
+
+#+begin_src shell
+sysrc kld_list+=nvidia
+sysrc kld_list+=nvidia-modeset
+#+end_src
+
+Some people advise adding Linux (=sysrc kld_list+=linux=) to kld_list, but I got my GPU working without that.
+
+After that, either load the drivers manually or give the computer an old, good reboot.
+
+Login as root again and use the NVIDIA configurator to get Xorg configured.
+
+#+begin_src shell
+nvidia-xconfig
+#+end_src
+
+Then try starting your desktop environment, windows manager, or startx.
+You may be done, but I got an error about =Screen not found=.
+Tell Xorg where the NVIDIA GPU is if you have the same problem.
+Try probing the system for GPUs
+
+#+begin_src shell
+pciconf -l | grep vga
+#+end_src
+
+You will see one on more elements on the list. The critical part is in the first column, for example:
+
+#+begin_src shell
+vgapci0@pci0:1:0:0
+#+end_src
+
+Our GPU is available under BUS 1:0:0 (we skip the first 0). You may need to try different elements from the list.
+
+#+begin_quote
+For PCI/AGP cards, the bus−id string has the form PCI:bus:device:function (e.g., “PCI:1:0:0” might be appropriate for an AGP card).
+
+[[https://www.x.org/releases/X11R7.7/doc/man/man5/xorg.conf.5.xhtml#heading10X][Xorg documentation]]
+#+end_quote
+
+
+Open =/etc/X11/xorg.conf=, look for =Section "Device"= and add:
+
+#+begin_src shell
+BusID "PCI:1:0:0"
+#+end_src
+
+In my case, everything worked fine after that.
+
+Notes:
+
+I learned the BUS trick from [[https://nudesystems.com/how-to-fix-no-screen-found-xorg-error-on-freebsd/][Nude Systems]].
+
* Unix history :@bsd:
+:PROPERTIES:
+:EXPORT_HUGO_SECTION: bsd/history
+:END:
+* Varia :@bsd:
+** DONE FreeBSD: Early thoughts
+CLOSED: [2023-02-15 Mon 21:12]
+:PROPERTIES:
+:EXPORT_FILE_NAME: early-freebsd-thoughts
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract I've been using FreeBSD on my server for the last few weeks and I like it!
+:EXPORT_HUGO_MENU: :menu bsd-varia :name "FreeBSD: early thoughts"
+:EXPORT_HUGO_PAIRED_SHORTCODES: img-r img-c
+:END:
+I'm leaning more and more towards joining the [[https://www.freebsd.org/][FreeBSD]] crowd.
+
+The community is small and welcoming, and I'm driven towards more minor groups.
+But I was surprised to find out hoh welcoming it was.
+People seem to be actually happy to help a noob - something the Linux crowd forgot how to do.
+
+#+attr_shortcode: "freebsd-beastie.png"
+#+begin_img-r
+FreeBSD Beastie
+#+end_img-r
+Another aspect is the documentation.
+People say it's excellent, and I consider it to be selling short.
+I'm reading [[https://docs.freebsd.org/en/books/handbook/][The Official Handbook]]
+It starts with the assumption that the reader has close to 0 knowledge but never treats him as a moron.
+And chapter by chapter explains how and why things work this way.
+It may not be for everyone, as you are expected to want to learn - but it is invaluable if you are in the target group.
+It's worth reading even if you don't want to move to BSD, as a lot applies to other NIXs, like Linux.
+
+And, of course, the system itself.
+I've been using unix-inspired OSs exclusively for over a decade (and quite often before that).
+FreeBSD is so close, that from day 0, I am able to navigate it.
+And what I see is a very well-thought system without many pitfalls Linux fell into.
+Just two examples that strike me the most.
+
+In Linux, the root partition is a mess.
+System and userland are intertwined, and I wonder if anyone understands where things should go.
+Just look at how many explanations of the structure there are!
+Should this particular config be in /var/ or maybe in /etc/?
+AFAIK there are no generic guidelines, just tribal knowledge.
+If FreeBSD, there's a [[https://docs.freebsd.org/en/books/handbook/basics/#dirstructure][dedicated chapter]] in the documentation!
+There's also a strict rule where userland should live - in /usr.
+Everything you install goes to /usr - the executables, the configs, etc.
+Finally, a new user can experiment without fearing breaking the system!
+
+The other one is the `rc` subsystem.
+The Linux world has a neverending war between Systemd and, well, everything else.
+Here?
+The system itself dictates how to manage the cattle - elegantly and logically.
+
+#+attr_shortcode: "freebsd13-bootloader.png"
+#+begin_img-c
+How the OS greats us.
+#+end_img-c
+
+FreeBSD comes with two package managers: pkg and ports.
+Pkg is a standard replacement for brew/apt/pacman or whatever else is there.
+What is nice is that the user can configure to use packages updated quarterly or the latest.
+Want to have a stable infrastructure?
+Go with quarterly - bug fixes will be included in between updates.
+Want modern thingies? Go with the latest.
+My biggest issue with Ubuntu and its derivatives is how far behind the packages in apt are, as they are tied to the yearly distro update circle.
+You can mitigate this by using personal repositories, but those are a nuance to set up.
+FreeBSD comes prepared for servers and workstations at the same time.
+
+And then there are ports for the demanding crowd.
+Since BSD is semi-compatible with Linux, you can compile most of its software.
+But there are some differences, so it requires some manual configuration or looking for dependencies.
+Or rather, it would, as FreeBSD has you covered.
+Ports is a single repository with makefiles for different projects tailored for the system.
+You can either compile anything with default settings or adjust the parameters easily.
+Want Firefox without JS support? Why not! I have yet to use ports, as they seem excessive for my humble VPS, but I love the idea.
+
+So, you have the best features from Ubuntu (stable versions), Arch (cutting edge), and from Gentoo (compile from source code) right at your disposal.
+
+I am **this** close to installing FreeBSD on my personal computer. My work-issued Macbook is [[https://en.wikipedia.org/wiki/Darwin_(operating_system)#Kernel][already running a BSD derivative]]... for better or worse.
+
+** DONE FreeBSD on the Desktop won't improvide unless people are using it
+CLOSED: [2023-03-29 Mon 22:09]
+:PROPERTIES:
+:EXPORT_FILE_NAME: desktop-freebsd-wont-improve-unless-people-are-using-it
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER: abstract I have hits from /r/bsd, but almost none of those people are using BSD
+:EXPORT_HUGO_MENU: :menu bsd-varia :name "Desktop FreeBSD won't improve unless people are using it"
+:EXPORT_HUGO_PAIRED_SHORTCODES: img-r img-c
+:END:
+Shamelessly, I posted my previous post, [[https://d-s.sh/2023/freebsd-on-thinkpad-x1-extreme-g2/][FreeBSD on a Thinkpad Extreme G2]] on [[https://www.reddit.com/r/BSD/comments/124v5cm/freebsd_on_a_thinkpad_x1_extreme_g2/][/r/bsd Reddit]].
+
+The result, some 24 hours later, is 100 visitors.
+Out of that 100, 57 are using a desktop.
+Out of that 57, only 2 used FreeBSD—2%. No other BSDs are recorded.
+
+People who are into BSD don't use BSD.
+This seems to be a reason for lacking hardware support.
+If no one uses FreeBSD, no one will encounter those problems. If no one encounters them, no one will fix them.
+
+*** Update 2023-04-14
+
+The article, got quite the round around the internets, gathering some interests from [[https://old.reddit.com/r/freebsd/comments/126fvkz/desktop_freebsd_wont_improve_unless_people_are/][Reddit]], [Hacker News](https://news.ycombinator.com/item?id=35378367), Twitter, Discover BSD, or [[https://vermaden.wordpress.com/2023/04/03/valuable-news-2023-04-03/][Vermaden]].
+With all that interest come quite a few questions and comments.
+The following is an attempt to summarize it all.
+
+**** People who use FreeBSD don't care about FreeBSD hardware
+
+This makes perfect sense.
+If your FreeBSD installation on X220 works flawlessly, you may not care about anything more modern.
+But there will come a time when you will need to replace the hardware.
+
+#+attr_shortcode: "freebsd-beastie.png"
+#+begin_img-r
+FreeBSD Beastie
+#+end_img-r
+This comment, however, came as a proof that the sample from my blog is invalid.
+This may be the case, but I don't buy it.
+All traffic on the aforementioned post came from Reddit's BSD forum.
+It's the one place where you could expect that people using BSD would hang.
+It may also be that it's quite a random sample - it's small, and people who have yet to become into BSD but are BSD-curious opened my blog post.
+I am in no place to debunk or confirm this.
+I, however, know that many people presenting at FreeBSD conferences do it using Macs or Windows.
+So even if the numbers are dubious, the overall feeling remains sorrowful.
+
+To add to the above: there are also stats for the commented opinion piece.
+Two hundred forty-four people opened it from /r/freebsd.
+Of that, 24 people were using FreeBSD, and just 2 were using OpenBSD.
+
+**** Your statistics may be invalid as people mask their browser agent.
+
+This also may be the case.
+Why, then, is the referer not spoofed?
+It's a much more invasive data point than the underlying OS.
+But I'm a simple Firefox user, never used Librewolf.
+
+**** FreeBSD is a server OS
+
+Yeah, this is the sentiment I've read before jumping aboard.
+My problem with this idea is that each and every FOSS OS is a value in itself.
+The current poster boy,
+Linux, also had huge problems getting to work on various machines.
+In my opinion, it's limiting OS to a single use case is a completely valid point - your use case for FreeBSD is on a server, and this is where it currently shines (or not, depending on your experience).
+Some folks despise allocating any FreeBSD dev time to the desktop as there are many server issues.
+
+But again, I don't see it this way.
+Limiting FreeBSD to the server only is short-lighted.
+Unless you are already powering your servers with BSD, there will always be a question: "Why not Linux. It's what everyone else is doing".
+And Linux got into its current position not by being a great server machine but rather by attracting the interest of some very skillful people.
+And it did it by allowing more and more people to free themselves from Windows on their machines.
+
+I see FreeBSD problems as having two primary causes: the [[https://en.wikipedia.org/wiki/Unix_wars][Unix wars]] of the past and limited resources now.
+If FreeBSD were easier to use on a wide range of end-user machines (which tend to be laptops), the easier it would for people to want to develop it.
+BSDs are now a far second choice.
+Why would someone invest time?
+They may fall in love with the OS, but unless they try it, it will never happen.
+
+**** I like our small userbase
+
+I'm as elitist as the other person. [[https://dwm.suckless.org/][DWM]] stated that
+
+#+begin_quote
+"This keeps its userbase small and elitist.
+No novices asking stupid questions.
+#+end_quote
+
+I can't find this quote anymore, but the sentiment seems similar.
+However, there are two aspects here.
+
+FreeBSD comes with no graphical interface by default.
+This makes it much closer to minimalist distros than Ubuntu.
+This still allows anyone to feel like a hacker.
+
+The second, however, is that some problems are unsolvable by end-user.
+Writing drivers is EXTREMELY difficult, and, as I've recently learned (thanks, Jeff!), this is especially true when it comes to WiFi drivers, as there is no open implementation.
+This means that any progress requires a trial-and-error process based on reverse engineering.
+No one without deep knowledge of low-level programming will be able to make any progress, and even those few will need people with real hardware for testing.
+
+**** Hardware support is years behind Linux
+
+Yes, and this is what I was referring to.
+
+**** Why would anyone use BSD on a desktop?
+
+It's a great system, just needs a lot of work on hardware support :-)
+
+**** Your post is worthless, and only the comments are interesting
+
+It's more than I anticipated. That post was small and written without any deeper research. But the discussion around it makes me believe that I hit something real.
+
* WIP
** TODO XMPP (Jabber) server on OpenBSD
/intro/