<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.1.1">Jekyll</generator><link href="https://blog.msbit.com.au/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.msbit.com.au/" rel="alternate" type="text/html" /><updated>2020-08-20T22:45:58+10:00</updated><id>https://blog.msbit.com.au/feed.xml</id><title type="html">blog.msbit.com.au</title><entry><title type="html">Sending non-text emails with stunnel and netcat</title><link href="https://blog.msbit.com.au/reference/2018/08/08/sending-non-text-emails-with-stunnel-and-netcat.html" rel="alternate" type="text/html" title="Sending non-text emails with stunnel and netcat" /><published>2018-08-08T10:19:41+10:00</published><updated>2018-08-08T10:19:41+10:00</updated><id>https://blog.msbit.com.au/reference/2018/08/08/sending-non-text-emails-with-stunnel-and-netcat</id><content type="html" xml:base="https://blog.msbit.com.au/reference/2018/08/08/sending-non-text-emails-with-stunnel-and-netcat.html">&lt;h3 id=&quot;the-initial-problem&quot;&gt;The initial problem&lt;/h3&gt;

&lt;p&gt;Today I was putting together an update for my answer on &lt;a href=&quot;https://stackoverflow.com/questions/51718121/how-to-get-the-plaintext-representation-of-an-e-mail-body-out-from-the-mime-mys/51720861&quot;&gt;this StackOverflow question&lt;/a&gt;, and it occurred to me that (as I’d noted in the edit) it would be possible to create an email that had neither a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; part or a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/html&lt;/code&gt; part.
While I was fairly confident that this would be true, I thought I should quickly confirm this, and the simplest way that I could think of was to send the email through to the SMTP server using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netcat&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, as I’m using Gmail for my email, the SMTP server is only available via secure connection to either port 465 (for SSL connections) or port 587 (for TLS/STARTTLS connections) as shown &lt;a href=&quot;https://support.google.com/mail/answer/7126229&quot;&gt;here&lt;/a&gt;. Therefore, I was going to need some kind of SSL tunnel to allow me to connect in plaintext using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netcat&lt;/code&gt;, but connect to the SMTP server over SSL. From my days using Slackware consistently, I remembered &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stunnel&lt;/code&gt;, which is conveniently available on macOS via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;cheat-sheet&quot;&gt;Cheat sheet&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ brew install stunnel
$ cat &amp;lt;&amp;lt; EOF &amp;gt; smtps-gmail.conf
&amp;gt; [smtps-gmail]
&amp;gt; accept = localhost:2525
&amp;gt; client = yes 
&amp;gt; connect = smtp.gmail.com:465
&amp;gt; EOF
$ stunnel smtps-gmail.conf
$ nc -c localhost 2525
&amp;gt; EHLO msbit.com.au
&amp;gt; AUTH LOGIN
&amp;gt; &amp;lt;Base64 encoded username&amp;gt;
&amp;gt; &amp;lt;Base64 encoded password&amp;gt;
&amp;gt; MAIL FROM: &amp;lt;tom@msbit.com.au&amp;gt;
&amp;gt; RCPT TO: &amp;lt;tom@msbit.com.au&amp;gt;
&amp;gt; DATA
&amp;gt; Content-Type: application/data; name=&quot;data.bin&quot;
&amp;gt; Content-Transfer-Encoding: base64
&amp;gt; &amp;lt;Base64 encoded data&amp;gt;
&amp;gt; .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;making-the-tunnel&quot;&gt;Making the tunnel&lt;/h3&gt;

&lt;p&gt;Firstly, we will need to install &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stunnel&lt;/code&gt;, which is as simple as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ brew install stunnel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stunnel&lt;/code&gt; configuration file can define multiple services, each with its own local options. In this case, there is only one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smtps-gmail&lt;/code&gt;, and the configuration defines the endpoint on which to listen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;accept = localhost:2525
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;the endpoint to connect to:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;connect = smtp.gmail.com:465
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and the mode in which to operate:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;client = yes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which means that the listening connection does not require SSL.&lt;/p&gt;

&lt;p&gt;Putting it all together we have:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[smtps-gmail]
accept = localhost:2525
client = yes 
connect = smtp.gmail.com:465
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can now start the tunnel by running:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ stunnel smtps-gmail.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;NOTE: The listening port is set to 2525 to ensure it can be bound to as an unprivileged user. If I wanted to use the well-known port for SMTP, port 25, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stunnel&lt;/code&gt; would need to be run as a privileged user (e.g. via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;preparing-to-send&quot;&gt;Preparing to send&lt;/h3&gt;

&lt;p&gt;We need to prepare a few items in advance, as the commands are entered interactively:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;username&lt;/li&gt;
  &lt;li&gt;password&lt;/li&gt;
  &lt;li&gt;message data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these involve Base64 encoding to protect the contents during transmission, as SMTP is traditionally not &lt;a href=&quot;https://en.wikipedia.org/wiki/8-bit_clean&quot;&gt;8-bit clean&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;format-username&quot;&gt;Format username&lt;/h4&gt;

&lt;p&gt;To prepare the username and password strings:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ echo -n 'username' | base64

dXNlcm5hbWU=
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;format-password&quot;&gt;Format password&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ echo -n 'password' | base64

cGFzc3dvcmQ=
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;generate-message-body&quot;&gt;Generate message body&lt;/h4&gt;

&lt;p&gt;For the purposes of this, I’m going to generate a random file for sending:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ dd if=/dev/urandom of=data.bin bs=1024 count=1
$ base64 --break 76 data.bin

ypV6owJCIyb+nm5ayZbeeaVp5Wqfxw+VWce+NE2DDAz+LDWCNbFd05LfyyXCVaclsL65Q26ILiHD
RvzMMyRRPyvWvG8q/R3yQcUykFXvTQ4GmOkpMo4hhcqmmfj9blhXT0gTW5UHIMDCSJdvMc8gaS4i
tvEs5ftjCeTMoX1IXOv0N5hDPwue125ZFkG4WCK4LTd44BIRJyVDdMLh+ycVNmCkFq+l3dCTy34r
w2/c9WPpvzo+w1rvA2ryZcd4MXVBbLc7EBA5V0v7IKrCj6af/GmfqulxPWHCwDdhiOc/v1ctO8Q1
jaorupDkRioF3YnN/6SZDJYYxcc5okLRh8DOmYGPlLLx1gthqXeo6BY1wcf5Rh5JiRf6gSgZ2djL
PWBXt0TC96ndK4VT/pxQvShDx/eIG5QSaziNFXQUkVnXfxyazwZdZRgVxdjwrpkM0MZQixVgMPoS
81ucUlhu99SCd+LPfWbsa9Cloyec6GAmfXwvNaYK57g15fTZRm9wftJnzeqavoePIFK9ldgkdgob
Ek2Cm+lEK+2IVmrYg0Y4zWDsuWX01Wf9SKw+QFro4zdMpFrFCB2GAW8ErZrvWE/mjRlXtY4Ja2MN
OQ6KF8pRuzLehNJJhvQJjKGP2RzTqs/OcNnGULOUiy9SIBEnszzhtjqlkMbuZ+cwEKWmRX+/5Wi9
CK28ZxAMSEuAQbCOEEAcKcrqWJKr8bgrOmp0A41IaiZIKzwqkONinCFOEdRSdRvGpJ67oDplvzB6
gLT2Ij+7F5Sc3Yyg00mXK+Zae7bcsMwYVWcH6b3XYRo0LaNUTlCz4oHFWY4/rhhEhVA0zRZpKKYX
H9C7qInKh1+1TJ3hmNW87jrttFft/ggW0LYoTKZEVEAeJHtICJay6GsFaqG6q/KRCdV1ZxfImMgH
gbhgEEzDq2hTpACgBkRu7SUrcKPSzXgBufbUrZwH4EZRcj+x6PRFM0D9EOT+uPQxK3EBNmTjwwLa
uYpP0hDg84o4e7IkCbBHdNNc1PK1YuPXlKjIyNQd5kOQxJJY8+GVgA5IGTrSWUitCh/yW7U8Px7B
Mw7xMKxAdu4nBptvS8mgc1ueikyRGVPTv3NJ44jO6IBCqce3a0yGXLZ3DNc1p0IR1MKe6ta584Fd
bCw5/3/QowqroFMEORxdq/UY7Flea4FufoVCmAhHOVm/W7s4F/ZnF7sUBH0GV8b5cnLmpn1KPsKK
hA4jqT+KrofjiPreu99qGkv01oxPAPLDGNPU7ahCPETK6bznGMO3Fw8dZW9ElonZywP99P8UQU7q
7QP1KMA8EdB0DDdtLpvQeuHWBv3aBgwRnx1HC44fs6yzCVn9H5/SfDUyWh29dWJZWpRBM7If4Q==
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The simplest format for the body of the message specifies the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type&lt;/code&gt;, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Transfer-Encoding&lt;/code&gt; and provides the encoded file. Given that this is for testing sending an email without parts of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/html&lt;/code&gt;, the message body will be as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Content-Type: application/data; name=&quot;data.bin&quot;
Content-Transfer-Encoding: base64
ypV6owJCIyb+nm5ayZbeeaVp5Wqfxw+VWce+NE2DDAz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ikyRGVPTv3NJ44jO6IBCqce3a0yGXLZ3DNc1p0IR1MKe6ta584Fd
bCw5/3/QowqroFMEORxdq/UY7Flea4FufoVCmAhHOVm/W7s4F/ZnF7sUBH0GV8b5cnLmpn1KPsKK
hA4jqT+KrofjiPreu99qGkv01oxPAPLDGNPU7ahCPETK6bznGMO3Fw8dZW9ElonZywP99P8UQU7q
7QP1KMA8EdB0DDdtLpvQeuHWBv3aBgwRnx1HC44fs6yzCVn9H5/SfDUyWh29dWJZWpRBM7If4Q==
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;sending-the-email&quot;&gt;Sending the email&lt;/h3&gt;

&lt;p&gt;Now that we have the tunnel running and our encoded contents prepared, we can connect through it to the SMTP server by running:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ nc -c localhost 2525
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;NOTE: On macOS, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netcat&lt;/code&gt; command has the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c&lt;/code&gt; option, which sends CRLF as the line-ending. This is important when entering the body of the email, as the end of the data is expected to be exactly &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;.&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are greeted with the service ready message:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;220 smtp.gmail.com ESMTP v17-v6sm3241947pfn.177 - gsmtp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From here, we interactively enter the SMTP commands effectively in a script as expected by the server:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;EHLO msbit.com.au

250-smtp.gmail.com at your service, [xxx.xxx.xxx.xxx]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

AUTH LOGIN

334 VXNlcm5hbWU6

dXNlcm5hbWU=

334 UGFzc3dvcmQ6

cGFzc3dvcmQ=

235 2.7.0 Accepted

MAIL FROM: &amp;lt;tom@msbit.com.au&amp;gt;

250 2.1.0 OK v17-v6sm3241947pfn.177 - gsmtp

RCPT TO: &amp;lt;tom@msbit.com.au&amp;gt;

250 2.1.5 OK v17-v6sm3241947pfn.177 - gsmtp

DATA

354  Go ahead v17-v6sm3241947pfn.177 - gsmtp

Content-Type: application/data; name=&quot;data.bin&quot;
Content-Transfer-Encoding: base64
ypV6owJCIyb+nm5ayZbeeaVp5Wqfxw+VWce+NE2DDAz+LDWCNbFd05LfyyXCVaclsL65Q26ILiHD
RvzMMyRRPyvWvG8q/R3yQcUykFXvTQ4GmOkpMo4hhcqmmfj9blhXT0gTW5UHIMDCSJdvMc8gaS4i
tvEs5ftjCeTMoX1IXOv0N5hDPwue125ZFkG4WCK4LTd44BIRJyVDdMLh+ycVNmCkFq+l3dCTy34r
w2/c9WPpvzo+w1rvA2ryZcd4MXVBbLc7EBA5V0v7IKrCj6af/GmfqulxPWHCwDdhiOc/v1ctO8Q1
jaorupDkRioF3YnN/6SZDJYYxcc5okLRh8DOmYGPlLLx1gthqXeo6BY1wcf5Rh5JiRf6gSgZ2djL
PWBXt0TC96ndK4VT/pxQvShDx/eIG5Q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&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&lt;/code&gt; line to end the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DATA&lt;/code&gt; portion.&lt;/p&gt;

&lt;p&gt;The email should now have been sent!&lt;/p&gt;

&lt;h3 id=&quot;confirming-the-output&quot;&gt;Confirming the output&lt;/h3&gt;

&lt;p&gt;When checking my inbox, there is a new email from me, with no subject, or body, but an attachment. The full email message is as shown below:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Bcc: tom@msbit.com.au
Return-Path: &amp;lt;tom@msbit.com.au&amp;gt;
Received: from msbit.com.au (xxx.xxx.xxx.xxx.xxx. [xxx.xxx.xxx.xxx])
        by smtp.gmail.com with ESMTPSA id v17-v6sm3241947pfn.177.2018.08.07.18.43.09
        for &amp;lt;tom@msbit.com.au&amp;gt;
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 07 Aug 2018 18:43:25 -0700 (PDT)
Message-ID: &amp;lt;5b6a4abd.1c69fb81.319ec.8e62@mx.google.com&amp;gt;
Date: Tue, 07 Aug 2018 18:43:25 -0700 (PDT)
From: tom@msbit.com.au
Content-Type: application/data; name=&quot;data.bin&quot;
Content-Transfer-Encoding: base64

ypV6owJCIyb+nm5ayZbeeaVp5Wqfxw+VWce+NE2DDAz+LDWCNbFd05LfyyXCVaclsL65Q26ILiHD
RvzMMyRRPyvWvG8q/R3yQcUykFXvTQ4GmOkpMo4hhcqmmfj9blhXT0gTW5UHIMDCSJdvMc8gaS4i
tvEs5ftjCeTMoX1IXOv0N5hDPwue125ZFkG4WCK4LTd44BIRJyVDdMLh+ycVNmCkFq+l3dCTy34r
w2/c9WPpvzo+w1rvA2ryZcd4MXVBbLc7EBA5V0v7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aBgwRnx1HC44fs6yzCVn9H5/SfDUyWh29dWJZWpRBM7If4Q==
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As we can see, the email has been delivered, the content is exactly the same as what was sent, and there is no mention of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/html&lt;/code&gt; component. As a final test, we can download the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data.bin&lt;/code&gt; attachment and compare the SHA hashes:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ shasum data.bin
e54b3d70b1368829d5db4c9ea77f2f667adf5b59  data.bin
$ shasum ~/Downloads/data.bin
e54b3d70b1368829d5db4c9ea77f2f667adf5b59  /Users/tom/Downloads/data.bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which also confirm that the file has been successfully sent.&lt;/p&gt;</content><author><name></name></author><category term="reference" /><summary type="html">The initial problem</summary></entry><entry><title type="html">OpenBSD Kernels</title><link href="https://blog.msbit.com.au/reference/2018/04/23/opensbd-kernels.html" rel="alternate" type="text/html" title="OpenBSD Kernels" /><published>2018-04-23T14:07:34+10:00</published><updated>2018-04-23T14:07:34+10:00</updated><id>https://blog.msbit.com.au/reference/2018/04/23/opensbd-kernels</id><content type="html" xml:base="https://blog.msbit.com.au/reference/2018/04/23/opensbd-kernels.html">&lt;h3 id=&quot;the-initial-problem&quot;&gt;The initial problem&lt;/h3&gt;

&lt;p&gt;This weekend I’ve installed OpenBSD 6.3 on my old Macbook (&lt;a href=&quot;https://everymac.com/systems/apple/macbook/specs/macbook-core-2-duo-2.4-white-13-early-2008-penryn-specs.html&quot;&gt;Early 2008&lt;/a&gt;), and immediately I remember why I love this operating system. However, not everything is completely rosy.&lt;/p&gt;

&lt;p&gt;After boot, the &lt;a href=&quot;https://man.openbsd.org/inteldrm&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inteldrm&lt;/code&gt;&lt;/a&gt; driver appears to get confused and changes the console resolution to 848x480 (480i), but restricts this to the top left of the Macbook’s 1280x800 panel. Taking a look online, I found the following suggestion &lt;a href=&quot;http://openbsd-archive.7691.n7.nabble.com/inteldrm-4-regression-and-multi-screen-at-boot-tp322161p322264.html&quot;&gt;here&lt;/a&gt;: build a new kernel with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DRMDEBUG&lt;/code&gt; enabled and consult the output.&lt;/p&gt;

&lt;h3 id=&quot;cheat-sheet&quot;&gt;Cheat sheet&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# export KERNEL_CONFIGURATION_NAME=GENERIC_CUSTOM_NAME.MP
# cat &amp;lt;&amp;lt; EOF &amp;gt; /sys/arch/$(machine)/conf/${KERNEL_CONFIGURATION_NAME}
&amp;gt; include &quot;arch/i386/conf/GENERIC.MP&quot;
&amp;gt;
&amp;gt; #option OPTION1
&amp;gt; #option OPTION2
&amp;gt;
&amp;gt; EOF
# mkdir /sys/arch/$(machine)/compile/${KERNEL_CONFIGURATION_NAME}
# cat &amp;lt;&amp;lt; EOF &amp;gt; /sys/arch/$(machine)/compile/${KERNEL_CONFIGURATION_NAME}/Makefile
&amp;gt; .include &quot;../Makefile.inc&quot;
&amp;gt; EOF
# cd /sys/arch/$(machine)/compile/${KERNEL_CONFIGURATION_NAME}
# make obj
# make config
# make &amp;amp;&amp;amp; make install
# reboot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;the-process&quot;&gt;The process&lt;/h3&gt;

&lt;p&gt;The first steps are as listed &lt;a href=&quot;https://www.openbsd.org/faq/faq5.html&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cd /usr
$ cvs -qd anoncvs@anoncvs.ca.openbsd.org:/cvs checkout -rOPENBSD_6_3 -P src
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will take a while, and afterwards you’ll have all the source for the kernel and the core userland nicely in place.&lt;/p&gt;

&lt;p&gt;Given that it’s been a long time since I’ve compiled an OpenBSD kernel, I thought I’d follow the instructions &lt;a href=&quot;https://man.openbsd.org/release&quot;&gt;here&lt;/a&gt; pretty much verbatim to start with:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /sys/arch/$(machine)/compile/GENERIC.MP
# make obj
# make config
# make &amp;amp;&amp;amp; make install
# reboot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Fingers crossed, breath held and my Macbook comes back up. Success; I know I can build a kernel properly.&lt;/p&gt;

&lt;h3 id=&quot;configuration-modification&quot;&gt;Configuration modification&lt;/h3&gt;

&lt;p&gt;Now, as I’d noted in the introduction, I needed to enable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DRMDEBUG&lt;/code&gt; to enable the &lt;a href=&quot;https://man.openbsd.org/drm&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;drm&lt;/code&gt;&lt;/a&gt; debug logging, and the way to do this is via &lt;a href=&quot;https://man.openbsd.org/options&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;options&lt;/code&gt;&lt;/a&gt;. Each of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;option&lt;/code&gt; entries are provided as defines to the kernel build process, so in my case:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;option DRMDEBUG
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;would result in:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-DDRMDEBUG
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;being added to the compiler flags.&lt;/p&gt;

&lt;h4 id=&quot;where-to-add-this&quot;&gt;Where to add this?&lt;/h4&gt;

&lt;p&gt;In the compilation steps, the only obviously variable item (besides the call to &lt;a href=&quot;https://man.openbsd.org/machine&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;machine&lt;/code&gt;&lt;/a&gt; which will be the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i386&lt;/code&gt; for any invocations on this installation) is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GENERIC.MP&lt;/code&gt;. If we take a look at this directory (ignoring source control files and the generated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;obj&lt;/code&gt; link) we find a single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Makefile&lt;/code&gt; which is the tail end of the following include hierarchy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/i386/compile/GENERIC.MP/Makefile&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/i386/compile/Makefile.inc&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/src/share/mk/bsd.obj.mk&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/src/share/mk/bsd.own.mk&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$MAKECONF&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/mk.conf&lt;/code&gt; if they exist&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The target we are interested in, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt;, is defined in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/i386/compile/Makefile.inc&lt;/code&gt; as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config:
        config ${.CURDIR:M*.PROF:C/.*/-p/} -b ${.OBJDIR} \
                -s ${SYSDIR} ${CONFDIR}/${.CURDIR:T:S/.PROF$//}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This command makes use of &lt;a href=&quot;https://man.openbsd.org/config&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt;&lt;/a&gt; command to create a kernel build directory for a specified top-level source kernel source directory based on the configuration file. This configuration file (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${CONFDIR}/${.CURDIR:T:S/.PROF$//}&lt;/code&gt;) is the next thing to look at.&lt;/p&gt;

&lt;h4 id=&quot;variable-interpretation&quot;&gt;Variable interpretation&lt;/h4&gt;

&lt;p&gt;To work out what this expands to, we need to know a few things from &lt;a href=&quot;http://man.openbsd.org/make#VARIABLE_ASSIGNMENTS&quot;&gt;here&lt;/a&gt;, namely:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The built in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.CURDIR&lt;/code&gt; variable, which is the path from which &lt;a href=&quot;https://man.openbsd.org/make&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;&lt;/a&gt; is called&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:S&lt;/code&gt; modifier, which performs string replacement on a variable&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:T&lt;/code&gt; modifier, which replaces the variable with its last path component&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Due to where we called &lt;a href=&quot;https://man.openbsd.org/make&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;&lt;/a&gt; from, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.CURDIR&lt;/code&gt; is now:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/sys/arch/i386/compile/GENERIC.MP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Based on this, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONFDIR&lt;/code&gt; (defined at the top of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/i386/compile/Makefile.inc&lt;/code&gt; as the absolute path to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${.CURDIR}/../../conf&lt;/code&gt;), becomes:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/sys/arch/i386/conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;so we have:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/sys/arch/i386/conf/${.CURDIR:T:S/.PROF$//}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.CURDIR:T:S/.PROF$//&lt;/code&gt; is getting the last path component of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/i386/compile/GENERIC.MP&lt;/code&gt; and removing the first (and only, based on the regex anchoring) occurence of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.PROF&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;NOTE: The removal of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.PROF&lt;/code&gt; in this case isn’t relevant, but works in concert with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${.CURDIR:M*.PROF:C/.*/-p/}&lt;/code&gt; in the call to &lt;a href=&quot;https://man.openbsd.org/config&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt;&lt;/a&gt; to automatically include profiling code for appropriately named configurations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Expanding this out, we now have:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/sys/arch/i386/conf/GENERIC.MP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Voila.&lt;/p&gt;

&lt;p&gt;The contents of this configuration file (comments removed) are:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;include &quot;arch/i386/conf/GENERIC&quot;

option          MULTIPROCESSOR

cpu*            at mainbus?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which is where we could set our options.&lt;/p&gt;

&lt;h3 id=&quot;custom-configuration&quot;&gt;Custom configuration&lt;/h3&gt;

&lt;p&gt;I say &lt;em&gt;could&lt;/em&gt; because it’s not a great idea to modify a configuration file that’s checked into source control, and from the use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;include &quot;arch/i386/conf/GENERIC&quot;&lt;/code&gt; at the top of the file it’s clear that we can easily extend the configuration, creating our own custom configuration. All we need to do is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;create the configuration file&lt;/li&gt;
  &lt;li&gt;add a correspondingly named directory and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Makefile&lt;/code&gt; under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/sys/arch/$(machine)/compile&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Given that I’m adding the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DRMDEBUG&lt;/code&gt; flag, I’m going to name the configuration &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GENERIC_DRMDEBUG.MP&lt;/code&gt;, so the commands look like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cat &amp;lt;&amp;lt; EOF &amp;gt; /sys/arch/$(machine)/conf/GENERIC_DRMDEBUG.MP
&amp;gt; include &quot;arch/i386/conf/GENERIC.MP&quot;
&amp;gt;
&amp;gt; option  DRMDEBUG
&amp;gt; EOF
# mkdir /sys/arch/$(machine)/compile/GENERIC_DRMDEBUG.MP
# cat &amp;lt;&amp;lt; EOF &amp;gt; /sys/arch/$(machine)/compile/GENERIC_DRMDEBUG.MP/Makefile
&amp;gt; .include &quot;../Makefile.inc&quot;
&amp;gt; EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, the compilation is almost exactly the same as the default:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /sys/arch/$(machine)/compile/GENERIC_DRMDEBUG.MP
# make obj
# make config
# make &amp;amp;&amp;amp; make install
# reboot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once that’s done and the computer restarts, I can check the (voluminous) contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var/log/messages&lt;/code&gt; for the additional logging information, and hopefully this puts me on the path to working out my initial console resolution issue.&lt;/p&gt;</content><author><name></name></author><category term="reference" /><summary type="html">The initial problem</summary></entry><entry><title type="html">Windows 10 Update Issues</title><link href="https://blog.msbit.com.au/rabbit-hole/2018/04/12/windows-10-update-issue.html" rel="alternate" type="text/html" title="Windows 10 Update Issues" /><published>2018-04-12T13:08:18+10:00</published><updated>2018-04-12T13:08:18+10:00</updated><id>https://blog.msbit.com.au/rabbit-hole/2018/04/12/windows-10-update-issue</id><content type="html" xml:base="https://blog.msbit.com.au/rabbit-hole/2018/04/12/windows-10-update-issue.html">&lt;h3 id=&quot;an-issue-with-an-update&quot;&gt;An issue with an update&lt;/h3&gt;

&lt;p&gt;After waking my Windows 10 PC up and running updates, I was told that the latest update (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2018-04 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4093112)&lt;/code&gt;) could not be installed. Looking over the update history, it appeared that this was the second update that couldn’t be installed, the first being &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2018-02 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4074588)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Restarting the PC, either manually or through the button in Windows Update, wasn’t causing the update to be installed; in my experience the update would be queued up immediately prior to restart, or immediately after restart.&lt;/p&gt;

&lt;p&gt;Some information could be gleaned in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Event Viewer&lt;/code&gt;, under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Windows Logs&lt;/code&gt; &amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt;, filtering by:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Event sources&lt;/code&gt; restricted to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WindowsUpdateClient&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Event level&lt;/code&gt; restricted to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Error&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;or using the following XML filter:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;QueryList&amp;gt;
  &amp;lt;Query Id=&quot;0&quot; Path=&quot;System&quot;&amp;gt;
    &amp;lt;Select Path=&quot;System&quot;&amp;gt;*[System[Provider[@Name='Microsoft-Windows-WindowsUpdateClient'] and (Level=2)]]&amp;lt;/Select&amp;gt;
  &amp;lt;/Query&amp;gt;
&amp;lt;/QueryList&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From this I had the following distinct events:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Installation Failure: Windows failed to install the following update with error 0x80010108: 2018-02 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4074588).
Installation Failure: Windows failed to install the following update with error 0x80070BC2: 2018-02 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4074588).
Installation Failure: Windows failed to install the following update with error 0x80070020: 2018-02 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4074588).
Installation Failure: Windows failed to install the following update with error 0x80246007: 2018-02 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4074588).
Installation Failure: Windows failed to install the following update with error 0x80070BC2: 2018-04 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4093112).
Installation Failure: Windows failed to install the following update with error 0x8007045B: 2018-04 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4093112).
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;resolving down to the following error codes:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0x80010108
0x80070020
0x8007045B
0x80070BC2
0x80246007
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;a-solution-is-found&quot;&gt;A solution is found&lt;/h3&gt;

&lt;p&gt;Looking for these error codes online, I luckily found a very helpful comment on Reddit &lt;a href=&quot;https://www.reddit.com/r/Windows10/comments/7otpmx/windows_10_update_kb4056892_fails_to_install/dt0u3tr/&quot;&gt;here&lt;/a&gt; which indicated that ensuring particular services were configured to run automatically would solve the issue.&lt;/p&gt;

&lt;p&gt;The services in question were:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BITS&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Background Intelligent Transfer Service&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CryptSvc&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cryptographic Services&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Windows Modules Installer&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wuauserv&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Windows Update&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As opposed to simply configuring the services to run automatically, I thought I’d take a look at the current configuration of each.&lt;/p&gt;

&lt;p&gt;Before attempting the fix, the service configuration for each (obtained via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sc qc &amp;lt;service-name&amp;gt;&lt;/code&gt;) was:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SERVICE_NAME: BITS
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 2   AUTO_START  (DELAYED)
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\WINDOWS\System32\svchost.exe -k netsvcs -p
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Background Intelligent Transfer Service
        DEPENDENCIES       : RpcSs
        SERVICE_START_NAME : LocalSystem

SERVICE_NAME: CryptSvc
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\WINDOWS\system32\svchost.exe -k NetworkService -p
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Cryptographic Services
        DEPENDENCIES       : RpcSs
        SERVICE_START_NAME : NT Authority\NetworkService

SERVICE_NAME: TrustedInstaller
        TYPE               : 10  WIN32_OWN_PROCESS
        START_TYPE         : 3   DEMAND_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\WINDOWS\servicing\TrustedInstaller.exe
        LOAD_ORDER_GROUP   : ProfSvc_Group
        TAG                : 0
        DISPLAY_NAME       : Windows Modules Installer
        DEPENDENCIES       :
        SERVICE_START_NAME : localSystem

SERVICE_NAME: wuauserv
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\WINDOWS\system32\svchost.exe -k netsvcs
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Windows Update
        DEPENDENCIES       : rpcss
        SERVICE_START_NAME : LocalSystem
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The odd one out in this listing is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt;, with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;START_TYPE&lt;/code&gt; of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEMAND_START&lt;/code&gt;, all others have some variant of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AUTO_START&lt;/code&gt;. More importantly, the current status of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; (obtained via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sc query TrustedInstaller&lt;/code&gt;) was:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SERVICE_NAME: TrustedInstaller
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;so the service was not running.&lt;/p&gt;

&lt;p&gt;My understanding of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEMAND_START&lt;/code&gt; is that it should be, well, started on demand, so Windows Update should have been able to start it as part of the update installation process. However, this seemed a very likely issue, so I reconfigured the start type via the command mentioned in the Reddit comment, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sc config TrustedInstaller start= auto&lt;/code&gt; and restarted  my PC.&lt;/p&gt;

&lt;p&gt;After this, initialising a restart via Windows Update proceeded smoothly, and the update has been installed.&lt;/p&gt;

&lt;h3 id=&quot;further-investigation&quot;&gt;Further investigation&lt;/h3&gt;

&lt;p&gt;Now I felt it was worth looking into how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; service had been configured for on-demand start, so I took a look at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Event Viewer&lt;/code&gt; once again. This time, filtering by:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Event sources&lt;/code&gt; restricted to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Service Control Manager&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WindowsUpdateClient&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;or using the following XML filter:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;QueryList&amp;gt;
  &amp;lt;Query Id=&quot;0&quot; Path=&quot;System&quot;&amp;gt;
    &amp;lt;Select Path=&quot;System&quot;&amp;gt;*[System[Provider[@Name='Service Control Manager' or @Name='Microsoft-Windows-WindowsUpdateClient']]]&amp;lt;/Select&amp;gt;
  &amp;lt;/Query&amp;gt;
&amp;lt;/QueryList&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Around the time of a failed update installation were the following events:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;The start type of the Windows Update service was changed from demand start to auto start.
Windows Update started downloading an update.
The start type of the Windows Modules Installer service was changed from demand start to auto start.
Installation Started: Windows has started installing the following update: 2018-04 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4093112)
The start type of the Windows Modules Installer service was changed from auto start to demand start.
The start type of the Update Orchestrator Service service was changed from demand start to auto start.
The start type of the Background Intelligent Transfer Service service was changed from auto start to demand start.
The Update Orchestrator Service service terminated with the following error:
    This operation returned because the timeout period expired.
The start type of the Update Orchestrator Service service was changed from auto start to demand start.
Installation Failure: Windows failed to install the following update with error 0x80070BC2: 2018-04 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4093112).
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From this listing, it appears that:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wuauserv&lt;/code&gt; initiates an update download and starts &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; starts an install, but stops due to the installation requiring a restart&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UsoSvc&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Update Orchestrator Service&lt;/code&gt;) is started but is terminated due to an error&lt;/li&gt;
  &lt;li&gt;Installation of the update fails&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how does changing the start type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; do to fix this issue? My guess is that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UsoSvc&lt;/code&gt; is tasked with re-enabling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; (among other things), and so if it fails it also doesn’t re-enable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; to finalise the installation during the restart process.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;That’s about as far as I can go now, without attempting to rollback the update and reinstall to trigger the issue. Going forward, I’m going to return the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrustedInstaller&lt;/code&gt; service to start on demand, and see whether this issue rears its head again for the next update.&lt;/p&gt;</content><author><name></name></author><category term="rabbit-hole" /><summary type="html">An issue with an update</summary></entry></feed>