<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MkKiefer</title>
    <description>The latest articles on DEV Community by MkKiefer (@mkkiefer).</description>
    <link>https://dev.to/mkkiefer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4248614%2Fede8f4cf-59da-441d-8212-aa6bbb283fb8.png</url>
      <title>DEV Community: MkKiefer</title>
      <link>https://dev.to/mkkiefer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mkkiefer"/>
    <language>en</language>
    <item>
      <title>Your PLC Doesn't Care About Your Event Loop</title>
      <dc:creator>MkKiefer</dc:creator>
      <pubDate>Sun, 06 Dec 2026 21:29:17 +0000</pubDate>
      <link>https://dev.to/mkkiefer/your-plc-doesnt-care-about-your-event-loop-1h4</link>
      <guid>https://dev.to/mkkiefer/your-plc-doesnt-care-about-your-event-loop-1h4</guid>
      <description>&lt;p&gt;&lt;em&gt;Four lessons from putting asyncio on the factory floor&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;At some point, almost every automation team picks up Python.&lt;/p&gt;

&lt;p&gt;It rarely starts as a big decision. Someone needs a quick script to log a few PLC variables to a CSV. Then the script needs a small web dashboard. Then it has to push data to a database, watch a second machine, and send an alert when a value drifts. A few months later the "quick script" is a service that the production line depends on.&lt;/p&gt;

&lt;p&gt;If your controllers are Beckhoff TwinCAT systems, that service talks &lt;strong&gt;ADS&lt;/strong&gt;, the Automation Device Specification. ADS is a compact binary protocol over TCP (port 48898), and it is pleasant to work with once you know it. The usual way to use it from Python, though, is synchronous: open a connection, read a value, sleep, repeat. To watch more than one thing, you add threads.&lt;/p&gt;

&lt;p&gt;That works fine, until the service has to watch thirty machines, serve a UI, and write to a historian, all at once.&lt;/p&gt;

&lt;p&gt;I spent a good part of the last year moving this kind of workload to &lt;code&gt;asyncio&lt;/code&gt;. Here is what I learned, mostly the hard way.&lt;/p&gt;




&lt;h2&gt;
  
  
  Lesson 1: Round-trips are the real cost
&lt;/h2&gt;

&lt;p&gt;A PLC answers a single read quickly. The time goes into the round-trip: framing the request, crossing the network, waiting for the runtime to pick it up, and coming back. Do that 500 times in a loop and you have a slow application, however fast each read is.&lt;/p&gt;

&lt;p&gt;ADS has an answer that is easy to miss: &lt;strong&gt;sum commands&lt;/strong&gt;. Instead of 500 separate requests, you send one request that holds 500 sub-requests, and you get one response back. On a typical network this turns &lt;em&gt;seconds&lt;/em&gt; of polling into &lt;em&gt;milliseconds&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;There is a catch. Batching has a ceiling, and the PLC enforces it. Ask for too much in one request (for example, symbol metadata for hundreds of variables, each with a generous response buffer) and the router simply refuses with an error. The fix is dull but important: size your batches by the bytes you expect back, not only by the number of items.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Batch by default, and size each batch by its payload, not by its item count.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Lesson 2: &lt;code&gt;async&lt;/code&gt; does not mean non-blocking
&lt;/h2&gt;

&lt;p&gt;This one surprised me most.&lt;/p&gt;

&lt;p&gt;The network side of an async ADS client is easy: &lt;code&gt;await&lt;/code&gt; the socket and let the event loop do the rest. But once a large response arrives, you have to &lt;em&gt;decode&lt;/em&gt; it: parse thousands of values, map them onto symbol types, and build Python objects. That is pure CPU work, and if it runs in one coroutine without a single &lt;code&gt;await&lt;/code&gt;, it &lt;strong&gt;blocks the entire event loop&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On my desk this was invisible. On a real system, while a big bulk read was being decoded, every other connection in the process stopped. Heartbeats were late, other requests timed out, and the dashboard froze. Nothing crashed, and nothing was logged. The only symptom was latency.&lt;/p&gt;

&lt;p&gt;The first fix is almost embarrassingly small: give control back to the loop between chunks of work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# let everyone else breathe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cleaner long-term design splits the work. The event loop only frames and routes messages, and a pure, side-effect-free codec does the heavy decoding in a thread pool. The loop stays responsive however big the payload is.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; In asyncio, CPU-bound work is a shared resource. Measure loop latency, not only request latency.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Lesson 3: Stop polling, but plan for backpressure
&lt;/h2&gt;

&lt;p&gt;Polling is the habit everyone starts with. ADS offers something better: &lt;strong&gt;notifications&lt;/strong&gt;. You register a variable once, and the PLC pushes new values to you, either cyclically or on change. Less traffic, lower latency, less work for everyone.&lt;/p&gt;

&lt;p&gt;Push-based data raises a question that polling never had to answer: &lt;strong&gt;what happens when your consumer is slower than the PLC?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A notification on a fast-changing variable can produce more values than your callback can handle, especially if that callback writes to a database. Without a plan, memory grows until something gives.&lt;/p&gt;

&lt;p&gt;The pattern that worked for me is a bounded queue per subscription with an explicit overflow policy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Drop oldest.&lt;/strong&gt; Keep the most recent values. A good default for monitoring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drop newest.&lt;/strong&gt; Keep what arrived first and ignore new values until the consumer has caught up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latest only.&lt;/strong&gt; Always deliver just the current value. Ideal for dashboards, where nobody wants to see stale history.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three more details mattered in practice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Let the PLC bundle values.&lt;/strong&gt; A larger &lt;em&gt;max delay&lt;/em&gt; means fewer, bigger frames, which are much cheaper to process than a stream of tiny ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean up after yourself.&lt;/strong&gt; A crashed process can leave notification handles on the PLC that keep firing into the void. The runtime only allows around 1024 of them, so orphans are a real problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resubscribe after reconnects.&lt;/strong&gt; Networks on the shop floor drop. Subscriptions should survive that without the application having to notice.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Push-based data needs a backpressure policy, and you should choose it on purpose.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Lesson 4: The transport is not always TCP
&lt;/h2&gt;

&lt;p&gt;The classic picture is a client opening a TCP connection straight to the controller. More and more installations look different: PLCs behind firewalls, edge gateways, and messages routed through an &lt;strong&gt;MQTT broker&lt;/strong&gt;. TwinCAT supports ADS over MQTT for exactly this case.&lt;/p&gt;

&lt;p&gt;If your protocol code is tied to a TCP socket, supporting that means a rewrite. If the protocol layer only knows "send these bytes, give me those bytes," a new transport is just a small adapter.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Keep the protocol and the transport apart from day one. Your future network diagram will thank you.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Where these lessons ended up
&lt;/h2&gt;

&lt;p&gt;All of this eventually turned into a small open-source library I have been building on the side: &lt;strong&gt;aioads&lt;/strong&gt;, an asyncio-native ADS client for TwinCAT.&lt;/p&gt;

&lt;p&gt;It is my attempt to bake the lessons above into the defaults:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Batched reads, so reading many variables costs one round-trip instead of hundreds&lt;/li&gt;
&lt;li&gt;Symbol and data-type caching, so repeated reads skip the metadata lookup&lt;/li&gt;
&lt;li&gt;Notifications with bounded queues, overflow policies, and automatic resubscription&lt;/li&gt;
&lt;li&gt;Pluggable transports: plain TCP, or ADS over MQTT&lt;/li&gt;
&lt;li&gt;Fully typed, Python 3.12+, and no runtime dependencies for the TCP client&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is roughly what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;aioads&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;AdsClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AmsAddress&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;aioads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ams_service_port&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;AmsServicePort&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AdsClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_tcp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;AmsAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;net_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"192.168.1.100.1.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;dst&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;AmsAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;net_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"192.168.1.200.1.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                       &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;AmsServicePort&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TC3_RUNTIME_1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"192.168.1.200"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_symbols_by_names&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"MAIN.Temperature"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"MAIN.Pressure"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"MAIN.FlowRate"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is still young. Version 0.1.0 has just come out, and the notification API is marked as a preview. If you run TwinCAT systems and write Python, I would really like to hear how it behaves on your hardware, and especially where it falls short.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;pip install aioads&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Source and issues: &lt;a href="https://github.com/MkKiefer/aioads" rel="noopener noreferrer"&gt;github.com/MkKiefer/aioads&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The bigger picture
&lt;/h2&gt;

&lt;p&gt;Industrial software and modern Python have moved forward mostly side by side, without much contact. The tools on the plant floor are reliable but often synchronous and tied to one platform. The Python ecosystem has excellent async tooling but little knowledge of fieldbuses and PLC runtimes.&lt;/p&gt;

&lt;p&gt;The gap is closing, and it is a fun place to work. Whether or not you use my library, the lessons hold: &lt;strong&gt;batch your round-trips, protect your event loop, give push-based data a backpressure policy, and keep your transport replaceable.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your PLC doesn't care about your event loop. Your users will.&lt;/p&gt;

</description>
      <category>python</category>
      <category>asyncio</category>
      <category>plc</category>
    </item>
    <item>
      <title>TrueNAS on Proxmox on the UGREEN DXP4800 GT, with real SATA passthrough</title>
      <dc:creator>MkKiefer</dc:creator>
      <pubDate>Sun, 06 Dec 2026 21:27:49 +0000</pubDate>
      <link>https://dev.to/mkkiefer/truenas-on-proxmox-on-the-ugreen-dxp4800-gt-with-real-sata-passthrough-d93</link>
      <guid>https://dev.to/mkkiefer/truenas-on-proxmox-on-the-ugreen-dxp4800-gt-with-real-sata-passthrough-d93</guid>
      <description>&lt;p&gt;The UGREEN DXP4800 GT is a 4-bay NAS with an AMD Ryzen Embedded R2514, two 10 GbE ports and two SO-DIMM slots for up to 64 GB of DDR4 (ECC supported). That makes it a good small Proxmox host. The usual plan for a box like this is Proxmox on the NVMe drive and TrueNAS as a VM that owns the hard drives.&lt;/p&gt;

&lt;p&gt;The catch: out of the box, the GT's BIOS shows no IOMMU option at all, and without IOMMU you can't pass the SATA controller to a VM. Most guides online cover the Intel models (DXP4800 Plus, DXP2800, DXP8800), where VT-d sits in a normal menu. On the AMD-based GT, the setting is in a hidden menu.&lt;/p&gt;

&lt;p&gt;This post walks through the whole setup, including that menu and a few traps I hit along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hardware
&lt;/h2&gt;

&lt;p&gt;What Proxmox reports on my unit:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Detail&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CPU&lt;/td&gt;
&lt;td&gt;AMD Ryzen Embedded R2514, 4 cores / 8 threads, AMD-V&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RAM&lt;/td&gt;
&lt;td&gt;2 × 16 GB DDR4 SO-DIMM, dual-channel (about 30 GiB usable). Max 64 GB (2 × 32 GB)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boot drive&lt;/td&gt;
&lt;td&gt;NVMe in one of the two M.2 slots (PCIe 3.0 x2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Internal eMMC&lt;/td&gt;
&lt;td&gt;58 GB, holds UGOS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SATA for the 4 bays&lt;/td&gt;
&lt;td&gt;ASMedia ASM1164 (&lt;code&gt;1b21:1164&lt;/code&gt;) at &lt;code&gt;01:00.0&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Network&lt;/td&gt;
&lt;td&gt;2× Aquantia AQC113 10 GbE (&lt;code&gt;atlantic&lt;/code&gt; driver)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BIOS&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DXP4800 GT V1.0 20260429&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The GT ships with a single 8 GB module, which runs single-channel. I upgraded mine to 32 GB (2 × 16 GB) before installing Proxmox. 8 GB is too little for Proxmox plus TrueNAS: TrueNAS alone wants 8 GB or more, and with passthrough its RAM is reserved in full. The RAM slots are behind a small screwed cover on the bottom, next to the M.2 slots.&lt;/p&gt;

&lt;p&gt;There's a second SATA controller (the AMD FCH one, &lt;code&gt;1022:7901&lt;/code&gt;) with nothing attached. The drive bays all hang off the ASM1164, which is exactly what we want to hand to TrueNAS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: BIOS settings
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Enter the BIOS by pressing &lt;code&gt;Ctrl + F2&lt;/code&gt; while the box starts.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the normal BIOS menu, change these first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Advanced → Watchdog Settings → disable everything.&lt;/strong&gt; The hardware watchdog expects UGOS to reset it. Without UGOS, the box can reboot itself every few minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Advanced → Power Settings → Restore on AC power loss → Power On&lt;/strong&gt;, so the host comes back after a power cut.&lt;/li&gt;
&lt;li&gt;Boot order: NVMe first, so it doesn't boot UGOS from the eMMC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The hidden menu with the IOMMU switch
&lt;/h3&gt;

&lt;p&gt;In the normal BIOS mode, &lt;strong&gt;Advanced → CPU Configuration&lt;/strong&gt; only has these options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Turbo Mode&lt;/li&gt;
&lt;li&gt;C-States&lt;/li&gt;
&lt;li&gt;SVM Mode&lt;/li&gt;
&lt;li&gt;PSS Support&lt;/li&gt;
&lt;li&gt;NX Mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's no IOMMU entry. The Chipset tab doesn't have it either;&lt;/p&gt;

&lt;p&gt;The trick: &lt;strong&gt;while you're in the BIOS, press &lt;code&gt;Ctrl + F1&lt;/code&gt;.&lt;/strong&gt; That switches to the extended menu. Now &lt;strong&gt;Advanced → CPU Configuration&lt;/strong&gt; has an &lt;strong&gt;IOMMU&lt;/strong&gt; option. Set it to &lt;strong&gt;Enabled&lt;/strong&gt;, save and exit.&lt;/p&gt;

&lt;p&gt;Without this step, Linux has nothing to work with. You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ls /sys/firmware/acpi/tables/IVRS
ls: cannot access &lt;span class="s1"&gt;'/sys/firmware/acpi/tables/IVRS'&lt;/span&gt;: No such file or directory
$ ls /sys/kernel/iommu_groups &lt;span class="o"&gt;|&lt;/span&gt; wc -l
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No kernel parameter fixes that: &lt;code&gt;amd_iommu=on&lt;/code&gt; doesn't help when the firmware doesn't publish the IVRS table.&lt;/p&gt;

&lt;p&gt;After enabling IOMMU in the extended menu, the same BIOS version gives you this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ dmesg &lt;span class="o"&gt;|&lt;/span&gt; grep -i amd-vi
AMD-Vi: Using global IVHD EFR:0x4f77ef22294ada, EFR2:0x0
pci 0000:00:00.2: AMD-Vi: IOMMU performance counters supported
$ ls /sys/kernel/iommu_groups &lt;span class="o"&gt;|&lt;/span&gt; wc -l
28
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Install Proxmox VE
&lt;/h2&gt;

&lt;p&gt;Install Proxmox on the NVMe drive. &lt;strong&gt;Leave the eMMC alone.&lt;/strong&gt; It holds UGOS, and keeping it is your way back to the stock system.&lt;/p&gt;

&lt;p&gt;Make sure the installer target really is the NVMe and not one of the bay drives. The bay drives sit on the controller you're going to pass through. If Proxmox lives there, passing the controller to a VM pulls the floor out from under the host.&lt;/p&gt;

&lt;p&gt;Once it's installed, check the IOMMU group of the SATA controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;g&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;basename &lt;span class="s2"&gt;"$(readlink -f /sys/bus/pci/devices/0000:01:00.0/iommu_group)"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"ASM1164 is in group $g:"&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; d &lt;span class="k"&gt;in&lt;/span&gt; /sys/kernel/iommu_groups/&lt;span class="nv"&gt;$g&lt;/span&gt;/devices/*&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; lspci -nns &lt;span class="s2"&gt;"${d##*/}"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On my unit the ASM1164 is &lt;strong&gt;alone in its group&lt;/strong&gt;, which is the ideal case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ASM1164 is in group 9:
01:00.0 SATA controller [0106]: ASMedia Technology Inc. ASM1164 Serial ATA AHCI Controller [1b21:1164] (rev 02)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One more safety check: the Proxmox host must never import the ZFS pool that TrueNAS creates. On a stock install with LVM, &lt;code&gt;zfs-import-scan.service&lt;/code&gt; is disabled and there's no &lt;code&gt;/etc/zfs/zpool.cache&lt;/code&gt;, so nothing gets imported. Verify it anyway:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl is-enabled zfs-import-scan.service   &lt;span class="c"&gt;# should say: disabled&lt;/span&gt;
ls /etc/zfs/zpool.cache                         &lt;span class="c"&gt;# should not exist&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Create the TrueNAS VM
&lt;/h2&gt;

&lt;p&gt;Download the TrueNAS ISO and check its SHA-256 against the value on the download page. Then create the VM. Adjust the VM ID, storage names and bridge to your setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm create 102 --name truenas --ostype l26 --machine q35 \
  --bios ovmf --efidisk0 local-lvm:1,efitype=4m,pre-enrolled-keys=0 \
  --cpu host --cores 4 --memory 12288 --balloon 0 \
  --scsihw virtio-scsi-single --scsi0 local-lvm:32,discard=on,ssd=1,iothread=1 \
  --hostpci0 0000:01:00.0,pcie=1 \
  --ide2 local:iso/TrueNAS-SCALE-25.10.8.iso,media=cdrom --boot &lt;span class="s1"&gt;'order=scsi0;ide2'&lt;/span&gt; \
  --net0 virtio,bridge=vmbr0,firewall=0 \
  --vga virtio --onboot 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes on the choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--hostpci0 0000:01:00.0,pcie=1&lt;/code&gt;&lt;/strong&gt; passes the whole ASM1164, so TrueNAS sees the real drives, with SMART. On &lt;code&gt;q35&lt;/code&gt;, &lt;code&gt;pcie=1&lt;/code&gt; presents it as a PCIe device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--balloon 0&lt;/code&gt; with fixed memory.&lt;/strong&gt; PCI passthrough pins all of the VM's RAM anyway, and ZFS doesn't like memory being taken away.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--scsi0&lt;/code&gt; on the NVMe&lt;/strong&gt; is TrueNAS's boot disk. VM disks never go on TrueNAS itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--vga virtio&lt;/code&gt;, not &lt;code&gt;std&lt;/code&gt;.&lt;/strong&gt; This one cost me time. With OVMF (UEFI) and the default &lt;code&gt;std&lt;/code&gt; adapter, the TrueNAS boot menu and installer show nothing but colored noise, in the Proxmox console too. Switching the display to VirtIO-GPU fixed it immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the VM starts, Proxmox moves the controller from the host's &lt;code&gt;ahci&lt;/code&gt; driver to &lt;code&gt;vfio-pci&lt;/code&gt;. The host's &lt;code&gt;lsblk&lt;/code&gt; stops listing the bay drives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ basename &lt;span class="s2"&gt;"$(readlink /sys/bus/pci/devices/0000:01:00.0/driver)"&lt;/span&gt;
vfio-pci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The kernel log shows the controller resetting cleanly when the VM starts (&lt;code&gt;vfio-pci 0000:01:00.0: reset done&lt;/code&gt;). I didn't see the reset hangs that some people report with ASMedia controllers on other UGREEN models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Install TrueNAS
&lt;/h2&gt;

&lt;p&gt;The installer is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install/Upgrade&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pick the 32 GiB QEMU disk only.&lt;/strong&gt; The installer also lists your bay drives, now real WDC/Seagate models thanks to the passthrough. Don't select them.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Administrative user (truenas_admin)&lt;/strong&gt; and set the password right there. I'd avoid "Configure using Web UI": then whoever opens the web UI first sets the password.&lt;/li&gt;
&lt;li&gt;When it reports success, detach the ISO in Proxmox (Hardware → CD/DVD Drive → Do not use any media) and pick &lt;strong&gt;Reboot System&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After the reboot, the console shows the address of the web UI. Set a static address there (menu 1) or later in the web UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Check that TrueNAS really owns the drives
&lt;/h2&gt;

&lt;p&gt;In the TrueNAS shell (console menu 8):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# lspci | grep -i sata
01:00.0 SATA controller: ASMedia Technology Inc. ASM1164 Serial ATA AHCI Controller (rev 02)

# smartctl -i -H /dev/sdb | grep -E 'Device Model|Serial|overall'
Device Model:     WDC WD30EFRX-68EUZN0
Serial Number:    WD-WCC4NAAAAAAA
SMART overall-health self-assessment test result: PASSED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real model names, real serials, working SMART: TrueNAS has the drives. Now create your pool in the web UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;BIOS: &lt;code&gt;Ctrl + F2&lt;/code&gt; to enter, &lt;code&gt;Ctrl + F1&lt;/code&gt; for the extended menu, &lt;strong&gt;Advanced → CPU Configuration → IOMMU → Enabled&lt;/strong&gt;. Also turn off the watchdog.&lt;/li&gt;
&lt;li&gt;Proxmox on the NVMe, eMMC untouched, no ZFS auto-import on the host.&lt;/li&gt;
&lt;li&gt;The ASM1164 at &lt;code&gt;01:00.0&lt;/code&gt; is alone in its IOMMU group. Pass it whole with &lt;code&gt;hostpci0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;TrueNAS VM: &lt;code&gt;q35&lt;/code&gt;, OVMF, &lt;code&gt;--vga virtio&lt;/code&gt;, fixed RAM, boot disk on the NVMe.&lt;/li&gt;
&lt;li&gt;Check SMART inside TrueNAS, then build the pool.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>proxmox</category>
      <category>truenas</category>
      <category>homelab</category>
      <category>selfhosted</category>
    </item>
  </channel>
</rss>
