<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - ubuntu</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/ubuntu</link>
<lastBuildDate>Wed, 20 May 2026 02:45:54 -0700</lastBuildDate>
<item>
<title>SNMP server not reporting disk size</title>
<link>/blog/entries/snmp-server-not-reporting-disk-size</link>
<pubDate>Thu, 29 Feb 2024 12:21:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>I was setting up snmpd on an Ubuntu box, and noticed that it was reporting weird numbers
for a couple of XFS filesystems I had setup for Minio.</p>
<p>An snmpwalk showed values like this:</p>
<pre><code>HOST-RESOURCES-MIB::hrStorageType.51 = OID: HOST-RESOURCES-TYPES::hrStorageFixedDisk
HOST-RESOURCES-MIB::hrStorageType.52 = OID: HOST-RESOURCES-TYPES::hrStorageFixedDisk
...
HOST-RESOURCES-MIB::hrStorageDescr.51 = STRING: /minio/disk1
HOST-RESOURCES-MIB::hrStorageDescr.52 = STRING: /minio/disk2
...
HOST-RESOURCES-MIB::hrStorageAllocationUnits.51 = INTEGER: 0 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.52 = INTEGER: 0 Bytes
...
HOST-RESOURCES-MIB::hrStorageSize.51 = INTEGER: 0
HOST-RESOURCES-MIB::hrStorageSize.52 = INTEGER: 0
...
HOST-RESOURCES-MIB::hrStorageUsed.51 = INTEGER: 0
HOST-RESOURCES-MIB::hrStorageUsed.52 = INTEGER: 0</code></pre>
<p>So it was reporting the existence of the disks, but with all 0 values.  The root ext4 filesystem showed up fine,
was it something to do with XFS?  </p>
<p>Turns out the answer was NO, it was the permissions of the /minio directory
that the filesystems were mounted under.  I figured this out when I noticed
that <code>df -h</code> showed the disks when I was running as root</p>
<pre><code>/dev/sdb1        60G  461M   60G   1% /minio/disk1
/dev/sdc1        60G  461M   60G   1% /minio/disk2</code></pre>
<p>But when running as non-root, such as the Debian-snmp user, <code>df -h</code> didn't show the disks at all.</p>
<p>Turns out I had been too strict with the permissions on <code>/minio</code>, I had originally set that to</p>
<pre><code>drwx------   4 minio-user root       4096 Feb 14 14:57 minio</code></pre>
<p>But that apparently, and to my surprise, prevented snmpd from being able to read the size and usage
information for the mounts under that directory.  Changing that to <code>0755</code> fixed the problem, and I just
made sure that the mountpoints had more strict permissions</p>
<pre><code>drwxr-x--- 3 minio-user root 24 Feb 27 13:08 disk1
drwxr-x--- 3 minio-user root 24 Feb 27 13:08 disk2</code></pre>]]></description>
</item>
<item>
<title>Automatically restarting Percona XtraDB cluster</title>
<link>/blog/entries/automatically-restarting-percona-xtradb-cluster</link>
<pubDate>Wed, 01 Feb 2023 10:05:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p>I've been experimenting with Percona XtraDB cluster, and found that by default it requires manual intervention
to restart the cluster from an all-nodes-down state when the nodes were gracefully shutdown.  The docs talk about
identifying which node has <code>safe_to_bootstrap: 1</code> in it's <code>/var/lib/mysql/grastate.dat</code> file, and on that node starting
the <code>mysql@boostrap</code> service instead of just plain <code>mysql</code>.</p>
<p>Looking at a file and acting on what's found seems like something that could be automated, so here's my take for an
Ubuntu 22.04 setup:</p>
<p>On each node (yay Ansible!) I added this script as <code>/usr/local/sbin/choose-mysql-service.sh</code></p>
<div class="source"><pre><span></span><span class="ch">#!/bin/bash</span>

<span class="nv">GRASTATE</span><span class="o">=</span><span class="s2">"/var/lib/mysql/grastate.dat"</span>

<span class="nv">service</span><span class="o">=</span><span class="s2">"mysql"</span>

<span class="c1"># Start a different service if grastate.dat is present</span>
<span class="c1"># with safe_to_bootstrap: 1</span>
<span class="c1">#</span>
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span>-f<span class="w"> </span><span class="nv">$GRASTATE</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span>grep<span class="w"> </span>--quiet<span class="w"> </span><span class="s2">"^safe_to_bootstrap: 1"</span><span class="w"> </span><span class="nv">$GRASTATE</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w">        </span><span class="nv">service</span><span class="o">=</span><span class="s2">"mysql@bootstrap"</span>
<span class="w">    </span><span class="k">fi</span>
<span class="k">fi</span>

<span class="nb">echo</span><span class="w"> </span><span class="s2">"Starting </span><span class="nv">$service</span><span class="s2">"</span>
systemctl<span class="w"> </span>start<span class="w"> </span><span class="nv">$service</span>
</pre></div>
<p>Then I added a one-shot systemd unit to execute at boot time, as <code>/etc/systemd/system/choose-mysql-service.service</code></p>
<div class="source"><pre><span></span><span class="k">[Unit]</span>
<span class="na">Description</span><span class="o">=</span><span class="s">Choose MySQL service</span>
<span class="na">After</span><span class="o">=</span><span class="s">network.target</span>

<span class="k">[Service]</span>
<span class="na">Type</span><span class="o">=</span><span class="s">oneshot</span>
<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/local/sbin/choose-mysql-service.sh</span>
<span class="na">RemainAfterExit</span><span class="o">=</span><span class="s">true</span>

<span class="k">[Install]</span>
<span class="na">WantedBy</span><span class="o">=</span><span class="s">multi-user.target</span>
</pre></div>
<p>And the disabled the default <code>mysql</code> service and enabled my new unit with:</p>
<pre><code>systemctl daemon-reload
systemctl disable mysql
systemctl enable choose-mysql-service</code></pre>
<p>So now when the OS boots, instead of just blindly trying to start <code>mysql</code>, it looks at the <code>grastate.dat</code> and if it has <code>safe_to_bootstrap: 1</code> it starts <code>mysql@bootstrap</code> instead - or otherwise falls back to the default of starting <code>mysql</code></p>
<p>I also shared this on the <a href="https://forums.percona.com/t/pxc-8-auto-restart-after-graceful-shutdown/19850">Percona Forum</a>, look for feedback there</p></body>]]></description>
</item>
<item>
<title>UFW and LXC/LXD on Ubuntu 22.04</title>
<link>/blog/entries/ufw-and-lxd-lxd-on-ubuntu-2204</link>
<pubDate>Thu, 26 May 2022 10:00:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>I recently setup a new Ubuntu server with LXC containers.  At first it all went great, but then
later when I enabled UFW, things got flaky.  Looking at <code>/var/log/syslog</code> I saw UFW was blocking
lots of traffic from inside the containers.  </p>
<p>Also when restarting a container, the container wouldn't get one of the bridged <code>10.x.x.x</code> IP addresses.</p>
<p>After Googling a bit, I found the magic commmands on <a href="https://discuss.linuxcontainers.org/t/lxd-bridge-doesnt-work-with-ipv4-and-ufw-with-nftables/10034/16">this discussion</a>:</p>
<pre><code>ufw allow in on lxdbr0
ufw route allow in on lxdbr0</code></pre>
<p>In hindsight, I think it would have been better to enable <code>ufw</code> <em>before</em> doing anything else with the new install,
that way the problems would have been more obvious right away - rather than it being a &quot;geez, it was working before&quot;
type situation.</p>]]></description>
</item>
<item>
<title>Decrease snmpd logging level on Ubuntu 18.04</title>
<link>/blog/entries/decrease-snmpd-logging-on-ubuntu-18-04</link>
<pubDate>Sun, 01 Mar 2020 08:45:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p>I recently updated some servers from Ubuntu 16.04 to 18.04, and found that
the <code>snmpd</code> daemon was generating way too many log entries
in <code>/var/log/syslog</code> - one for every SNMP query coming from our monitoring system.  </p>
<p>In older Ubuntus I had edited <code>/etc/defaults/snmpd</code> to change the <code>SNMPDOPTS</code> line
to have a different <code>-Ls</code> parameter, but it seems that on the new Ubuntu, the
systemd service for snmp doesn't use that <code>defaults</code> file at all.  A comment
on this <a href="https://serverfault.com/questions/310640/reduce-snmpd-logging-verbosity">serverfault question</a>
gave me a clue on how to fix it in systemd - I thought I'd elaborate here.</p>
<p>If you run </p>
<pre><code>systemctl cat snmpd.service</code></pre>
<p>You see the current service file:</p>
<div class="source"><pre><span></span><span class="c1"># /lib/systemd/system/snmpd.service</span>
<span class="k">[Unit]</span>
<span class="na">Description</span><span class="o">=</span><span class="s">Simple Network Management Protocol (SNMP) Daemon.</span>
<span class="na">After</span><span class="o">=</span><span class="s">network.target</span>
<span class="na">ConditionPathExists</span><span class="o">=</span><span class="s">/etc/snmp/snmpd.conf</span>

<span class="k">[Service]</span>
<span class="na">Environment</span><span class="o">=</span><span class="s">"MIBSDIR=/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp"</span>
<span class="na">Environment</span><span class="o">=</span><span class="s">"MIBS="</span>
<span class="na">Type</span><span class="o">=</span><span class="s">simple</span>
<span class="na">ExecStartPre</span><span class="o">=</span><span class="s">/bin/mkdir -p /var/run/agentx</span>
<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f</span>
<span class="na">ExecReload</span><span class="o">=</span><span class="s">/bin/kill -HUP $MAINPID</span>

<span class="k">[Install]</span>
<span class="na">WantedBy</span><span class="o">=</span><span class="s">multi-user.target</span>
</pre></div>
<p>I wanted to override the ExecStart line with something different.  To do that, run</p>
<pre><code>systemctl edit snmpd.service</code></pre>
<p>This brings up your default editor with a <em>blank</em> file.  I entered these new lines:</p>
<div class="source"><pre><span></span><span class="c1"># Override default "-Lsd" paramter to "-LSwd" to decrease logging level</span>
<span class="k">[Service]</span>
<span class="na">ExecStart</span><span class="o">=</span>
<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/sbin/snmpd -LSwd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f</span>
</pre></div>
<p>The first <code>ExecStart=</code> line is a bit odd, without it you get an error:</p>
<pre><code>snmpd.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.</code></pre>
<p>so the first line 'clears' the setting before processing your own version.</p>
<p>Save your file (<code>systemctl edit</code> stores it as <code>/etc/systemd/system/snmpd.service.d/override.conf</code>), and then run
<code>service snmpd restart</code> to have take effect. If you re-run <code>systemctl cat snmpd.service</code> you should now see:</p>
<div class="source"><pre><span></span><span class="c1"># /lib/systemd/system/snmpd.service</span>
<span class="k">[Unit]</span>
<span class="na">Description</span><span class="o">=</span><span class="s">Simple Network Management Protocol (SNMP) Daemon.</span>
<span class="na">After</span><span class="o">=</span><span class="s">network.target</span>
<span class="na">ConditionPathExists</span><span class="o">=</span><span class="s">/etc/snmp/snmpd.conf</span>

<span class="k">[Service]</span>
<span class="na">Environment</span><span class="o">=</span><span class="s">"MIBSDIR=/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp"</span>
<span class="na">Environment</span><span class="o">=</span><span class="s">"MIBS="</span>
<span class="na">Type</span><span class="o">=</span><span class="s">simple</span>
<span class="na">ExecStartPre</span><span class="o">=</span><span class="s">/bin/mkdir -p /var/run/agentx</span>
<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f</span>
<span class="na">ExecReload</span><span class="o">=</span><span class="s">/bin/kill -HUP $MAINPID</span>

<span class="k">[Install]</span>
<span class="na">WantedBy</span><span class="o">=</span><span class="s">multi-user.target</span>

<span class="c1"># /etc/systemd/system/snmpd.service.d/override.conf</span>
<span class="c1"># Override default "-Lsd" paramter to "-LSwd" to decrease logging level</span>
<span class="k">[Service]</span>
<span class="na">ExecStart</span><span class="o">=</span>
<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/sbin/snmpd -LSwd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f</span>
</pre></div>
<p>Which is a combination of the default service along with your override.</p>
<p>If you have other servers you want to copy your <code>/etc/systemd/system/snmpd.service.d/override.conf</code> file to, you need
to run</p>
<pre><code>systemctl daemon-reload
service snmpd restart</code></pre>
<p>to have it take effect.</p></body>]]></description>
</item>
<item>
<title>VM Serial Console part 2</title>
<link>/blog/entries/vm-serial-console-part-2</link>
<pubDate>Wed, 09 Nov 2011 08:18:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>Fooling around a bit more with accessing a VM's serial console from a KVM hypervisor with</p>
<pre><code>virsh console mymachine</code></pre>
<p>I found one thing that doesn't carry over from the host to the VM is the terminal window size, so if you try to use something like <code>vim</code> through the console connection, it seems to assume a 80x25 or so window, and when <code>vim</code> exits your console is all screwed up.</p>
<p>It looks like a serial connection doesn't have an out-of-band way of passing that info the way telnet or ssh does, so you have set it manually.   You can discover your settings on the host machine with</p>
<pre><code>stty size</code></pre>
<p>which should show something like:</p>
<pre><code>60 142</code></pre>
<p>on the VM, the same command probably shows</p>
<pre><code>0 0</code></pre>
<p>zero rows and columns, no wonder it's confused.  Fix it by setting the VM to have the same rows and columns as the host with something like:</p>
<pre><code>stty rows 60 columns 142</code></pre>
<p>and you're in business.</p>]]></description>
</item>
</channel>
</rss>