Jekyll2023-12-22T00:51:46+01:00https://simon-mueller.de/feed.xmlSimon Müller’s BlogDaily IT topics. Tech stuff.
Simon Müllerblog@simon-mueller.deBind mounting directories in a CIFS parent directory2023-12-22T00:00:00+01:002023-12-22T00:00:00+01:00https://simon-mueller.de/2023/12/22/Bind-mounting-directories-in-a-CIFS-parent-directory<p>I’ve been having some capacity problems on my Hetzner Cloud instances. To get around these limitations I’ve been using sub accounts on my StorageBox and mount them via CIFS onto their respective targets. However, when I wanted to bind-mount some other directories, my fstab configuration didn’t survive any restarts.</p>
<p>The error message stated:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
</pre></td><td class="rouge-code"><pre>local-fs.target: Found ordering cycle on networking.service/stop
local-fs.target: Found dependency on network-online.target/stop
local-fs.target: Found dependency on <mount-name-redacted>.mount/stop
local-fs.target: Found dependency on local-fs.target/stop
local-fs.target: Job networking.service/stop deleted to break ordering cycle starting with local-fs.target/stop
</pre></td></tr></tbody></table></code></pre></div></div>
<p>This meant going onto the cloud console, opening the serial console window and hitting CTRL+D to continue booting, then mounting everything manually. (Usually <em>mount -av</em> sufficed.)
To get rid of this nasty behaviour, there is an easy-to-implement, but not-so-easy-to-find fix which can be made to the /etc/fstab.</p>
<p>Bind mounts themselves don’t have their own filesystem type. So typically, you would write “none” in the third column of your fstab. However, this will lead to systemd thinking that this is a local filesystem and at that it doesn’t need to wait for the networking to be fully setup first.</p>
<p>So the solution was to simply enter “cifs” instead of “none” in the third column and systemd considered the mountpoint as remote-fs.target and not local-fs.target, thus waiting for the network to come online first, as well as the cifs mount of the parent directory which needs to be mounted in order for the bind mount to climb down its path.</p>
<p>No more cycling dependencies and no more manual boot interactions!</p>Simon Müllerblog@simon-mueller.deI’ve been having some capacity problems on my Hetzner Cloud instances. To get around these limitations I’ve been using sub accounts on my StorageBox and mount them via CIFS onto their respective targets. However, when I wanted to bind-mount some other directories, my fstab configuration didn’t survive any restarts.Persisting External HyperV Switch upon Reboots2023-12-07T00:00:00+01:002023-12-07T00:00:00+01:00https://simon-mueller.de/2023/12/07/Persisting-External-HyperV-Switch-upon-Reboots<p>I recently migrated from WSL1 to WSL2. After the migration, being somebody who prefers to connect to their infrastructure via IPv6, I was struggling with the problem that my WSL2 didn’t have IPv6 connectivity since NAT is default switch setting for the NetAdapter “WSL”.</p>
<p>Long story short, here’s what I did:</p>
<div class="language-powershell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="rouge-code"><pre><span class="c"># Create a new task in Windows' Task Scheduler (WIN+R => taskschd.msc)</span><span class="w">
</span><span class="c"># Trigger: On Boot</span><span class="w">
</span><span class="c"># Action 01:</span><span class="w">
</span><span class="c"># Script:</span><span class="w">
</span><span class="n">C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</span><span class="w">
</span><span class="c"># Arguments:</span><span class="w">
</span><span class="nt">-command</span><span class="w"> </span><span class="s2">"Set-NetAdapterBinding -ComponentID vms_pp -Name Ethernet -Enable </span><span class="bp">$false</span><span class="s2">"</span><span class="w">
</span><span class="c"># Action 02:</span><span class="w">
</span><span class="c"># Script:</span><span class="w">
</span><span class="n">C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</span><span class="w">
</span><span class="c"># Arguments:</span><span class="w">
</span><span class="nt">-command</span><span class="w"> </span><span class="s2">"Set-VMSwitch -Name WSL -NetAdapterName Ethernet"</span><span class="w">
</span></pre></td></tr></tbody></table></code></pre></div></div>
<p>This will remove the “Hyper-V Extensible Switch” binding from the (physical) Ethernet Adapter which is necessary in order to be able to change the WSL Switch to an External one instead of an internal (NAT).
Soon after that you will see your eth0 adapter in the WSL getting a valid IPv6 address.</p>
<p>PS: The process of adding the Scheduled Task to your Windows Box can also be automated via PowerShell.</p>Simon Müllerblog@simon-mueller.deI recently migrated from WSL1 to WSL2. After the migration, being somebody who prefers to connect to their infrastructure via IPv6, I was struggling with the problem that my WSL2 didn’t have IPv6 connectivity since NAT is default switch setting for the NetAdapter “WSL”.Upgrading Mikrotik RouterOS plus AccessPoints via CAPsMAN2023-10-24T00:00:00+02:002023-10-24T00:00:00+02:00https://simon-mueller.de/2023/10/24/Upgrading-Mikrotik-RouterOS-plus-AccessPoints-via-CAPsMAN<p>I always forget that my access points have basically the same OS so when I update my Mikrotik router, I tend to forget to prepare the updates of my access points as well.<br />
This blog post helps myself to do it better next time.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
</pre></td><td class="rouge-code"><pre><span class="c"># Make sure that your CAPsMAN path is set. For example you can set it to "/firmware":</span>
/caps-man manager <span class="nb">set </span>package-path<span class="o">=</span>/firmware
<span class="c"># Check for updates and note the latest version:</span>
/system package update check-for-updates
<span class="c"># Download the firmware for the access points:</span>
/tool fetch https://download.mikrotik.com/routeros/<VERSION>/routeros-mipsbe-<VERSION>.npk dst-path<span class="o">=</span>/firmware/routeros-mipsbe-<VERSION>.npk
</pre></td></tr></tbody></table></code></pre></div></div>
<p>Note: If the directory “/firmware” doesn’t exist, it will be created via the fetch command, nice!</p>Simon Müllerblog@simon-mueller.deI always forget that my access points have basically the same OS so when I update my Mikrotik router, I tend to forget to prepare the updates of my access points as well. This blog post helps myself to do it better next time.Windows Updates Via Powershell On Remote Computers2018-11-10T00:00:00+01:002018-11-10T00:00:00+01:00https://simon-mueller.de/2018/11/10/Windows-Updates-via-PowerShell-on-Remote-Computers<p>Doing Windows Updates has always been a mess. When working with unixoid OSes you are really looking out for something like “<package manager=""> upgrade".</package></p>
<p>Natively pre-installed Windows comes with a thing called <code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>usoclient
</pre></td></tr></tbody></table></code> which let’s you at least choose between searching, downloading and installing updates.</p>
<p>Unfortunately though, you won’t receive any visual feedback if the command you just typed was entered correctly and what the result of your actions were,</p>
<p>Luckily, the Windows community has developed a PowerShell script called <code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>PSWindowsUpdate
</pre></td></tr></tbody></table></code>. It’s featured within the PowerShell Gallery.</p>
<p>This nice so-called PowerShell Module can be installed via Microsoft’s NuGet mechanism by calling simply:</p>
<p><code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>Install-Module PSWindowsUpdate
</pre></td></tr></tbody></table></code></p>
<p>Once the Module is installed you can already use it on your local machine. The following commands are now available:</p>
<ul>
<li>Add-WUOfflineSync</li>
<li>Add-WUServiceManager</li>
<li>Get-WUHistory</li>
<li>Get-WUInstall</li>
<li>Get-WUInstallerStatus</li>
<li>Get-WUList</li>
<li>Hide-WUUpdate</li>
<li>Invoke-WUInstall</li>
<li>Get-WURebootStatus</li>
<li>Get-WUServiceManager</li>
<li>Get-WUUninstall</li>
<li>Remove-WUOfflineSync</li>
<li>Remove-WUServiceManager</li>
<li>Update-WUModule</li>
</ul>
<p>Building an all-in-one command, it would probably look something like this:</p>
<p><code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>Install-WindowsUpdate -Verbose -IgnoreReboot -AcceptAll
</pre></td></tr></tbody></table></code></p>
<p>But what about installing updates also on another (remote) computer?</p>
<p>With the parameter <code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>-Computername <Host1>,<Host2>,..
</pre></td></tr></tbody></table></code> you can also run and install updates on remote computers. But you will soon learn that you have to do the following things to get it working:</p>
<ol>
<li>Add the machines you want to manage updates for to the winrm TrustedHost List: `winrm set winrm/config/client ‘@{TrustedHosts=”HOST1,HOST2,…”}’</li>
<li>Run the module install command on every machine, see above</li>
<li>Add a firewall exception to your target machines (either through active directory gpo, via netsh or manually via the GUI) with the following specifics:
<ul>
<li>Allowed program: %windir%\System32\dllhost.exe</li>
<li>Protocol: TCP</li>
<li>Local Ports: Dynamic RPC Ports</li>
<li>Remote Ports: All Ports</li>
<li>set the rest according to your company policies</li>
</ul>
</li>
</ol>
<p>That’s it!</p>
<p>You should now be able to fully enjoy easy patch management (even without WSUS) and are only a few steps far from automating the whole process via background jobs/scheduling.</p>
<p>(Article might follow)</p>Simon Müllerblog@simon-mueller.deDoing Windows Updates has always been a mess. When working with unixoid OSes you are really looking out for something like “ upgrade".Fc Is A Shell Builtin2016-07-01T00:00:00+02:002016-07-01T00:00:00+02:00https://simon-mueller.de/2016/07/01/fc-is-a-shell-builtin<p>A few days ago, I learned about a command that you can use to edit the last command you typed into your terminal.</p>
<p>Imagine you are writing a very long one-lined command and you are absolutely sure that it will work, but after pressing the ENTER button you find out that you mistyped something.</p>
<p>Now you have to use the arrow keys and/or POS1/END to navigate inside your one-lined command, which is really annoying if your command is so long that your terminal has to scroll to display everything. :(</p>
<p>The fc command can be of great use to you!</p>
<p>Simply type ‘fc’ and you can edit your command in whatever is set as your favourite EDITOR (mine is vim). Now you have the possibility to do things as ‘search-and-replace’ and another nice features. :)</p>Simon Müllerblog@simon-mueller.deA few days ago, I learned about a command that you can use to edit the last command you typed into your terminal.Bulk Edit With Bash2016-06-09T00:00:00+02:002016-06-09T00:00:00+02:00https://simon-mueller.de/2016/06/09/Bulk-edit-with-bash<p>Today I’m sharing a small bash script that I needed some days ago to edit a bunch of files.</p>
<p>Let’s say you were doing a security copy of your favourite CD album a while ago and you were doing it with a trial version of some CD Ripper software which created an output that looked like this:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="rouge-code"><pre>-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-10-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-11-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-12-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-13-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-14-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-15-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-1-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-2-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-3-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-4-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-5-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-6-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-7-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-8-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 bestcdripperever.com_Artist-Album-9-Title.mp3
</pre></td></tr></tbody></table></code></pre></div></div>
<p>Pretty long and unnecessary name for a file right? But with a mighty tool like /bin/bash this is no challenge for us.</p>
<p>Here is how to change the files with a command that fits into one line. Here it goes:</p>
<p><code class="language-plaintext highlighter-rouge"><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
</pre></td><td class="rouge-code"><pre>for i in $(ls); do for j in $(echo $i |awk -F_ '{ print $2 }');do mv -v $i $j; done; done
</pre></td></tr></tbody></table></code></p>
<p>et voilà, the folder now looks much more tidy:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="rouge-code"><pre>-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-10-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-11-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-12-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-13-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-14-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-15-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-1-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-2-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-3-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-4-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-5-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-6-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-7-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-8-Title.mp3
-rw-r--r-- 1 simon simon 0 Jun 9 20:30 Artist-Album-9-Title.mp3
</pre></td></tr></tbody></table></code></pre></div></div>
<p>So what is the magic behind this?</p>
<p>Let’s look at all the commands that were used:</p>
<ul>
<li>
<p>for : a simple for-loop look like this: ‘for i in 1 2 3; do some_command; done’ (note that we are using two in this one-liner)</p>
</li>
<li>
<p>ls : shows the content of the directory without any information about the contents</p>
</li>
<li>
<p>echo : writes something on the standard output (so that we see it on the commandline)</p>
</li>
<li>
<p>awk : a neat command that can manipulate input, the parameter -F followed by a character divides the input into pieces, which you can then output using { print $columnnumber }</p>
</li>
<li>
<p>mv : moves files, can also be used for renaming</p>
</li>
</ul>
<p>So, the first for-loop is running through all the files in the directory and creates variables ($1,$2,$3,etc.). The second for-loop prints the file of every line the first for-loop has gathered and divides the part before and after the _ . It only remembers the part after it, though ($2). Now we have the old file name in $i and the new name without our prefix in $j. Now the second for-loop just renames every single file in the directory.</p>
<p>That’s it!</p>Simon Müllerblog@simon-mueller.deToday I’m sharing a small bash script that I needed some days ago to edit a bunch of files.Hello And Welcome2016-06-08T00:00:00+02:002016-06-08T00:00:00+02:00https://simon-mueller.de/2016/06/08/Hello-and-welcome<p>…to my blog.</p>
<p>In this blog you will find solutions to things that I have to deal with on a daily basis. Things that might be useful for yourself, if you are working in IT as well. Of course I will try to describe the topic at hand in such a way that someone outside of IT also has an idea what I was trying to achieve.</p>Simon Müllerblog@simon-mueller.de…to my blog.