<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts on Artur Meski</title>
    <link>https://meski.io/posts/</link>
    <description>Recent content in Posts on Artur Meski</description>
    <generator>Hugo</generator>
    <language>en-gb</language>
    <lastBuildDate>Fri, 09 Sep 2022 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://meski.io/posts/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Limiting resources on FreeBSD</title>
      <link>https://meski.io/posts/rctl/</link>
      <pubDate>Fri, 09 Sep 2022 00:00:00 +0000</pubDate>
      <guid>https://meski.io/posts/rctl/</guid>
      <description>&lt;h1 id=&#34;what-is-rctl&#34;&gt;What is &lt;code&gt;rctl&lt;/code&gt;&lt;/h1&gt;&#xA;&lt;p&gt;In FreeBSD, in addition to &lt;code&gt;login.conf&lt;/code&gt;, we also get a very nice and&#xA;flexible mechanism for setting resource limits: &lt;code&gt;rctl&lt;/code&gt;.&#xA;I like it in particular for limiting resources allocated to each jail.&lt;/p&gt;&#xA;&lt;h1 id=&#34;configuration&#34;&gt;Configuration&lt;/h1&gt;&#xA;&lt;p&gt;Here is a short example:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;jail:example_jail:vmemoryuse:deny=2G/jail&#xA;jail:example_jail:maxproc:deny=200/jail&#xA;jail:example_jail:readiops:throttle=500/jail&#xA;jail:example_jail:pcpu:deny=70/jail&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the above, for the jail identified by &lt;code&gt;example_jail&lt;/code&gt; we allow:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;2G of memory,&lt;/li&gt;&#xA;&lt;li&gt;200 processes,&lt;/li&gt;&#xA;&lt;li&gt;500 I/O read operations per second,&lt;/li&gt;&#xA;&lt;li&gt;70% of CPU.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h1 id=&#34;enabling-rctl-on-boot&#34;&gt;Enabling rctl on boot&lt;/h1&gt;&#xA;&lt;p&gt;Actually, there is no need to enable anything in &lt;code&gt;rc.conf&lt;/code&gt; &amp;ndash;&#xA;this is what you can find in &lt;code&gt;/etc/defaults/rc.conf&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Public VMs on OpenBSD</title>
      <link>https://meski.io/posts/public-vms-openbsd/</link>
      <pubDate>Wed, 28 Jul 2021 00:00:00 +0000</pubDate>
      <guid>https://meski.io/posts/public-vms-openbsd/</guid>
      <description>&lt;p&gt;This is a note on how to make a VM running on OpenBSD connect to the host&amp;rsquo;s network.&lt;/p&gt;&#xA;&lt;p&gt;Firstly, we need to create a bridge with our external network interface.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# echo &amp;#34;em0&amp;#34; &amp;gt; /etc/hostname.bridge0&#xA;# /etc/netstart bridge0&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In &lt;code&gt;/etc/vm.conf&lt;/code&gt; we need to add a switch on &lt;code&gt;bridge0&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;switch &amp;#34;sw&amp;#34; {&#xA;    interface bridge0&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then, our VM needs to be attached to that switch:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;vm &amp;#34;openbsd&amp;#34; {&#xA;    memory 8G&#xA;    enable&#xA;    disk /data/vm/openbsd/main.qcow2&#xA;    interface tap {&#xA;&#x9;switch &amp;#34;sw&amp;#34;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;My network setup also requires to specify the MAC address of the network interface:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Basic concurrency with fork()</title>
      <link>https://meski.io/posts/concurrency-unix-fork/</link>
      <pubDate>Wed, 23 Jun 2021 00:00:00 +0000</pubDate>
      <guid>https://meski.io/posts/concurrency-unix-fork/</guid>
      <description>&lt;p&gt;When programming on Linux/Unix, the function &lt;a href=&#34;https://man.openbsd.org/fork&#34; target=&#34;_blank&#34;&gt;fork(2)&lt;/a&gt; allows us to create new processes.&#xA;This is a short and example-driven introduction to the basics of using that function.&lt;/p&gt;&#xA;&lt;h1 id=&#34;first-stab&#34;&gt;First stab&lt;/h1&gt;&#xA;&lt;p&gt;After a brief look at the manual page for &lt;a href=&#34;https://man.openbsd.org/fork&#34; target=&#34;_blank&#34;&gt;fork(2)&lt;/a&gt; we can tell that it returns a value of type &lt;em&gt;pid_t&lt;/em&gt; and does not take any arguments:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;NAME&#xA;     fork – create a new process&#xA;&#xA;SYNOPSIS&#xA;     #include &amp;lt;unistd.h&amp;gt;&#xA;&#xA;     pid_t&#xA;     fork(void);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let us simply call &lt;em&gt;fork&lt;/em&gt; and see what happens and what values does it return.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Quick start: virtual machines on OpenBSD</title>
      <link>https://meski.io/posts/vms-on-openbsd/</link>
      <pubDate>Sat, 19 Jun 2021 00:00:00 +0000</pubDate>
      <guid>https://meski.io/posts/vms-on-openbsd/</guid>
      <description>&lt;p&gt;Since &lt;a href=&#34;http://www.openbsd.org/&#34; target=&#34;_blank&#34;&gt;OpenBSD&lt;/a&gt; 5.9 it is possible to run virtual machines using a native virtualisation solution.&lt;/p&gt;&#xA;&lt;p&gt;This is a short note/guide on how to set up a VM on &lt;a href=&#34;http://www.openbsd.org/&#34; target=&#34;_blank&#34;&gt;OpenBSD&lt;/a&gt; in the simplest way that lets you have a quick play with vmm/vmd.&lt;/p&gt;&#xA;&lt;h1 id=&#34;preliminaries&#34;&gt;Preliminaries&lt;/h1&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;First of all, we need to enable &lt;em&gt;vmd&lt;/em&gt; on our host and get it running:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# rcctl enable vmd&#xA;# rcctl start vmd&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;You may also want to make sure you firewall can initially let everything through:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Reading and monitoring files on Linux</title>
      <link>https://meski.io/posts/reading-and-monitoring-files/</link>
      <pubDate>Sat, 19 Jun 2021 00:00:00 +0000</pubDate>
      <guid>https://meski.io/posts/reading-and-monitoring-files/</guid>
      <description>&lt;p&gt;Let&amp;rsquo;s start with something super basic. To print the contents of a file you can use &lt;code&gt;cat&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cat file&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This tool is simple but really powerful when combined (piped) with other commands.&#xA;However, &lt;code&gt;cat&lt;/code&gt; is not very practical if you just want to see the contents of a larger file.&#xA;In that case you can use &lt;code&gt;less&lt;/code&gt;, which also allows you to conveniently browse your file:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;press &lt;em&gt;space&lt;/em&gt; for &lt;em&gt;page down&lt;/em&gt; or &lt;code&gt;b&lt;/code&gt; for &lt;em&gt;page up&lt;/em&gt;,&lt;/li&gt;&#xA;&lt;li&gt;type &lt;code&gt;/pattern&lt;/code&gt; to search for &lt;code&gt;pattern&lt;/code&gt; in the file (&lt;code&gt;n&lt;/code&gt; jumps to the next occurence, while &lt;code&gt;N&lt;/code&gt; jumps to the previous one),&lt;/li&gt;&#xA;&lt;li&gt;press &lt;code&gt;q&lt;/code&gt; to quit.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;If you need to watch a certain file (typically a log file), you can simply use &lt;code&gt;tail -f&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
