<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Learning-Diary on Bastien Traverse</title>
    <link>https://bastientraverse.com/en/tags/learning-diary/</link>
    <description>Recent content in Learning-Diary on Bastien Traverse</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sat, 03 Feb 2024 00:00:00 +0100</lastBuildDate><atom:link href="https://bastientraverse.com/en/tags/learning-diary/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Using a container to sidestep a forgotten password in CasaOS</title>
      <link>https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/</link>
      <pubDate>Sat, 03 Feb 2024 00:00:00 +0100</pubDate>
      
      <guid>https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/</guid>
      <description>&lt;h2 id=&#34;problem-statement&#34;&gt;&lt;a href=&#34;#problem-statement&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Problem statement&lt;/h2&gt;&lt;p&gt;As part of dabbling with self-hosting again, I installed &lt;a href=&#34;https://github.com/IceWhaleTech/CasaOS&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CasaOS&lt;/a&gt; on an Oracle Cloud free Ampere instance to try it out.&lt;/p&gt;
&lt;p&gt;After setting it aside for a few weeks, when I logged in via SSH and tried to use &lt;code&gt;sudo&lt;/code&gt; I realized I absolutely couldn&amp;rsquo;t remember my user&amp;rsquo;s password 😅&lt;/p&gt;
&lt;p&gt;The standard operating procedure in this case is to either reboot the machine on a live system and use that to chroot into the local install, or fiddle with GRUB rescue/kernel command line.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;But since I could still install containers through CasaOS web interface, I thought I&amp;rsquo;d use this opportunity to explore ways to recover my sudo access/change my password without rebooting (which could be nice in case it is essential to avoid downtime).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; As I was finishing this post, I realized that the third constraint listed below was incorrect, and as a result a less cumbersome resolution was possible. So read on if you are interested in the learning journey, or jump straight to &lt;a href=&#34;#the-solution-simplified&#34;&gt;the simplified solution&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;the-constraints&#34;&gt;&lt;a href=&#34;#the-constraints&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;The constraints&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;the CLI/SSH access is &amp;ldquo;useless&amp;rdquo;: my user is not setup to interact with the Docker socket without elevated privileges (which is usually a good thing)&lt;/li&gt;
&lt;li&gt;besides its App Store content, CasaOS allows to manually install containers using a Compose file or a &lt;code&gt;docker run&lt;/code&gt; command (which is then &lt;a href=&#34;https://www.composerize.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;composerized&lt;/a&gt;): see &lt;a href=&#34;https://youtu.be/ToV6vRIl3Nk?si=HH9YiQdyqy2LDsva&amp;amp;t=16&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;official video&lt;/a&gt; or &lt;a href=&#34;https://docs.zimaboard.com/docs/Self-Deploying-Applications.html#Follow-these-steps-in-order&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;screenshots&lt;/a&gt; of the process&lt;/li&gt;
&lt;li&gt;&lt;del&gt;its interface however doesn&amp;rsquo;t allow to &lt;code&gt;docker exec&lt;/code&gt; or interact with containers in any other way; the installed containers &lt;em&gt;must&lt;/em&gt; expose a web interface for us to be able to interact with them.&lt;/del&gt; As it turns out, CasaOS interface does &lt;a href=&#34;https://github.com/IceWhaleTech/CasaOS/issues/1316&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;offer access to containers&amp;rsquo; console&lt;/a&gt; (equivalent to a &lt;code&gt;docker exec -it &amp;lt;containe&amp;gt; /bin/sh&lt;/code&gt;), at least for apps installed from its official Store, via the app Settings &amp;gt; &amp;ldquo;Terminal and Logs&amp;rdquo; icon.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class=&#34;center&#34;&gt;&lt;img src=&#34;https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/casa-app-settings-terminal.png&#34;
    alt=&#34;Access to a container shell and logs in CasaOS interface&#34;&gt;&lt;figcaption&gt;
      &lt;h4&gt;Access to a container shell and logs in CasaOS interface&lt;/h4&gt;
    &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&#34;hacking-around&#34;&gt;&lt;a href=&#34;#hacking-around&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Hacking around&lt;/h2&gt;&lt;p&gt;Because I&amp;rsquo;m pretty new to this, my first idea was to start a container which would give me a root shell with access to the docker socket, and then use that environment to start a second privileged container (&lt;a href=&#34;https://www.docker.com/blog/docker-can-now-run-within-docker/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Docker-in-Docker&lt;/a&gt; style) from which I would mount the host filesystem and use &lt;code&gt;{ch,}passwd&lt;/code&gt; or such&amp;hellip; Yes, I felt very smart thinking this up 😅&lt;/p&gt;
&lt;p&gt;Unaware of my mistaken approach, I looked online for a &amp;ldquo;web terminal container&amp;rdquo; and the first result on StartPage was the &lt;a href=&#34;https://github.com/raonigabriel/web-terminal&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;web terminal&lt;/a&gt; GitHub repo, which did what I needed (expose a root shell in the browser) but hadn&amp;rsquo;t been updated since August 2021 😕&lt;/p&gt;
&lt;figure class=&#34;center&#34;&gt;&lt;img src=&#34;https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/sp-results-webterm.png&#34;
    alt=&#34;StartPage results for web terminal container&#34;&gt;
&lt;/figure&gt;
&lt;details class=&#34;admonition note&#34;&gt;&lt;summary class=&#34;admonition-title&#34;&gt;Aside&lt;/summary&gt;
  &lt;p&gt;Docker Hub search is appalling: searching for &lt;code&gt;web terminal&lt;/code&gt; gave me a bunch of &lt;a href=&#34;https://hub.docker.com/search?q=web%20terminal&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;completely unrelated results&lt;/a&gt;. I had to put a dash between the two words &lt;a href=&#34;https://hub.docker.com/search?q=web-terminal&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;to get anywhere&lt;/a&gt;, but then the two first results hadn&amp;rsquo;t been updated in 2 years either&amp;hellip;&lt;/p&gt;
&lt;p&gt;Searching for &lt;code&gt;web shell&lt;/code&gt; and &lt;code&gt;&amp;quot;web shell&amp;quot;&lt;/code&gt; didn&amp;rsquo;t give better results, while &lt;code&gt;web-shell&lt;/code&gt; and &lt;code&gt;webshell&lt;/code&gt; led to very outdated stuff without any description. I can&amp;rsquo;t believe there isn&amp;rsquo;t a reference implementation of this stuff!!&lt;/p&gt;
&lt;p&gt;I also looked up &lt;code&gt;ttyd&lt;/code&gt;, the software used by &lt;code&gt;web-terminal&lt;/code&gt;, and here the first result was fresh from a few days ago; however there was no mention of &lt;em&gt;&amp;ldquo;How to use this with Docker&amp;rdquo;&lt;/em&gt; , so I wasn&amp;rsquo;t sure a simple &lt;code&gt;docker run&lt;/code&gt; would achieve the desired result&amp;hellip; Had I checked its &lt;a href=&#34;https://hub.docker.com/layers/tsl0922/ttyd/alpine/images/sha256-92dd5758ccda91ffc1f113c4c8d8c7407cc236d02c55993dd01d5629fe3a882b?context=explore&amp;amp;tab=vulnerabilities&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Dockerfile&lt;/a&gt;, I would have seen that its &lt;code&gt;ENTRYPOINT&lt;/code&gt;/&lt;code&gt;CMD&lt;/code&gt; was, in fact, starting up the service 🙃&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;Lo and behold, I took the &amp;ldquo;risk&amp;rdquo; (after checking the image&amp;rsquo;s Dockerfile) and entered the following command in CasaOS Docker CLI interface:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;run&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;run&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nl&#34;&gt;sock&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;run&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sock&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;7681&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;7681&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;raonigabriel&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;web&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;nl&#34;&gt;terminal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;latest&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After setting up the access port in CasaOS interface and confirming everything was okay, I clicked &amp;ldquo;Install&amp;rdquo; and connected to my server&amp;rsquo;s port &lt;code&gt;7681&lt;/code&gt; in a browser&amp;hellip; Success, I was in!&lt;/p&gt;
&lt;p&gt;For the next stage of my plan I ran the following command inspired by &lt;a href=&#34;https://security.stackexchange.com/questions/218355/how-to-execute-a-command-directly-on-the-host-system-through-docker-sock-in-a-do&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this StackExchange thread&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;run&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ti&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;privileged&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;net&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pid&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ipc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;volume&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/:/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;busybox&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chroot&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;nl&#34;&gt;sh&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nl&#34;&gt;docker&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;found&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Crap, I didn&amp;rsquo;t even check that the container had docker installed 🤦 You can tell I really don&amp;rsquo;t know what I am doing 😂&lt;/p&gt;
&lt;p&gt;Of course when I subsequently tried to install docker&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;root&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;@&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d0fa4b64c55&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;err&#34;&gt;$&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;apk&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;add&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fetch&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;aarch64&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ERROR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UNTRUSTED&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;signature&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;WARNING&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Ignoring&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;e37b76c2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;No&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;such&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;file&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fetch&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;community&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;aarch64&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ERROR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;community&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UNTRUSTED&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;signature&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;WARNING&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Ignoring&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d022dfc8&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;No&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;such&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;file&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ERROR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;unsatisfiable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;constraints&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;missing&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;required&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;by&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;world&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;root&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;@&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d0fa4b64c55&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;err&#34;&gt;$&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;apk&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;update&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fetch&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;aarch64&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ERROR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;main&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UNTRUSTED&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;signature&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;WARNING&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Ignoring&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;e37b76c2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;No&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;such&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;file&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fetch&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;community&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;aarch64&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ERROR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;https&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;//&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dl&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cdn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpinelinux&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;org&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alpine&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;edge&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;community&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;UNTRUSTED&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;signature&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;WARNING&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Ignoring&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;APKINDEX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d022dfc8&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tar&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;gz&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;No&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;such&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;file&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;errors&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;36&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;distinct&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;packages&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;available&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A quick search seems to indicate that the image is &lt;a href=&#34;https://stackoverflow.com/questions/73374745/error-http-dl-4-alpinelinux-org-alpine-edge-testing-untrusted-signature&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;simply too old&lt;/a&gt;. Building an updated image was out of the scope I had set for this experiment, so I paused and took time to think.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;That&amp;rsquo;s when it occurred to me that this &amp;ldquo;nested container&amp;rdquo; approach was completely useless, and would most likely not work since at that point you have the first container&amp;rsquo;s virtualized filesystem namespace acting as a buffer between the host and the DinD container&amp;hellip; Complete misdirection, backing up!&lt;/p&gt;
&lt;h2 id=&#34;the-solution&#34;&gt;&lt;a href=&#34;#the-solution&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;The solution&lt;/h2&gt;&lt;p&gt;After thinking it through some more, I realized one could achieve the desired outcome by simply mounting the host &lt;code&gt;/&lt;/code&gt; read-write as an attached volume 😁&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;run&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/:/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;7681&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;7681&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;raonigabriel&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;web&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;nl&#34;&gt;terminal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;latest&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;Et voilà&lt;/em&gt;, I finally had a root shell from which I could chroot into the host and update the user password and/or configure password-less sudo (which amounts to the same). Or really, do (nearly) everything to the host system 😨&lt;/p&gt;
&lt;figure class=&#34;center&#34;&gt;&lt;img src=&#34;https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/webterm.png&#34;
    alt=&#34;Root shell provided by the web-terminal container&#34;&gt;&lt;figcaption&gt;
      &lt;h4&gt;Root shell provided by the web-terminal container&lt;/h4&gt;
    &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;blockquote&gt;
&lt;p&gt;Initially I thought it would be necessary to use a &lt;a href=&#34;https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;privileged&lt;/a&gt; container, but trying it showed that wasn&amp;rsquo;t the case. I guess it&amp;rsquo;s because I was only editing files/using regular utilites, and not trying to create new devices/nodes etc.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;the-solution-simplified&#34;&gt;&lt;a href=&#34;#the-solution-simplified&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;The solution: simplified&lt;/h2&gt;&lt;p&gt;This is what happens when you don&amp;rsquo;t know your tools enough&amp;hellip; You miss very obvious pathways that lead to simpler solutions 😁&lt;/p&gt;
&lt;p&gt;Indeed, there is no need to install a third-party container. It is enough to add the &lt;code&gt;/:/host&lt;/code&gt; volume to an existing app installed from CasaOS official App Store (&lt;em&gt;e.g.&lt;/em&gt; NextCloud), and  after making sure in its settings it runs with the root &lt;code&gt;UID&lt;/code&gt;/&lt;code&gt;GID&lt;/code&gt;, we can use the interface to connect the container&amp;rsquo;s console!&lt;/p&gt;
&lt;figure class=&#34;center&#34;&gt;&lt;img src=&#34;https://bastientraverse.com/en/posts/2024-02/casa-password-recovery/casa-nc-root-shell.png&#34;
    alt=&#34;Root shell inside nextcloud container&#34;&gt;&lt;figcaption&gt;
      &lt;h4&gt;Root shell inside nextcloud container&lt;/h4&gt;
    &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;And that is the Easy Way© to get a root shell on your server using containers!&lt;/p&gt;
&lt;h2 id=&#34;trying-to-refine-the-solution&#34;&gt;&lt;a href=&#34;#trying-to-refine-the-solution&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Trying to refine the solution&lt;/h2&gt;&lt;p&gt;Now that I was there, I felt like I should have been able to use a simple &lt;code&gt;busybox&lt;/code&gt; image to execute a command non-interactively directly from &lt;code&gt;docker run&lt;/code&gt;/Compose file, eliminating the need to find an image that exposes a web service or to connect to the container&amp;rsquo;s console.&lt;/p&gt;
&lt;p&gt;After a bit of fiddling, I came up with the following invocation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;docker&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;run&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;etc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;nl&#34;&gt;sudoers&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;etc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sudoers&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;busybox&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sh&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;c&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;echo&lt;/span&gt; &lt;span class=&#34;err&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;%&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sudo&lt;/span&gt;  &lt;span class=&#34;n&#34;&gt;ALL&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ALL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;nl&#34;&gt;NOPASSWD&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ALL&lt;/span&gt;&lt;span class=&#34;err&#34;&gt;&amp;#39;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;host&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;etc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sudoers&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But CasaOS interface constantly threw an error. Probably the redirection in the command, but no amount of quoting led me to a successful run.&lt;/p&gt;
&lt;p&gt;At that point I threw the towel in: I had recovered access to my sudo access and learnt quite a few things along the way. Time to wrap up.&lt;/p&gt;
&lt;h2 id=&#34;takeways&#34;&gt;&lt;a href=&#34;#takeways&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Takeways&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Docker default security story is scary: because the daemon runs as root by default, the mere ability to run containers (even without &lt;code&gt;--privileged&lt;/code&gt;) and mount any desired host path as a volume gives &lt;a href=&#34;https://stackoverflow.com/a/32192369&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;root-equivalent status&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Due to this, access to CasaOS interface is equivalent to root access on the server&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s all folks, thanks for reading this account I hope you enjoyed!&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;See &lt;em&gt;e.g.&lt;/em&gt; &lt;a href=&#34;https://gcore.com/learning/how-to-reset-password-in-linux/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;https://gcore.com/learning/how-to-reset-password-in-linux/&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Offline Arch install with local pacman cache</title>
      <link>https://bastientraverse.com/en/posts/2022-03/arch-offline-cache/</link>
      <pubDate>Sat, 12 Mar 2022 00:00:00 +0100</pubDate>
      
      <guid>https://bastientraverse.com/en/posts/2022-03/arch-offline-cache/</guid>
      <description>&lt;p&gt;While developing my &lt;a href=&#34;https://github.com/neitsab/archvm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Arch VM script&lt;/a&gt;, I had to go through the installation over and over to test every change.&lt;/p&gt;
&lt;p&gt;I am tethered to my phone for Internet connectivity, and the quality and speeds are&amp;hellip; How should I put it? &lt;em&gt;Underwhelming&lt;/em&gt; to say the least (I live in a mountainous rural area).&lt;/p&gt;
&lt;p&gt;So while doing so, I grew increasingly wary of the long wait for packages to download and the &lt;em&gt;287 MB&lt;/em&gt; worth (&lt;em&gt;gah!&lt;/em&gt;) of data it would chip off my 40 GB plan each and every time. What I needed was a way to provide a local package cache to pacman.&lt;/p&gt;
&lt;p&gt;Amazingly, but certainly not surprisingly, &lt;a href=&#34;https://wiki.archlinux.org/title/Offline_installation&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;there is a great article on the Arch wiki&lt;/a&gt; for that.&lt;/p&gt;
&lt;p&gt;However, due to my target file system being exFAT (&lt;em&gt;cough&lt;/em&gt; &lt;a href=&#34;https://bastientraverse.com/en/posts/2022-02/system-imaging/#an-unexpected-obstacle-to-boot-ventoy-shenanigans&#34;&gt;ventoy shenanigans&lt;/a&gt;, &lt;em&gt;cough&lt;/em&gt;) and some file names containing the &lt;a href=&#34;https://averstak.tripod.com/fatdox/names.htm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;forbidden &lt;code&gt;:&lt;/code&gt; character&lt;/a&gt;, this solution didn&amp;rsquo;t work for me.&lt;/p&gt;
&lt;p&gt;Also because I am using GNOME Boxes, &lt;a href=&#34;https://people.gnome.org/~shaunm/help.gnome.org/gnome-boxes/shared-folders.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;sharing a folder&lt;/a&gt; with the host was out of the equation as that entails installing some &lt;a href=&#34;https://www.spice-space.org/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;SPICE&lt;/a&gt;-related packages which pull in an entire graphical stack as dependencies, hence defeating the purpose.&lt;/p&gt;
&lt;p&gt;Setting up SSH access  to the guest requires &lt;a href=&#34;https://unix.stackexchange.com/a/649326&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;quite some fiddling&lt;/a&gt;, and anyway it wasn&amp;rsquo;t immediately clear to me how I would instruct pacstrap to tap into the network cache, or it would have likely required some modifications to the live &lt;code&gt;pacman.conf&lt;/code&gt; and I wanted to avoid all that complexity&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;Remastering the ISO was another option that I left out because I wanted the script to work with a vanilla install. No, what I was really looking for was something of the &lt;em&gt;utmost&lt;/em&gt; simplicity&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;What I finally came up with, and not to toot my own horn but I think it is pretty darn &lt;em&gt;brillant&lt;/em&gt; (considering I haven&amp;rsquo;t seen it mentioned anywhere online when I researched the topic&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;), is a &lt;em&gt;bind mounted squashfs&lt;/em&gt;&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt; package cache placed on an external medium like a USB flash drive. This in turn can easily be shared in GNOME Boxes even without the SPICE packages installed in the guest!&lt;/p&gt;
&lt;p&gt;Here is a rundown of the process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;create a SquashFS archive of &lt;code&gt;/var/cache/pacman/pkg&lt;/code&gt; on a system containing the desired package set (I reused a just-installed VM to match its exact minimal set but you can go wild and copy everything from your main rig, that&amp;rsquo;ll give you a larger cache):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mksquashfs /var/cache/pacman/pkg/ pkg.sqsh &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -comp zstd &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -no-exports &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -progress &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -mem 1G &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -not-reproducible
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;copy the SquashFS file on the external medium you will mount during the install&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;boot into the Arch Live environment and create two directories, one for your external medium and one for the archive:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir /tmp/{usb,squash}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;admonition note&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;
  Do not use &lt;code&gt;/mnt&lt;/code&gt; if you plan to use it as the installation mount point.
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;mount the external medium containing the squash file and then the squash file itself:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mount /dev/XXXY /tmp/usb
mount /tmp/usb/pkg.sqsh /tmp/squash
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;finally, and that&amp;rsquo;s what&amp;rsquo;s doing the trick for pacstrap, &lt;strong&gt;bind&lt;/strong&gt;-mount &lt;code&gt;/tmp/squash&lt;/code&gt; on archiso&amp;rsquo;s &lt;code&gt;/var/cache/pacman/pkg&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mount --bind /tmp/squash /var/cache/pacman/pkg
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s it, now you just have to add &lt;code&gt;-c&lt;/code&gt; to your &lt;a href=&#34;https://man.archlinux.org/man/extra/arch-install-scripts/pacstrap.8.en&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;pacstrap&lt;/a&gt; invocation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pacstrap -c /mnt base linux [...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Downloads will be skipped (as long as package versions in the squashfs archive are not older than the synced databases&amp;rsquo; ones), and now you can carry on with your installation, contented by the blissful release of not having to suffer through the hell of this perpetual cycle of reincar&amp;hellip; Err I mean wasteful downloading of already acquired packages 😊️&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://stallman.org/articles/happy-hacking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Happy hacking&lt;/a&gt;!&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Just as I was bringing the finishing touches to this article, I realized my blunder: what I needed was an access &lt;em&gt;from&lt;/em&gt; the guest to the host, not the contrary. This would allow me to do something like an &lt;a href=&#34;https://wiki.archlinux.org/title/Pacman/Tips_and_tricks#Read-write_cache&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;SSHFS&lt;/a&gt; mount or even &lt;a href=&#34;https://wiki.archlinux.org/title/Pacman/Tips_and_tricks#Read-only_cache&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;serving the cache via a simple web server&lt;/a&gt;. Follow-up article to come on how &lt;em&gt;easy&lt;/em&gt; it actually is to connect from a guest to the host in GNOME Boxes 😁️&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Yeah, no seriously, in my use case that was the web server/SSHFS mount. But let&amp;rsquo;s just say this article was &lt;em&gt;actually&lt;/em&gt; meant to be for a fully offline install&amp;hellip; 😂️&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;I&amp;rsquo;ll admit this may only be due to my constraints being ridiculously specific, but maybe for once I can dream of having come up with a truly original solution, wouldn&amp;rsquo;t you agree ? 😀️&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;The idea of using &lt;a href=&#34;https://tldp.org/HOWTO/SquashFS-HOWTO/whatis.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;SquashFS&lt;/a&gt; instead of a more common loop-mounted filesystem-in-a-file is what I felt was the real feat of ingeniosity here. And yes, I need to pat myself on the back from time to time, is it something wrong? 😉️&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Ejecting and reattaching a USB drive from the CLI</title>
      <link>https://bastientraverse.com/en/posts/2022-02/cli-eject/</link>
      <pubDate>Thu, 24 Feb 2022 00:00:00 +0100</pubDate>
      
      <guid>https://bastientraverse.com/en/posts/2022-02/cli-eject/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;: I was booted on &lt;code&gt;archlinux-2022.02.01-x86_64.iso&lt;/code&gt; using a multiboot USB flash drive made with &lt;a href=&#34;https://www.ventoy.net/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ventoy&lt;/a&gt;  &lt;code&gt;1.0.65&lt;/code&gt;, and had selected the &amp;ldquo;Copy to RAM&amp;rdquo; option in the ISO menu with the idea of reusing the drive as a backup destination for a &lt;a href=&#34;https://bastientraverse.com/en/posts/2022-02/system-imaging/&#34;&gt;system backup&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The issue&lt;/strong&gt;: I was unable to normally eject the drive, both &lt;code&gt;eject&lt;/code&gt; and &lt;code&gt;udisksctl power-off&lt;/code&gt; (after installing &lt;code&gt;udisks2&lt;/code&gt;) gave the error &lt;code&gt;Device or resource busy&lt;/code&gt;, and &lt;a href=&#34;https://stackoverflow.com/questions/624154/linux-which-process-is-causing-device-busy-when-doing-umount&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;lsof | grep -e ventoy -e sdb&lt;/a&gt; didn&amp;rsquo;t return anything. Here is what it looked like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0           7:0    0 657.4M  1 loop /run/archiso/airootfs
sda             8:0    0 111.8G  0 disk
├─sda1          8:1    0     1G  0 part
│ └─boot-arch 254:1    0   252M  0 lvm  
└─sda2          8:2    0   100G  0 part
sdb             8:16   0  59.6G  0 disk
├─sdb1          8:17   0  59.6G  0 part
│ └─ventoy    254:0    0 812.3M  1 dm    &amp;lt;-- problematic entry
└─sdb2          8:18   0    32M  0 part
sr0            11:0    1  1024M  0 rom

root@archiso ~ # eject -v /dev/sdb
eject: device name is `/dev/sdb&#39;
eject: /dev/sdb: not mounted
eject: /dev/sdb: is whole-disk device
eject: cannot open /dev/sdb: Device or resource busy

root@archiso ~ # eject -v /dev/mapper/ventoy
eject: device name is `/dev/mapper/ventoy&#39;
eject: /dev/mapper/ventoy: not mounted
eject: /dev/mapper/ventoy: is whole-disk device
eject: /dev/mapper/ventoy: is not hot-pluggable device

root@archiso ~ # ls -l /dev/mapper/ventoy  
lrwxrwxrwx 1 root root 7 Feb 24 20:24 /dev/mapper/ventoy -&amp;gt; ../dm-0

root@archiso ~ # ls -l /dev/dm-0
brw-rw---- 1 root disk 254, 0 Feb 24 20:24 /dev/dm-0

root@archiso ~ # cat /sys/class/block/dm-0/dm/name
ventoy
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, I wasn&amp;rsquo;t sure what was causing the issue, and I didn&amp;rsquo;t want to simply pull the drive out as it equates to playing Russian roulette with your devices (do you like getting the rug pulled under you or being knocked inconscious by a stealthy sucker punch? Well, neither do most filesystems).&lt;/p&gt;
&lt;p&gt;At first I had worked around the issue by using &lt;a href=&#34;https://unix.stackexchange.com/a/384075&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this trick&lt;/a&gt; :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;echo offline &amp;gt; /sys/block/sdb/device/state
echo 1 &amp;gt; /sys/block/sdb/device/delete
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See &lt;a href=&#34;https://bbs.archlinux.org/viewtopic.php?pid=1914290#p1914290&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this post&lt;/a&gt; on the Arch forums for a more thorough procedure along the same vein.&lt;/p&gt;
&lt;p&gt;Still, I wasn&amp;rsquo;t entirely convinced: it didn&amp;rsquo;t address the root cause of the issue.&lt;/p&gt;
&lt;p&gt;Digging &lt;a href=&#34;https://superuser.com/a/131520&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;a little&lt;/a&gt; &lt;a href=&#34;https://unix.stackexchange.com/a/351361&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;deeper&lt;/a&gt; led me to &lt;code&gt;dmsetup&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # dmsetup table
boot-arch: 0 516096 linear 8:1 2048
ventoy: 0 1663640 linear 8:17 59447552

root@archiso ~ # dmsetup info /dev/mapper/ventoy  
Name:              ventoy
State:             ACTIVE (READ-ONLY)
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      254, 0
Number of targets: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Well, that &lt;code&gt;READ-ONLY&lt;/code&gt; state was already good news, but checking dmsetup &lt;a href=&#34;https://man.archlinux.org/man/core/device-mapper/dmsetup.8.en&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;manpage&lt;/a&gt; I saw it offered a &lt;code&gt;remove&lt;/code&gt; command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # dmsetup remove ventoy
root@archiso ~ # lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0           7:0    0 657.4M  1 loop /run/archiso/airootfs
sda             8:0    0 111.8G  0 disk
├─sda1          8:1    0     1G  0 part
│ └─boot-arch 254:1    0   252M  0 lvm  
└─sda2          8:2    0   100G  0 part
sdb             8:16   0  59.6G  0 disk
├─sdb1          8:17   0  59.6G  0 part
└─sdb2          8:18   0    32M  0 part
sr0            11:0    1  1024M  0 rom  
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Victory, the mapping is gone! And now&amp;hellip;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # eject /dev/sdb -v
eject: device name is `/dev/sdb&#39;
eject: /dev/sdb: not mounted
eject: /dev/sdb: is whole-disk device
eject: /dev/sdb: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sdb: trying to eject using SCSI commands
eject: SCSI eject succeeded

root@archiso ~ # lsblk  
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0           7:0    0 657.4M  1 loop /run/archiso/airootfs
sda             8:0    0 111.8G  0 disk
├─sda1          8:1    0     1G  0 part
│ └─boot-arch 254:1    0   252M  0 lvm  
└─sda2          8:2    0   100G  0 part
sdb             8:16   0  59.6G  0 disk
sr0            11:0    1  1024M  0 rom  
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Success! I saw the LED on my thumb drive flash quickly, and then it fell silent. But wait, what is all this red in my logs?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;archiso kernel: sd 6:0:0:0: [sdb] Media removed, stopped polling
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: ldm_validate_partition_table(): Disk read failed.
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel:  sdb: unable to read partition table
archiso kernel: sd 6:0:0:0: [sdb] Media removed, stopped polling
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: ldm_validate_partition_table(): Disk read failed.
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: I/O error, dev sdb, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
archiso kernel: Buffer I/O error on dev sdb, logical block 0, async page read
archiso kernel:  sdb: unable to read partition table
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
archiso kernel: sd 6:0:0:0: [sdb] tag#0 device offline or changed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hum, looks like &lt;code&gt;eject&lt;/code&gt; is doing something kind of dirty&amp;hellip; Let&amp;rsquo;s move ahead for now, we&amp;rsquo;ll come back to it later.&lt;/p&gt;
&lt;p&gt;Now, since this is a laptop laying on my desk, I certainly can manually unplug the drive before plugging it back again to make it available. But what if I am lazy, or the machine is faraway, or I just want to take extra care of that super frail USB plug and prevent a superfluous actuation cycle?&lt;/p&gt;
&lt;h2 id=&#34;reattaching-an-ejected-usb-device-from-the-cli&#34;&gt;&lt;a href=&#34;#reattaching-an-ejected-usb-device-from-the-cli&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Reattaching an ejected USB device from the CLI&lt;/h2&gt;&lt;p&gt;Here we are going to make use of the ability &lt;a href=&#34;https://lwn.net/Articles/143397/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;to bind and unbind drivers from devices manually from user space&lt;/a&gt;. First, get the drive Bus number:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # lsusb  
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 003: ID 0781:5580 SanDisk Corp. SDCZ80 Flash Drive  &amp;lt;-- here is my device
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then Port for &amp;ldquo;Bus 4 Device 3&amp;rdquo;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # lsusb -t  
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 1: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 5000M  &amp;lt;-- spot it?
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that I know that my USB device is identified as &lt;code&gt;4-1&lt;/code&gt; (bus-port) (this can be confirmed by checking &lt;code&gt;dmesg | grep usb-storage&lt;/code&gt;), we can make it go through an unbinding/binding cycle:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # echo &amp;quot;4-1&amp;quot; &amp;gt; /sys/bus/usb/drivers/usb/unbind
root@archiso ~ # lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0           7:0    0 657.4M  1 loop /run/archiso/airootfs
sda             8:0    0 111.8G  0 disk
├─sda1          8:1    0     1G  0 part
│ └─boot-arch 254:1    0   252M  0 lvm  
└─sda2          8:2    0   100G  0 part
sr0            11:0    1  1024M  0 rom  
root@archiso ~ # echo &amp;quot;4-1&amp;quot; &amp;gt; /sys/bus/usb/drivers/usb/bind  
root@archiso ~ # lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0           7:0    0 657.4M  1 loop /run/archiso/airootfs
sda             8:0    0 111.8G  0 disk
├─sda1          8:1    0     1G  0 part
│ └─boot-arch 254:1    0   252M  0 lvm  
└─sda2          8:2    0   100G  0 part
sdb             8:16   0  59.6G  0 disk
├─sdb1          8:17   0  59.6G  0 part
└─sdb2          8:18   0    32M  0 part
sr0            11:0    1  1024M  0 rom
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Et voilà, the flash drive is once again available for &lt;code&gt;mount&lt;/code&gt; without having to physically remove it!&lt;/p&gt;
&lt;div class=&#34;admonition note&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;
  Trying to &lt;code&gt;bind&lt;/code&gt; directly after  &lt;code&gt;eject&lt;/code&gt; without &lt;code&gt;unbind&lt;/code&gt; leads to a &lt;code&gt;write error: device or resource busy&lt;/code&gt; . So now I am really left wondering what &lt;code&gt;eject&lt;/code&gt; is doing to my drive&amp;hellip;
&lt;/div&gt;
&lt;p&gt;An alternative to manually writing to &lt;code&gt;/sys/bus/usb/drivers/usb/&lt;/code&gt; is to use &lt;a href=&#34;https://www.draisberghof.de/usb_modeswitch/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;usb_modeswitch&lt;/a&gt; (included on the Arch installation media). In that case we only need the ID pair from &lt;code&gt;lsusb&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # lsusb  
...
Bus 004 Device 003: ID 0781:5580 SanDisk Corp. SDCZ80 Flash Drive
                       ==== ==== ------ ---------
                                      |         |
root@archiso ~ # usb_modeswitch -v 0x0781 -p 0x5580 --reset-usb
Look for default devices ...
 Found devices in default mode (1)
Access device 003 on bus 004
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 8
Warning: no switching method given. See documentation
Reset USB device .
 Device was reset
-&amp;gt; Run lsusb to note any changes. Bye!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Props to &lt;a href=&#34;https://askubuntu.com/a/859492&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this&lt;/a&gt; AskUbuntu answer, confirmed and extended via &lt;a href=&#34;https://stackoverflow.com/questions/18765725/turning-off-a-single-usb-device-again&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this&lt;/a&gt; Stackoverflow one.&lt;/p&gt;
&lt;h2 id=&#34;wrap-up&#34;&gt;&lt;a href=&#34;#wrap-up&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Wrap up&lt;/h2&gt;&lt;p&gt;After a few trial and errors, I realized &lt;code&gt;eject&lt;/code&gt;ing the drive was entirely unnecessary: I could get away with just &lt;code&gt;dmsetup remove ventoy&lt;/code&gt; and an &lt;code&gt;unbind&lt;/code&gt;/&lt;code&gt;bind&lt;/code&gt; cycle.&lt;/p&gt;
&lt;p&gt;Now if you ever have to &lt;em&gt;cleanly&lt;/em&gt; power-off a device on the command line, here is the &lt;strong&gt;ultimate&lt;/strong&gt; method:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;% udisksctl power-off -h
Utilisation :
  udisksctl power-off [OPTION…]

Safely power off a drive.

Options :
  -p, --object-path         Object path for ATA device
  -b, --block-device        Device file for ATA device
  --no-user-interaction     Do not authenticate the user if needed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;E.g.&lt;/em&gt; &lt;code&gt;udisksctl power-off -b /dev/sdb&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For the life of me I don&amp;rsquo;t know why this utility isn&amp;rsquo;t included by default on the arch installation media, but in any case you are just one &lt;code&gt;pacman -S udisks2&lt;/code&gt; away from safely-removed device &lt;em&gt;nibbana&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s all folks for today&amp;rsquo;s learning diary. Thanks for reading and take care of your devices!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>A system imaging tale: LUKS, Clonezilla and friends</title>
      <link>https://bastientraverse.com/en/posts/2022-02/system-imaging/</link>
      <pubDate>Mon, 14 Feb 2022 00:00:00 +0100</pubDate>
      
      <guid>https://bastientraverse.com/en/posts/2022-02/system-imaging/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Today&amp;rsquo;s project:&lt;/strong&gt; make a system image of my previous laptop for archival purposes before refurbishing it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conditions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;make a space efficient image, &lt;em&gt;i.e.&lt;/em&gt; not a block-level copy: no need to retain encryption or logical volume setup, only their content matters. However:&lt;/li&gt;
&lt;li&gt;all standard and extended file attributes must be correctly preserved, so that if I ever want to boot this image the system will be in a correct state.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The plan:&lt;/strong&gt; boot up an Arch ISO, open the encrypted drives, set everything up for &lt;a href=&#34;https://clonezilla.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;clonezilla&lt;/a&gt; &amp;ndash; profit.&lt;/p&gt;
&lt;p&gt;Here is how it actually went.&lt;/p&gt;
&lt;h2 id=&#34;an-unexpected-obstacle-to-boot-ventoy-shenanigans&#34;&gt;&lt;a href=&#34;#an-unexpected-obstacle-to-boot-ventoy-shenanigans&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;An unexpected obstacle to boot: Ventoy shenanigans&lt;/h2&gt;&lt;p&gt;In order to boot into the Arch live environment, I unsheathed my very dear and trusted Sandisk Extreme multiboot USB thumb drive (not the currently sold, lower performing one but the &lt;a href=&#34;https://usb.userbenchmark.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ever chart-topping&lt;/a&gt; one from about 10 years ago), which had been irreproachably and impeccably fulfilling its duty in the two years since I had discovered &lt;a href=&#34;https://www.ventoy.net/en/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ventoy&lt;/a&gt;, the multiboot solution which surpassed them all and ended my long standing quest to find an easy to use, low-maintenance and low-friction multiboot USB solution. And yes, this was the longest sentence of the entire article 😁&lt;/p&gt;
&lt;p&gt;Just recently I had updated it to the latest version using the provided Linux script, which completed without issue. But as soon as I booted on it, I was faced with an error: &lt;code&gt;Warning! This is not a standard device and is not officially supported&lt;/code&gt;. Um, beg your pardon? It was working fine those past two years, so certainly it was the update which broke something&amp;hellip;&lt;/p&gt;
&lt;p&gt;Searching for this error, I eventually &lt;a href=&#34;https://github.com/ventoy/Ventoy/commit/8bbd5a14a3ca4820266bed6afc1314c3f41e76c3&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;found this &amp;ldquo;kill switch&amp;rdquo;&lt;/a&gt; the dev introduced slightly after I used the software, to try and contain the flood of users with non-standard installs complaining to them when something got wrong.&lt;/p&gt;
&lt;p&gt;I can&amp;rsquo;t really fault them for that, but here is the thing: mine was a pure product of the official tool from back in 2020, with no deviation from the &lt;a href=&#34;https://www.ventoy.net/en/doc_disk_layout.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;prescribed layout/FS&lt;/a&gt; whatsoever. The first partition was starting at the 2048/1 MB boundary and formatted with the default exFAT, the second partition was 65536 sector large, the drive had an MBR partition table and all and all&amp;hellip;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# fdisk -l /dev/sda
Disk /dev/sda: 59.63 GiB, 64023257088 bytes, 125045424 sectors
Disk model: Extreme  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd1a119ab

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 124979887 124977840 59.6G  7 HPFS/NTFS/exFAT
/dev/sda2       124979888 125045423     65536   32M ef EFI (FAT-12/16/32)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The official command line tool didn&amp;rsquo;t complain either while upgrading or when run manually:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ventoy -l /dev/sda

**********************************************
      Ventoy: 1.0.65  x86_64
      longpanda admin@ventoy.net
      https://www.ventoy.net
**********************************************

Ventoy Version in Disk: 1.0.65
Disk Partition Style  : MBR
Secure Boot Support   : NO
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Indeed but nope, I got axed by the kill switch all the same. Fuck artificial restrictions and &lt;a href=&#34;https://www.gnu.org/philosophy/can-you-trust.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;treacherous computing&lt;/a&gt;. And I am burned by a free software project at that&amp;hellip; What to expect from this world.&lt;/p&gt;
&lt;p&gt;Anyhoo, after transfering out my 24 GB of GNU/Linux ISOs (God bless USB 3.0 &amp;amp; &lt;em&gt;quality&lt;/em&gt; flash memory speeds), I forced a reinstall with the &lt;code&gt;-I&lt;/code&gt; switch:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ventoy -I /dev/sda

**********************************************
      Ventoy: 1.0.65  x86_64
      longpanda admin@ventoy.net
      https://www.ventoy.net
**********************************************

Disk : /dev/sda
Size : 59 GB
Style: MBR


Attention:
You will install Ventoy to /dev/sda.
All the data on the disk /dev/sda will be lost!!!

Continue? (y/n) y

All the data on the disk /dev/sda will be lost!!!
Double-check. Continue? (y/n) y

Create partitions on /dev/sda by parted in MBR style ...
Done
Wait for partitions ...
partition exist OK
create efi fat fs /dev/sda2 ...
mkfs.fat 4.2 (2021-01-31)
success
Wait for partitions ...
/dev/sda1 exist OK
/dev/sda2 exist OK
partition exist OK
Format partition 1 /dev/sda1 ...
mkexfatfs 1.3.0
Creating... done.
Flushing... done.
File system created successfully.
mkexfatfs success
writing data to disk ...
sync data ...
esp partition processing ...
Open ventoy efi file 0x610ac0
ventoy x64 efi file size 1757184 ...
Open bootx64 efi file 0x610ac0
Open ventoy ia32 efi file 0x610f10
ventoy efi file size 1183744 ...
Open bootia32 efi file 0x610ac0

Install Ventoy to /dev/sda successfully finished.

sudo ventoy -I /dev/sda  5,11s user 2,58s system 19% cpu 39,813 total
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After transferring my files back and rebooting on the flash drive, everything was back in order and I was ready to rock 🤟&lt;/p&gt;
&lt;h2 id=&#34;optional-step-setting-up-a-comfortable-environment&#34;&gt;&lt;a href=&#34;#optional-step-setting-up-a-comfortable-environment&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Optional step: setting up a comfortable environment&lt;/h2&gt;&lt;p&gt;Being console-based, the archiso environment is somewhat austere. So the first thing I usually do is to set up SSH access so as to connect from my main machine:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# set french keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# the &amp;#34;-latin9&amp;#34; part is only needed if using e.g. accents&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;loadkeys fr-latin9
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# directly connect to a known Wifi SSID&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;iwctl station wlan0 connect &amp;lt;SSID&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Enable NTP to have accurate time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;timedatectl set-timezone &amp;lt;Area/City&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;timedatectl set-ntp &lt;span class=&#34;nb&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# set root passhrase to enable SSH connection&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;passwd
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# start SSH service&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;systemctl start sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# get IP address&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;iwctl station wlan0 show &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep IP &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{print $3}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# or without iwd:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ip a &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep wlan &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;FNR == 2 {print substr($2, 1, length($2)-3)}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, connect to the live environment via SSH:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ssh -o &lt;span class=&#34;nv&#34;&gt;PreferredAuthentications&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;password &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -o &lt;span class=&#34;nv&#34;&gt;PubkeyAuthentication&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;no &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -o &lt;span class=&#34;nv&#34;&gt;UserKnownHostsFile&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;/dev/null &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    root@&amp;lt;other-machine-IP&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;admonition tip&#34;&gt;
  👉️ The options used allow not to be affected by the local SSH configuration (SSH keys&amp;hellip;), as well as well not polluting the local KnownHosts file with this one-time connection.
&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s it, now we can resume with the common procedure!&lt;/p&gt;
&lt;h2 id=&#34;clonezilla-and-lukslvm&#34;&gt;&lt;a href=&#34;#clonezilla-and-lukslvm&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Clonezilla and LUKS/LVM&lt;/h2&gt;&lt;p&gt;In order to &lt;em&gt;efficiently&lt;/em&gt; image the system, we first need to open any LUKS container and make sure all the LVs are displayed correctly:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cryptsetup open --allow-discards /dev/sdb2 os
lvs
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we create the &lt;code&gt;/home/partimag&lt;/code&gt; directory (hardcoded backup destination in Clonezilla) and mount our drive on it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir /home/partimag
mount -o noatime /dev/sdc1 !$
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition info&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;
  &lt;p&gt;When booting the archiso, I selected the &amp;ldquo;Copy to RAM&amp;rdquo; option so as to free up the drive and reuse it as backup destination.&lt;/p&gt;
&lt;p&gt;However, in order to do that I first needed to get rid of a lingering &lt;code&gt;/dev/mapper/ventoy&lt;/code&gt;  mapping on its first partition, which made &lt;code&gt;eject&lt;/code&gt;/&lt;code&gt;udisksctl&lt;/code&gt; throw errors despite the fact that it wasn&amp;rsquo;t mounted and &lt;code&gt;lsof | grep -e ventoy -e sdb&lt;/code&gt; didn&amp;rsquo;t return anything. I didn&amp;rsquo;t want to pull it out on the off chance it&amp;rsquo;d corrupt something&amp;hellip;&lt;/p&gt;
&lt;p&gt;I wrote a &lt;a href=&#34;https://bastientraverse.com/en/posts/2022-02/cli-eject/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;separate post&lt;/a&gt; which goes into the details, but the gist is a simple &lt;code&gt;dmsetup remove ventoy&lt;/code&gt; took care of the mapping, and then I was able to normally mount the drive.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;And now it is &lt;em&gt;&lt;strong&gt;on!&lt;/strong&gt;&lt;/em&gt; Launch &lt;code&gt;clonezilla&lt;/code&gt; from the command line and follow the on-screen instructions depending on your needs. Some personal recommendations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use expert mode&lt;/li&gt;
&lt;li&gt;avoid the 4G backup splitting by entering a large number when prompted (like 100000)&lt;/li&gt;
&lt;li&gt;select &amp;ldquo;parallel zstd&amp;rdquo; (&lt;code&gt;-z9p&lt;/code&gt;) as the compression algorithm&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Or if you feel like keeping it CLI-only&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/usr/bin/ocs-sr &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --use-partclone &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --confirm &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --clone-hidden-data &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --zstdmt-compress
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    --image-size &lt;span class=&#34;m&#34;&gt;1000000&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --fsck-src-part &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --skip-enc-ocs-img &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --postaction choose &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    saveparts &amp;lt;backup-name&amp;gt; sdb1 sdb2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is the long form equivalent of the&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/usr/bin/ocs-sr -q2 -c -j2 -z9p -i 1000000 -fsck -senc -p choose saveparts &amp;lt;backup-name&amp;gt; sdb1 sdb
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that got copied in a file under &lt;code&gt;/tmp&lt;/code&gt; after validating my options in the TUI.&lt;/p&gt;
&lt;p&gt;Then we just sit back and relax&amp;hellip; Wait, what? &lt;code&gt;dd mode&lt;/code&gt;? Why aren&amp;rsquo;t my OS logical volumes backed up by the regular free space-aware &lt;code&gt;partclone&lt;/code&gt; mode? I explicitly decrypted the containers for that purpose, and saw the LVs being listed during the preparation screens! Although it&amp;rsquo;s true I could only select whole partitions to be backed up and not specific logical volumes, and saw a line flash by saying something like &lt;code&gt;Shutting down the Volume manager&lt;/code&gt;&amp;hellip; Oh come on.&lt;/p&gt;
&lt;p&gt;One &lt;kbd&gt;Ctrl&lt;/kbd&gt;+&lt;kbd&gt;c&lt;/kbd&gt; later the backup of &lt;code&gt;/dev/sdb2&lt;/code&gt; was cancelled, but the unencrypted &lt;code&gt;/dev/sdb1&lt;/code&gt; with the &lt;code&gt;arch&lt;/code&gt; LV (the only one in the &lt;code&gt;boot&lt;/code&gt; VG) proceeded without issue. What the heck clonezilla?&lt;/p&gt;
&lt;p&gt;Hum alright, according to &lt;a href=&#34;https://sourceforge.net/p/clonezilla/discussion/Help/thread/770897b4/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this 2014 thread&lt;/a&gt; with the developer&amp;rsquo;s input, it seems this isn&amp;rsquo;t as straightforward as it looks. And it happened even &lt;a href=&#34;https://sourceforge.net/p/clonezilla/mailman/clonezilla-live/thread/MY6SeQk--3-2%40tuta.io/#msg37260650&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;much more recently&lt;/a&gt; to another user (although according to the dev&amp;rsquo;s answer it shouldn&amp;rsquo;t be the case), so anyway&amp;hellip; Time for some manual &lt;a href=&#34;https://partclone.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;partclone&lt;/a&gt; fun I guess!&lt;/p&gt;
&lt;h2 id=&#34;system-imaging-the-manual-way&#34;&gt;&lt;a href=&#34;#system-imaging-the-manual-way&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;System imaging, the manual way&lt;/h2&gt;&lt;p&gt;Full disclosure: I had already stumbled upon the &amp;ldquo;&lt;em&gt;manual partclone required&lt;/em&gt;&amp;rdquo; caveat when trying to efficiently backup LUKS-encrypted systems with Clonezilla, so I wasn&amp;rsquo;t really at a loss. All in all it&amp;rsquo;s pretty simple, you just have to use &lt;em&gt;partclone&lt;/em&gt; like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;partclone.$fstype --clone --source ... --output ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wich gave in my case:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;partclone.ext4 --clone --source /dev/mapper/arch-root --output &amp;lt;backup path&amp;gt;/$(date -I)-old-laptop-archroot.ext4-ptcl.img
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition tip&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Tip&lt;/p&gt;
  If you want to have the same nice ncurses-based UI as Clonezilla does, add the &lt;code&gt;-N/--ncurses&lt;/code&gt; option (&lt;a href=&#34;https://linuxconfig.org/how-to-use-partclone-to-create-a-smart-partition-backup&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;example&lt;/a&gt;).
&lt;/div&gt;
&lt;p&gt;Though if we really want to mimick Clonezilla and have space-efficient backups, we gotta add compression to the mix!&lt;/p&gt;
&lt;h3 id=&#34;compressing-partclone-images-with-zstd&#34;&gt;&lt;a href=&#34;#compressing-partclone-images-with-zstd&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Compressing partclone images with zstd&lt;/h3&gt;&lt;p&gt;Being a devout &lt;a href=&#34;https://facebook.github.io/zstd/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Zstandard&lt;/a&gt; Zealot© (&lt;a href=&#34;https://gregoryszorc.com/blog/2017/03/07/better-compression-with-zstandard/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this post&lt;/a&gt; summarizes well my feelings &amp;ndash; no affiliation with the author), here is how to interface it with partclone for a nicely multi-threaded compression:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;partclone.ext4 --clone --source /dev/mapper/arch-root | zstdmt -o &amp;lt;backup path&amp;gt;/$(date -I)-old-laptop-archroot.ext4-ptcl-img.zst
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition info&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Info&lt;/p&gt;
  From &lt;a href=&#34;https://man.archlinux.org/man/zstd.1#SYNOPSIS&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;zstd man page&lt;/a&gt;: &lt;code&gt;zstdmt&lt;/code&gt; is equivalent to &lt;code&gt;zstd -T0&lt;/code&gt;, enabling auto-adjusted multi-threading.
&lt;/div&gt;
&lt;p&gt;If you are like me and have several LVs to clone and their names follow a pattern, you can use a for loop to optimize things a bit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for i in arch-{root,home,opt,var} boot-arch; do partclone.ext4 --clone --source /dev/mapper/&amp;quot;${i}&amp;quot; | zstdmt -o &amp;lt;backup path&amp;gt;/$(date -I)-&amp;quot;${i}&amp;quot;.ext4-ptcl-img.zst; done
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Et voilà&lt;/em&gt;, space-efficient compressed images of your decrypted LVs!&lt;/p&gt;
&lt;div class=&#34;admonition tip&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Tip&lt;/p&gt;
  Someone made a &lt;a href=&#34;https://gist.github.com/andyrbell/4a339c0d8a3bc9465743a6b876671dcb&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;gist&lt;/a&gt; using somewhat older commands and touching upon restoration etc&amp;hellip; Give it a look if you want to review the process!
&lt;/div&gt;
&lt;h2 id=&#34;extra-comparing-the-process-with-different-tools&#34;&gt;&lt;a href=&#34;#extra-comparing-the-process-with-different-tools&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Extra: comparing the process with different tools&lt;/h2&gt;&lt;p&gt;A very precious thing in this world is diversity. Of people, ideas, food&amp;hellip; And backup tools. Here is a rundown of the same task undertaken with four of them:&lt;/p&gt;
&lt;h3 id=&#34;fsarchiver&#34;&gt;&lt;a href=&#34;#fsarchiver&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;FSArchiver&lt;/h3&gt;&lt;p&gt;The first time I realized I couldn&amp;rsquo;t use Clonezilla to properly back up my decrypted LVs, I stumbled upon a great alternative to partclone: &lt;a href=&#34;https://www.fsarchiver.org/compression/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;FSArchiver&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The main reason for using it over the former? FSArchiver:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;directly integrates &lt;a href=&#34;http://www.fsarchiver.org/internal-multithreading/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;multi-threaded&lt;/a&gt; compression with zstd (and &lt;a href=&#34;https://www.fsarchiver.org/compression/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;recommends it over any others&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;allows to specify multiple filesystems to be archived at once&lt;/li&gt;
&lt;li&gt;also works with directories (creating a compressed and checksummed tarball of sorts)&lt;/li&gt;
&lt;li&gt;allows to restore to a different filesystem and creating it in one go&lt;/li&gt;
&lt;li&gt;allows to restore to a smaller partition by default, whereas partclone needs the &lt;code&gt;-C&lt;/code&gt; option (and often just ends on a seek error)&lt;/li&gt;
&lt;li&gt;accepts exclusion patterns to filter what&amp;rsquo;s archived/restored (&lt;a href=&#34;https://github.com/fdupoux/fsarchiver/issues/98#issuecomment-1050415780&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;the syntax is a bit tricky though&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;offers to optionally encrypt data in the archive&lt;/li&gt;
&lt;li&gt;and is generally really careful with data integrity&amp;hellip; If that wasn&amp;rsquo;t already reason enough 😉&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Its multi-threaded compression-ready invocation goes something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;fsarchiver --zstd=3 --jobs=$(nproc) savefs &amp;lt;backup path&amp;gt;/&amp;lt;archive-name&amp;gt;.fsa &amp;lt;list of devices to backup&amp;gt; --exclude=&amp;lt;exclude pattern&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--zstd=3&lt;/code&gt; stands for zstd-compression at level 3&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--jobs=$(nproc)&lt;/code&gt; works exactly like the eponymous &lt;code&gt;make&lt;/code&gt; switch, enabling as many threads as there are logical cores on your system.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;fsarchiver -Z3 -j$(nproc) -v savefs &amp;lt;backup-path&amp;gt;/old-laptop.fsa /dev/mapper/arch-{root,home,opt,var} /dev/mapper/boot-arch --exclude=&amp;quot;lost+found&amp;quot; --exclude=&amp;quot;/var/cache/pacman/pkg/*&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;-v/--verbose&lt;/code&gt; option is useful to get a progress report, however it will list every file being archived and as such likely blow away your terminal history.&lt;/p&gt;
&lt;div class=&#34;admonition info&#34;&gt;
  BTW, &lt;a href=&#34;https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/295770be/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here is why&lt;/a&gt; clonezilla defaults to &lt;em&gt;partclone&lt;/em&gt; instead of &lt;em&gt;fsarchiver&lt;/em&gt; in the words of its author. Tldr: partclone supports pipes/stdin/stdout which are needed for other Clonezilla features, while fsarchiver doesn&amp;rsquo;t. Tough life.
&lt;/div&gt;
&lt;p&gt;Note however that FSArchiver (just like partclone) doesn&amp;rsquo;t deal with recreating a partition table on the destination, or any other form of partitioning/preparing the drive such as LUKS/LVM: you gotta do all that manually up to the point where you are ready to restore &lt;em&gt;filsystems&lt;/em&gt; (that is to say, fsarchiver isn&amp;rsquo;t a &lt;em&gt;disk cloning&lt;/em&gt; solution).&lt;/p&gt;
&lt;p&gt;Also, you cannot merge the content of separate partitions created this way into one destination (&lt;em&gt;e.g.&lt;/em&gt; if you want to consolidate separate LVs into one FS): they will overwrite each other. For that you&amp;rsquo;d rather use the &lt;code&gt;savedir/restdir&lt;/code&gt; mode, which is akin to a tarball on steroids.&lt;/p&gt;
&lt;h3 id=&#34;squashfs&#34;&gt;&lt;a href=&#34;#squashfs&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Squashfs&lt;/h3&gt;&lt;p&gt;I discovered this method by stumbling upon this gem on the Arch wiki, &amp;ldquo;&lt;a href=&#34;https://wiki.archlinux.org/title/Full_system_backup_with_SquashFS&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Full system backup with SquashFS&lt;/a&gt;&amp;rdquo;, and although the article is in dire need of a proper rewrite (which I&amp;rsquo;ve added to my todo list) I really wanted to give it a try.&lt;/p&gt;
&lt;p&gt;In the words of &lt;a href=&#34;https://tldp.org/HOWTO/SquashFS-HOWTO/whatis.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;TLDP&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/SquashFS&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;SquashFS&lt;/a&gt; is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;a read-only file system that lets you compress whole file systems or single directories, write them to other devices/partitions or to ordinary files, and then mount them directly (if a device) or using a loopback device (if it is a file). [&amp;hellip;] For archiving purposes, SquashFS gives you a lot more flexibility and performance speed than a tarball archive.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Its selling points to me are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;random access &amp;amp; transparent decompression: no need to decompress and extract the entire image to browse its content (this is huge, especially when talking about gigabyte-sized images&amp;hellip;)&lt;/li&gt;
&lt;li&gt;file-level deduplication&lt;/li&gt;
&lt;li&gt;exclusion patterns&lt;/li&gt;
&lt;li&gt;zstd support 😊&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However be aware that it &lt;a href=&#34;https://www.kernel.org/doc/html/latest/filesystems/squashfs.html#todo-list&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;doesn&amp;rsquo;t support ACLs&lt;/a&gt;, so if you rely on them you should look somewhere else.&lt;/p&gt;
&lt;p&gt;After quickly perusing its &lt;a href=&#34;https://www.mankier.com/1/mksquashfs&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;manpage&lt;/a&gt; I gave it a go:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mount -o ro /dev/mapper/arch-root /mnt
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mount -o ro /dev/mapper/boot-arch /mnt/boot
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; i in home opt var&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; mount -o ro /dev/mapper/arch-&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; /mnt/&lt;span class=&#34;nv&#34;&gt;$i&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; /mnt
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mksquashfs ./ &amp;lt;backup-path&amp;gt;/old-laptop.sqsh &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -comp zstd &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -no-exports &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -progress &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -mem 6G &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -not-reproducible &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -e var/cache/pacman/pkg
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Results:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Squashfs 4.0 filesystem, zstd compressed, data block size 131072
	compressed data, compressed metadata, compressed fragments,
	compressed xattrs, compressed ids
	duplicates are removed
Filesystem size 3912057.66 Kbytes (3820.37 Mbytes)
	35.64% of uncompressed filesystem size (10975717.90 Kbytes)
Inode table size 2886293 bytes (2818.65 Kbytes)
	24.42% of uncompressed inode table size (11819496 bytes)
Directory table size 3606490 bytes (3521.96 Kbytes)
	36.39% of uncompressed directory table size (9910813 bytes)
Xattr table size 621 bytes (0.61 Kbytes)
	28.98% of uncompressed xattr table size (2143 bytes)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To put things in perspective:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root@archiso ~ # du -sh /mnt
16G	/mnt
root@archiso ~ # du -sh /mnt/var/cache/pacman/pkg
4.5G	/mnt/var/cache/pacman/pkg
root@archiso ~ # du -h &amp;lt;backup-path&amp;gt;/old-laptop.sqsh
3.8G	&amp;lt;backup-path&amp;gt;/old-laptop.sqsh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So it went from 16-4.5=11.5 GiB to 3.8&amp;hellip; Nice!&lt;/p&gt;
&lt;p&gt;It produced a slightly smaller archive than both partclone and fsarchiver (even when accounting for the non-excluded pacman cache), but it took 11.5 minutes. After testing, &lt;code&gt;fsarchiver savedir&lt;/code&gt; took 3min08s and produced a 4.2 GiB image (with &lt;code&gt;--exclude=&#39;*.pkg.tar.zst&#39;&lt;/code&gt;), but then fsarchiver doesn&amp;rsquo;t produce browsable archives and doesn&amp;rsquo;t do any deduplication 😊&lt;/p&gt;
&lt;h3 id=&#34;rsync&#34;&gt;&lt;a href=&#34;#rsync&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Rsync&lt;/h3&gt;&lt;p&gt;One step more remote from system imaging, the ever powerful Swiss-army knife of file transfer can evidently also be used to create &lt;a href=&#34;https://wiki.archlinux.org/title/Rsync#Full_system_backup&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;full system backups&lt;/a&gt;. Here is my personal take on it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;rsync &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --archive &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --hard-links &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --acls &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --xattrs &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --atimes &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --open-noatime &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --sparse &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --human-readable &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --info&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;progress2 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --partial &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --exclude&lt;span class=&#34;o&#34;&gt;={&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;var/cache/pacman/pkg/*&amp;#34;&lt;/span&gt;,&lt;span class=&#34;s2&#34;&gt;&amp;#34;*/lost+found&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    /mnt/* /path/to/backup/dir
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or as a one-liner:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rsync -aHAXUUSh --info=progress2 --partial --exclude={&amp;quot;var/cache/pacman/pkg/*&amp;quot;,&amp;quot;*/lost+found&amp;quot;} /mnt/* /path/to/backup/dir
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See its &lt;a href=&#34;https://man.archlinux.org/man/extra/rsync/rsync.1.en&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;man page&lt;/a&gt; for details on the options used. Note that the repeated &lt;code&gt;-U&lt;/code&gt; is not a mistake but a shortcut to enable both &lt;code&gt;--atimes&lt;/code&gt; and &lt;code&gt;--open-noatime&lt;/code&gt; 😉&lt;/p&gt;
&lt;p&gt;However, while doing so I realized rsync wasn&amp;rsquo;t exactly the best solution when the destination filesystem is {ex,}FAT&amp;hellip; Timestamps and permissions/ACLs/xattr won&amp;rsquo;t carry over correctly&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; 😒  This is what got me for the very first time interested in using&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;tar&#34;&gt;&lt;a href=&#34;#tar&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Tar&lt;/h3&gt;&lt;p&gt;O venerable Lord of computerized backups! Thy name is reminiscent of the glorious days of yore, when backups were mere &lt;em&gt;&lt;strong&gt;t&lt;/strong&gt;ape &lt;strong&gt;ar&lt;/strong&gt;chives&lt;/em&gt;&amp;hellip;&lt;/p&gt;
&lt;p&gt;Okay, but how does it fare in 2022 for complete system backup with high fidelity? After delving into its &lt;a href=&#34;https://man.archlinux.org/man/core/tar/tar.1.en&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;manpage&lt;/a&gt; this is what I came up with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; /mnt
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;tar --create &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --preserve-permissions &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --acls &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --xattrs &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --atime-preserve&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;system &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    --exclude&lt;span class=&#34;o&#34;&gt;={&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;var/cache/pacman/pkg/*&amp;#34;&lt;/span&gt;,&lt;span class=&#34;s2&#34;&gt;&amp;#34;*lost+found&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -I zstdmt &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    -f /path/to/backup/dir/&amp;lt;backup-name&amp;gt;.tar.zst &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    *
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;tar: /var/run/nscd/socket: socket ignored
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# repeat dozens of times&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Hmmm okay, apart from socket files which apparently &lt;a href=&#34;https://comp.os.linux.redhat.narkive.com/z7CkxLXY/excluding-sockets-in-a-tar-backup&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;clearly&lt;/a&gt; &lt;a href=&#34;https://superuser.com/a/705649&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;don&amp;rsquo;t matter&lt;/a&gt;, what about the completeness of the backup? Sections &lt;a href=&#34;https://www.gnu.org/software/tar/manual/tar.html#verify&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;verify&lt;/a&gt; and &lt;a href=&#34;https://www.gnu.org/software/tar/manual/tar.html#compare&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;compare&lt;/a&gt; from tar manual cover this question. A few pitfalls to be aware of however:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--verify&lt;/code&gt; (only for archive creation) &lt;a href=&#34;https://unix.stackexchange.com/questions/618991/how-to-fix-tar-cannot-verify-compressed-archives-error&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;doesn&amp;rsquo;t work with compressed archives&lt;/a&gt;; if you don&amp;rsquo;t mind you can first create and verify an uncompressed archive, then compress it in a second step&amp;hellip;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--compare&lt;/code&gt; &amp;ldquo;&lt;em&gt;ignores files in the file system that do not have corresponding members in the archive&lt;/em&gt;&amp;rdquo;, so if something was left over during the backup, no errors will be reported.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you have the space and will for it, you could also just extract the archive and &lt;code&gt;diff --recursive&lt;/code&gt; it against the source, but all in all I feel this is an aspect where the original (and still current) purpose of tar as a &lt;em&gt;tape specific archiving tool&lt;/em&gt;, makes itself felt.&lt;/p&gt;
&lt;p&gt;From my superficial testing everything seemed mostly alright, but I can&amp;rsquo;t shake the feelings that tar isn&amp;rsquo;t making as complete a clone as fsarchiver or rsync (see its &lt;a href=&#34;https://en.wikipedia.org/wiki/Tar_%28computing%29#Limitations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;limitations&lt;/a&gt; too). But that&amp;rsquo;s probably because my beard isn&amp;rsquo;t  &lt;a href=&#34;https://www.urbandictionary.com/define.php?term=grey%20beard&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;grey enough&lt;/a&gt; I guess&amp;hellip; 😁&lt;/p&gt;
&lt;h2 id=&#34;wrap-up&#34;&gt;&lt;a href=&#34;#wrap-up&#34; class=&#34;headerlink anchor&#34;&gt;&lt;i class=&#34;iconfont icon-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;Wrap up&lt;/h2&gt;&lt;p&gt;In conclusion, if you are in a situation where Clonezilla doesn&amp;rsquo;t work for you (most notably when using LUKS), my recommendation would be to turn to either &lt;strong&gt;FSArchiver&lt;/strong&gt;, &lt;strong&gt;partclone&lt;/strong&gt; or &lt;strong&gt;SquashFS&lt;/strong&gt;. They seem to provide the most complete and reliable feature-set of the lot for imaging systems in a correct and efficient way. Rsync and tar being more general purpose tools, they require more options not to leave something out or otherwise shoot yourself in the foot.&lt;/p&gt;
&lt;p&gt;Also, while laboring over this article I realized that while it was all fine and dandy to have a static archive of my old system, the next step was to make an &lt;em&gt;interactive&lt;/em&gt; image of it that I could boot on whenever I want to see which GTK theme I used, or otherwise take a nostalgic whiff and relapse in my former computing abode&amp;hellip;&lt;/p&gt;
&lt;p&gt;This reminded me of the &lt;a href=&#34;https://wiki.archlinux.org/title/Moving_an_existing_install_into_%28or_out_of%29_a_virtual_machine&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Moving an existing install into a virtual machine&lt;/a&gt; article, and I have an entire article coming up with the fruits of this endeavour: creating a VM image from the backups made here, testing in the process the oh-so-important restoration side of all the different tools used here (which taught me that an un-restored backup is no backup at all), making the required adjustments to be able to boot from it&amp;hellip; Stay stuned for the second part! [edit: &lt;a href=&#34;https://bastientraverse.com/en/posts/2022-04/physical-to-virtual/&#34;&gt;there it goes&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Thanks for reading and happy imaging 🙏&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;One workaround is to use a &lt;a href=&#34;https://en.wikipedia.org/wiki/Loop_device&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;loop device&lt;/a&gt; file, &lt;em&gt;i.e.&lt;/em&gt; create a file sufficiently large to hold your backup, partition it, activate it via &lt;code&gt;losetup&lt;/code&gt;, then finally format it with a more amenable filesystem and  mount it as the backup destination (&lt;a href=&#34;https://wiki.archlinux.org/title/Moving_an_existing_install_into_%28or_out_of%29_a_virtual_machine#Create_the_container&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;example&lt;/a&gt;).&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Parallel ffmpeg stream manipulation</title>
      <link>https://bastientraverse.com/en/posts/2021-10/parallel-ffmpeg/</link>
      <pubDate>Fri, 29 Oct 2021 00:00:00 +0200</pubDate>
      
      <guid>https://bastientraverse.com/en/posts/2021-10/parallel-ffmpeg/</guid>
      <description>&lt;p&gt;This post will illustrate how we can apply different operations (audio transcoding, subtitles selection, video, chapters and fonts passthrough) on multistream MKVs with ffmpeg, while optimizing for multicore systems.&lt;/p&gt;
&lt;p&gt;More precisely, here is what we are trying to achieve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;transcode the Japanese audio track from a entire anime season, from a superfluously lossless Flac to the more efficient Opus format&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;shed the useless (to me) English audio track (also in Flac, and 5.1&amp;hellip;), as well as the unneeded &amp;ldquo;Signs-only&amp;rdquo; subtitle   tracks&lt;/li&gt;
&lt;li&gt;pass-through the video track&lt;/li&gt;
&lt;li&gt;retain all attachments (fonts, chapters&amp;hellip;)&lt;/li&gt;
&lt;li&gt;preserve file modification times&lt;/li&gt;
&lt;li&gt;replace the original files with the new ones&lt;/li&gt;
&lt;li&gt;do all this as fast and efficiently as possible 😎&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;When starting, I knew how to accomplish this in two steps using two different tools:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Identify and remove the unwanted streams with &lt;a href=&#34;https://mkvtoolnix.download/doc/mkvmerge.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;mkvmerge&lt;/a&gt;&lt;sup&gt;(&lt;a href=&#34;https://www.reddit.com/r/mkvtoolnix/comments/8qcgez/can_somebody_help_with_batch_remove_unwanted/e0jq70n/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;source&lt;/a&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mkvmerge -i *.mkv
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;File &lt;span class=&#34;s1&#34;&gt;&amp;#39;01.mkv&amp;#39;&lt;/span&gt;: container: Matroska
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 0: video &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;HEVC/H.265/MPEG-H&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 1: audio &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;Flac&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 2: audio &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;Flac&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 3: subtitles &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;SubStationAlpha&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 4: subtitles &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;SubStationAlpha&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 5: subtitles &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;HDMV PGS&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Track ID 6: subtitles &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;HDMV PGS&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Attachment ID 1: &lt;span class=&#34;nb&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;application/vnd.ms-opentype&amp;#39;&lt;/span&gt;, size &lt;span class=&#34;m&#34;&gt;30712&lt;/span&gt; bytes, file name &lt;span class=&#34;s1&#34;&gt;&amp;#39;font.ttf&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;...&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; f in *.mkv&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; mkvmerge -o &lt;span class=&#34;s2&#34;&gt;&amp;#34;remuxed/&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; --audio-tracks &lt;span class=&#34;s1&#34;&gt;&amp;#39;!eng&amp;#39;&lt;/span&gt; --subtitle-tracks &lt;span class=&#34;s1&#34;&gt;&amp;#39;!4,6&amp;#39;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;admonition tip&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;
  Here I was able to use &lt;code&gt;!eng&lt;/code&gt; because the audio track was labeled as such, but we could achieve the same with numerical index (just as we are doing for subs).
&lt;/div&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;
&lt;p&gt;Use ffmpeg to transcode the remaining audio track to Opus, using a &lt;a href=&#34;https://kokomins.wordpress.com/2019/10/10/anime-encoding-guide-for-x265-and-why-to-never-use-flac/#recommended-settings&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;generous 192 kbps&lt;/a&gt; (96k per audio channel) bitrate and then do the cleanup:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; f in remuxed/*.mkv&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; ffmpeg -i &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; -map &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt; -c copy -c:a libopus -b:a 192k &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; touch -r &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; mv &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where &lt;code&gt;-map 0&lt;/code&gt; ports over all input streams, &lt;code&gt;-c copy&lt;/code&gt; keeps them intact, and &lt;code&gt;-c:a libopus -b:a 192k&lt;/code&gt; modulates this by transcoding all audio streams (in our case, the one we kept) to 192k Opus. Finally, &lt;code&gt;touch -r&lt;/code&gt; updates our file modtime to reflect the original one, and &lt;code&gt;mv&lt;/code&gt; overwrite the source with the modified file (&lt;strong&gt;warning&lt;/strong&gt;: make sure to always test on a copy first, &lt;strong&gt;otherwise data loss will incur!&lt;/strong&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;From there it was rather easy to merge it all in one fell for loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; f in *.mkv&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    mkvmerge -o &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; --audio-tracks &lt;span class=&#34;s1&#34;&gt;&amp;#39;!eng&amp;#39;&lt;/span&gt; --subtitle-tracks &lt;span class=&#34;s1&#34;&gt;&amp;#39;!4,6&amp;#39;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    ffmpeg -i &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; -map &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt; -c copy -c:a libopus -b:a 192k &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp2_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    touch -r &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp2_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    mv &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp2_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;    rm &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;se&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, now the next step was to get rid of the superfluous &lt;em&gt;mkvmerge&lt;/em&gt; and do it all with the Ever Almighty Multimedia Swiss-Army Knife®, ffmpeg. For that I had to dig quite a bit, but here is the result:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; f in *.mkv&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; ffmpeg -i &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; -map &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt; -map -0:a:1 -map -0:s:1 -map -0:s:3 -c copy -c:a libopus -b:a 192k &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; touch -r &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; mv &lt;span class=&#34;s2&#34;&gt;&amp;#34;tmp_&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As before we first select all streams via &lt;code&gt;-map 0&lt;/code&gt;, then make use of &lt;a href=&#34;https://trac.ffmpeg.org/wiki/Map&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;negative mapping&lt;/a&gt; (notice the minus sign at the front of the subsequent &lt;code&gt;-map&lt;/code&gt; values) to get rid of the unwanted tracks (second audio track, second and fourth sub tracks&amp;hellip; Beware, this time we are using ffmpeg&amp;rsquo;s indexes/IDs which are relative to the category and 0-indexed). Then it is as before, we copy all remaining streams without changing them (&lt;code&gt;-c copy&lt;/code&gt;) except audio ones which are transcoded to Opus.&lt;/p&gt;
&lt;p&gt;Now this is all well and dandy, but this command runs sequentially, iterating over each file while queuing up the others, disregarding our multicore CPU architecture and thus slowing down the process. How can we run all this concurrently, dispatching a job to each CPU thread?&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.gnu.org/software/parallel/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;GNU Parallel&lt;/a&gt;&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; to the rescue!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;parallel ffmpeg -i &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; -map &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt; -map -0:a:1 -map -0:s:1 -map -0:s:3 -c copy -c:a libopus -b:a 192k tmp_&lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;;&amp;#39;&lt;/span&gt; touch -r &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; tmp_&lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;;&amp;#39;&lt;/span&gt; mv tmp_&lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; ::: *.mkv
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;admonition info&#34;&gt;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;
  Of course, overall time will also depend on your storage read/write speeds&amp;hellip;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Et voilà&lt;/em&gt;, that&amp;rsquo;s how you &lt;em&gt;efficiently&lt;/em&gt; and &lt;em&gt;stylishly&lt;/em&gt; reduce a bloated 10.9GB series to a lean and mean 4.8GB one. Great success! 👍👏🤗&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://kokomins.wordpress.com/2019/10/10/anime-encoding-guide-for-x265-and-why-to-never-use-flac/#why-you-should-never-use-flac&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Why you should never use FLAC&lt;/a&gt; (for that use case that is)&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://unix.stackexchange.com/a/104798&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this Unix SE answer&lt;/a&gt; for why Parallel is superior to Xargs in this matter.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
