{
  "created": "2023-01-06T00:13:22Z",
  "hierarchy": [
    {
      "name": "ROOT",
      "type": "folder",
      "uri": "/ROOT"
    },
    {
      "name": "Home Server Notes",
      "type": "article",
      "uri": "Home_Server_Notes"
    }
  ],
  "html": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"/><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/><meta name=\"name\" content=\"Nikhil's Personal Wiki\"/><meta name=\"description\" content=\"Home Server Notes – Nikhil's Personal Wiki\"/><meta name=\"author\" content=\"Nikhil Anand\"/><meta name=\"theme-color\" content=\"#ffe9a00\"/><meta property=\"og:title\" content=\"Home Server Notes – Nikhil's Personal Wiki\"/><meta property=\"og:description\" content=\"Home Server Notes – Nikhil's Personal Wiki\"/><meta property=\"og:type\" content=\"website\"/><meta property=\"og:image\" content=\"/img/logo512.png\"/><meta property=\"og:site_name\" content=\"Nikhil's Personal Wiki\"/><link rel=\"og:image\" href=\"/img/logo512.png\"/><link rel=\"icon\" href=\"/img/favicon.png\"/><link rel=\"apple-touch-icon\" href=\"/img/logo192.png\"/><link rel=\"stylesheet\" href=\"/css/styles.css\"/><title>Home Server Notes – Nikhil's Personal Wiki</title><script defer data-domain=\"wiki.nikhil.io\" src=\"https://plausible.io/js/plausible.js\"></script></head><body><noscript>👉 A few things won't work if you have JavaScript disabled.</noscript><div class=\"container article\"><header><nav><ul><li><a href=\"/archive\" class title=\"Archive\"><span>Archive</span></a></li><li><a href=\"/Home\" class title=\"Home\"><span>Home</span></a></li><li><a href=\"/random\" class title=\"See a random article\"><span>Random</span></a></li><li><a href=\"/Home_Server_Notes/raw.txt\" title=\"View Source\"><span>Raw</span></a></li><li><a href=\"/Home_Server_Notes/revisions\" class title=\"View revisions\"><span>Revisions</span></a></li><li><a href=\"/Home_Server_Notes/index.json\" title=\"View JSON Object\"><span>JSON</span></a></li></ul></nav></header><main><article><article-hierarchy><ul><li><a data-entity-type=\"folder\" href=\"/ROOT\" title=\"ROOT\">Root</a></li><li><a data-entity-type=\"article\" href=\"/Home_Server_Notes\" title=\"Home Server Notes\">Home Server Notes</a></li></ul></article-hierarchy><header><h1>Home Server Notes</h1></header><article-content><p>Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.</p>\n<hr />\n<ul id=\"toc\">\n<li>\n<a href=\"#hardware\">Hardware</a></li>\n<li>\n<a href=\"#image\">Image</a></li>\n<li>\n<a href=\"#post-install\">Post Install</a><ul>\n<li>\n<a href=\"#basic-stuff\">Basic Stuff</a></li>\n<li>\n<a href=\"#neovim\">NeoVim</a></li>\n<li>\n<a href=\"#firewall\">Firewall</a></li>\n<li>\n<a href=\"#login-logo\">Login Logo</a></li>\n<li>\n<a href=\"#set-hostname\">Set hostname</a></li>\n<li>\n<a href=\"#netplan\">Netplan</a></li>\n<li>\n<a href=\"#importing-the-zpools\">Importing the Zpools</a></li>\n<li>\n<a href=\"#groups\">Groups</a></li>\n<li>\n<a href=\"#cron-jobs\">Cron Jobs</a></li>\n<li>\n<a href=\"#docker\">Docker</a></li>\n<li>\n<a href=\"#desktop-environment\">Desktop Environment</a></li>\n<li>\n<a href=\"#samba\">Samba</a></li>\n<li>\n<a href=\"#sanoid\">Sanoid</a></li>\n<li>\n<a href=\"#glances\">Glances</a></li>\n</ul>\n</li>\n<li>\n<a href=\"#miscellaneous-notes\">Miscellaneous Notes</a><ul>\n<li>\n<a href=\"#reset-homebridge-password\">Reset HomeBridge password</a></li>\n<li>\n<a href=\"#remove-snap\">Remove Snap</a></li>\n<li>\n<a href=\"#installing-google-chrome\">Installing Google Chrome</a></li>\n</ul>\n</li>\n<li>\n<a href=\"#backups\">Backups</a><ul>\n<li>\n<a href=\"#creating-an-encrypted-backup-disk\">Creating an Encrypted Backup Disk</a></li>\n<li>\n<a href=\"#removing-encryption-on-backup-drive\">Removing Encryption on Backup Drive</a></li>\n<li>\n<a href=\"#exfat-on-backup-drive\">exFAT on Backup Drive</a></li>\n</ul>\n</li>\n<li>\n<a href=\"#references\">References</a></li>\n</ul>\n<h2 id=\"hardware\">Hardware</h2>\n<p>Read the <a href=\"https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/\">Community Hardware Guide</a> to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.</p>\n<ul>\n<li>SuperMicro X11SSM-F-O Micro-ATX: <a href=\"https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm\">website</a>, <a href=\"/assets/X11SSM-F-O-manual.pdf\">manual</a>, <a href=\"%5Bmanual%5D(/assets/X11SSM-F-O-quick-reference.pdf)\">quick reference</a></li>\n<li>Intel <a href=\"https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html\">Xeon E3-1230 V6 Kaby Lake</a></li>\n<li>Seasonic <a href=\"https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190\">FOCUS Plus Series SSR-850PX 850W 80+ Platinum</a></li>\n<li>4 x Crucial <a href=\"http://www.crucial.com/usa/en/x11ssm-f/CT7982341\">16GB ECC Unbuffered</a> memory (<code>CT7982341</code>: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a <em>nightmare</em>.</li>\n<li>5 x Western Digital <a href=\"https://www.wdc.com/products/internal-storage/wd-red.html\">4TB Red NAS Drives</a></li>\n<li><a href=\"http://www.amazon.com/gp/product/B005869A7K\">NZXT Source 210</a></li>\n<li><a href=\"http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015\">Rosewill RFT-120</a> fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.</li>\n<li>An old Intel <a href=\"https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG\">80GB SSD Drive</a></li>\n</ul>\n<p>Ran <a href=\"https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/\"><code>smartctl</code></a> short, conveyance, and long test with an ArchLinux ISO. <a href=\"https://www.orderfactory.com/articles/New-HDD-Testing.html\">Two</a> <a href=\"https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh\">more</a> resources on drive testing. Ran about 10 rounds of <code>memtest86</code> on the memory.</p>\n<hr />\n<h2 id=\"image\">Image</h2>\n<p>Got it <a href=\"https://ubuntu.com/download/server\">from here</a>. Verified via:</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo</span> <span class=\"s2\">&#34;10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso&#34;</span> <span class=\"p\">|</span> shasum -a <span class=\"m\">256</span> --check\n</span></span></code></pre><p>Formatted FAT with GUID Partition Table in <em>Disk Utility</em> on macOS. Then used <a href=\"https://www.balena.io/etcher/\">BalenaEtcher</a> (<code>brew install --cask balenaetcher</code>) to transfer the image.</p>\n<h2 id=\"post-install\">Post Install</h2>\n<h3 id=\"basic-stuff\">Basic Stuff</h3>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo apt update\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt upgrade\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt install <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    zfsutils-linux <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    docker-ce <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    docker-ce-cli <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    containerd.io <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    docker-compose-plugin <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    yadm <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    ntp <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    awscli <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    neovim <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    silversearcher-ag <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    ncdu <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    fzf <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    fd-find <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    tree\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># This is annoying</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt remove command-not-found\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Install SSHD and change the default port</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt install openssh-server\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Will install the NTP service and enable it as well.</span>\n</span></span><span class=\"line\"><span class=\"cl\">apt install ntp\n</span></span></code></pre><h3 id=\"neovim\">NeoVim</h3>\n<p>Needed to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Install prereqs</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt-get install <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    ninja-build gettext <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    libtool-bin <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    cmake <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    g++ <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    pkg-config <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    unzip <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>    curl\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Build!</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">cd</span>\n</span></span><span class=\"line\"><span class=\"cl\">git clone https://github.com/neovim/neovim.git\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">cd</span> neovim\n</span></span><span class=\"line\"><span class=\"cl\">git checkout release-0.8\n</span></span><span class=\"line\"><span class=\"cl\">make <span class=\"nv\">CMAKE_BUILD_TYPE</span><span class=\"o\">=</span>Release\n</span></span><span class=\"line\"><span class=\"cl\">sudo make install\n</span></span></code></pre><h3 id=\"firewall\">Firewall</h3>\n<p><a href=\"/ufw_Notes\">Used <code>ufw</code></a> that shipped with Ubuntu. It&rsquo;s a wrapper around <code>iptables</code>, is simple enough, and does the trick.</p>\n<h3 id=\"login-logo\">Login Logo</h3>\n<pre><code>\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n</code></pre>\n<p>Updated this in <code>/etc/update-motd.d</code></p>\n<h3 id=\"set-hostname\">Set hostname</h3>\n<p>Screwed this up during installation.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">hostnamectl set-hostname newNameHere\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Now edit this</span>\n</span></span><span class=\"line\"><span class=\"cl\">vim /etc/hosts\n</span></span></code></pre><h3 id=\"netplan\">Netplan</h3>\n<p>System would hang on this for a while:</p>\n<blockquote>\n<p>[**    ] A start job is running for Wait for Network to be Configured (XX / no limit)</p>\n</blockquote>\n<p>This is because of something called <code>netplan</code>. Saw the config in <code>/etc/netplan/00-installer-config.yaml</code>, noted that I was not using <code>eno2</code> (using <code>ip a</code>) and added <code>optional: true</code> as shown.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c\"># This is the network config written by &#39;subiquity&#39;</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\"></span><span class=\"nt\">network</span><span class=\"p\">:</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">  </span><span class=\"nt\">ethernets</span><span class=\"p\">:</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    </span><span class=\"nt\">eno1</span><span class=\"p\">:</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      </span><span class=\"nt\">dhcp4</span><span class=\"p\">:</span><span class=\"w\"> </span><span class=\"kc\">true</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    </span><span class=\"nt\">eno2</span><span class=\"p\">:</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      </span><span class=\"nt\">dhcp4</span><span class=\"p\">:</span><span class=\"w\"> </span><span class=\"kc\">true</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      </span><span class=\"nt\">optional</span><span class=\"p\">:</span><span class=\"w\"> </span><span class=\"kc\">true</span><span class=\"w\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"w\">  </span><span class=\"nt\">version</span><span class=\"p\">:</span><span class=\"w\"> </span><span class=\"m\">2</span><span class=\"w\">\n</span></span></span></code></pre><p>This fixed the issue. I don&rsquo;t know what <code>netplan</code> is. I see YAML and smell &lsquo;Enterprise™&rsquo;&hellip;</p>\n<h3 id=\"importing-the-zpools\">Importing the Zpools</h3>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Look for all disks</span>\n</span></span><span class=\"line\"><span class=\"cl\">lsblk -o NAME,SIZE,MODEL,SERIAL\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Look for zpools</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs import\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Import a zpool named &#39;tank&#39;</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs import tank -f\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># To see where things are mounted. In Ubuntu&#39;s case, it will be at /tank</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs get mountpoint\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># See the list of upgrades to the zpools</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zpool upgrade\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># YOU&#39;RE DOING HERE.)</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zpool upgrade -a\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># See when a snapshot is created. You can get other properties this way as well.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs get creation -t snapshot tank/dataset\n</span></span></code></pre><h3 id=\"groups\">Groups</h3>\n<p>For the tank</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo groupadd wheel\n</span></span><span class=\"line\"><span class=\"cl\">sudo usermod -aG wheel nikhil\n</span></span><span class=\"line\"><span class=\"cl\">sudo usermod -aG wheel root\n</span></span><span class=\"line\"><span class=\"cl\">sudo chown -R :wheel /tank\n</span></span></code></pre><p>ACLs were trouble, however. I had to do this to prevent &ldquo;Operation not permitted&rdquo; errors when I was trying to setgid with <code>chmod</code>. <a href=\"https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/\">This post</a> helped me.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">zfs <span class=\"nb\">set</span> <span class=\"nv\">aclmode</span><span class=\"o\">=</span>passthrough tank/dataset\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Then this was OK</span>\n</span></span><span class=\"line\"><span class=\"cl\">chmod g+s /tank/dataset\n</span></span></code></pre><h3 id=\"cron-jobs\">Cron Jobs</h3>\n<p>Prefixed all of them with <code>custom__</code> to distinguish them from things that came with the system or were installed via packages.</p>\n<p>Used this favorite as a preamble to any new jobs</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># +---------------- minute (0 - 59)</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># |  +------------- hour (0 - 23)</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># |  |  +---------- day of month (1 - 31)</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># |  |  |  +------- month (1 - 12)</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># |  |  |  |  +---- day of week (0 - 6) (Sunday=0)</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># |  |  |  |  |</span>\n</span></span></code></pre><h3 id=\"docker\">Docker</h3>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Get the keys</span>\n</span></span><span class=\"line\"><span class=\"cl\">curl -fsSL https://download.docker.com/linux/ubuntu/gpg <span class=\"p\">|</span> sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Set up the Docker repo</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo</span> <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  <span class=\"s2\">&#34;deb [arch=</span><span class=\"k\">$(</span>dpkg --print-architecture<span class=\"k\">)</span><span class=\"s2\"> signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s2\">  </span><span class=\"k\">$(</span>lsb_release -cs<span class=\"k\">)</span><span class=\"s2\"> stable&#34;</span> <span class=\"p\">|</span> sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Update apt</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt update\n</span></span></code></pre><p>Got all my images via the amazing <a href=\"https://github.com/linuxserver\">LinuxServer.io</a> project.</p>\n<p>Note that there <em>used</em> to be a <code>docker-compose</code> command (a standalone Python script) but they made it a plugin to the <code>docker</code> command. Woo. So you omit the hyphen and rock and roll.</p>\n<p>You will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are <code>1000</code> and <code>1000</code> which map to the non-root user the installer had you create.</p>\n<p>Created separate configurations for each of the services.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Start the container with the service name in the background (-d)</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /path/to/service.yml -p service_name up -d\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Stop the container</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /path/to/service.yml down\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Restart the container</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /path/to/service.yml restart\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Tail logs</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker logs --follow &lt;Container ID&gt;\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Check if a container is set to start at boot</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker inspect &lt;container_id&gt; <span class=\"p\">|</span> restart -A <span class=\"m\">5</span>\n</span></span></code></pre><p>When you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Find out the name of the service</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker ps\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Assume it&#39;s called `plex`. Now stop it</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /zpool/docker/plex.yml -p plex stop\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Make your changes to the config YAML, and then bring **another** container back up!</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /zpool/docker/plex.yml -p plex up -d\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># **** THIS WILL NOT APPLY CHANGES! ****</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker compose -f /zpool/docker/plex.yml -p plex start\n</span></span></code></pre><p><a href=\"https://stackoverflow.com/a/67335047\">Review this</a> for the differences between <code>always</code>, <code>unless-stopped</code>, etc.</p>\n<p>Networking was a bit iffy. I want the containers to appear as if they were on the LAN. <code>macvlan</code> networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network create -d macvlan <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --subnet<span class=\"o\">=</span>192.168.1.0/24 <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --gateway<span class=\"o\">=</span>192.168.1.1 <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -o <span class=\"nv\">parent</span><span class=\"o\">=</span>eno1 <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  my-macvlan\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Make sure it exists</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network ls\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Inspect it</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network inspect &lt;Network ID&gt;\n</span></span></code></pre><p>And now you add the bridge on the <em>host</em> so it knows how to route traffic.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge</span>\n</span></span><span class=\"line\"><span class=\"cl\">ip link add mac0 link eno1 <span class=\"nb\">type</span> macvlan mode bridge\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Assign an IP to this interface</span>\n</span></span><span class=\"line\"><span class=\"cl\">ip addr add 192.168.1.100/32 dev mac0\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Bring up the interface</span>\n</span></span><span class=\"line\"><span class=\"cl\">ip link <span class=\"nb\">set</span> mac0 up\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Tell docker to use the interface to communicate</span>\n</span></span><span class=\"line\"><span class=\"cl\">ip route add 192.168.1.0/24 dev mac0\n</span></span></code></pre><p>These should persist across reboots. People <a href=\"https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/\">configure stuff</a> in <code>/etc/network/interface</code> but I didn&rsquo;t need to do that (which mystifies me&hellip;)</p>\n<p>Some containers didn&rsquo;t have the <code>ip</code> command. Install via <code>apt install iproute2</code>.</p>\n<p>Constrained on router to assign same IP based on MAC. Docker appears to assign <code>02:42:0a</code> as the OUI. So be it.</p>\n<p><a href=\"https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064\">This is how you specify an external default network</a> in Docker Compose.</p>\n<p>Some other notes:</p>\n<ul>\n<li>AFAICT you cannot edit networks. You gotta remove and add them.</li>\n<li>To stop the Docker service, you must run <code>sudo systemctl stop docker.socket</code> (note the socket part!)</li>\n<li>When you try to remove a network and get the &ldquo;<a href=\"https://github.com/moby/moby/issues/17217\">has active endpoints</a>&rdquo; error,</li>\n</ul>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Get a list of all the containers and look for the &#34;Name&#34;</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network inspect my-macvlan\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Now make sure you remove all the endpoints. Let&#39;s say the container</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># name is &#34;ubooquity&#34;. Note that this is NOT the endpoint ID!</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network disconnect -f my-macvlan ubooquity\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Now remove the VLAN</span>\n</span></span><span class=\"line\"><span class=\"cl\">docker network rm -f my-macvlan\n</span></span></code></pre><p>Now re-run all the steps above and <em>remember to <strong>remove</strong> all containers and start them</em>! You cannot just restart them and expect them to work!</p>\n<h4 id=\"notes-on-archivebox\">Notes on ArchiveBox</h4>\n<p>Needed to run a command inside the running container and did this:</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo docker <span class=\"nb\">exec</span> -it archivebox /bin/bash\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Inside the container, you cannot be root</span>\n</span></span><span class=\"line\"><span class=\"cl\">su archivebox\n</span></span><span class=\"line\"><span class=\"cl\">archivebox manage createsuperuser\n</span></span></code></pre><h3 id=\"desktop-environment\">Desktop Environment</h3>\n<p>Meant for this to be headless but I am a lazy person. Used my lovely XFCE4 and <a href=\"https://tigervnc.org/\">TigerVNC</a>. Two important notes:</p>\n<ol>\n<li>You&rsquo;ll have to restart the VNC Server if you log out of your session. There <a href=\"https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out\">are solutions</a> but I did not use them.</li>\n<li>This configuration will only allow connections on <code>localhost</code>. You&rsquo;ll need an SSH tunnel to the server.</li>\n</ol>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo apt install xfce4 tigervnc-standalone-server firefox\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Set the password for the current (NON-ROOT) user</span>\n</span></span><span class=\"line\"><span class=\"cl\">vncpasswd\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Upon connection via VNC, start XFCE4</span>\n</span></span><span class=\"line\"><span class=\"cl\">cat <span class=\"s\">&lt;&lt;EOF &gt; ~/.vnc/xstartup\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">#!/bin/sh\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">unset SESSION_MANAGER\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">unset DBUS_SESSION_BUS_ADDRESS\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">exec startxfce4\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">EOF</span>\n</span></span><span class=\"line\"><span class=\"cl\">chmod u+x ~/.vnc/xstartup\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Create your own preferences for startup</span>\n</span></span><span class=\"line\"><span class=\"cl\">cat <span class=\"s\">&lt;&lt;EOF &gt; ~/.vnc/config\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">geometry=1280x960\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">depth=32\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">EOF</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Now create a service for the VNC Server. As root:</span>\n</span></span><span class=\"line\"><span class=\"cl\">cat <span class=\"s\">&lt;&lt;EOF &gt; /etc/systemd/system/vncserver@.service\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">[Unit]\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Description=Remote desktop service (VNC)\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">After=syslog.target network.target\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\"># DO NOT BE ROOT FFS. The &#39;-localhost&#39; flag is important too.\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">[Service]\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Type=simple\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">User=nikhil\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Group=wheel\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">WorkingDirectory=/home/nikhil\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">ExecStartPre=/bin/sh -c &#39;/usr/bin/vncserver -kill :%i &gt; /dev/null 2&gt;&amp;1 || :&#39;\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">ExecStart=/usr/bin/vncserver -localhost :%i\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">ExecStop=/usr/bin/vncserver -kill :%i\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">[Install]\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">WantedBy=multi-user.target\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">EOF</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Tell systemd about it and bring it up at reboot. This is a single instance btw.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl daemon-reload\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl <span class=\"nb\">enable</span> vncserver@1\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl start vncserver@1\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># See some startup logs</span>\n</span></span><span class=\"line\"><span class=\"cl\">journalctl -u vncserver@1 -f\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Now on the client, create an SSH tunnel</span>\n</span></span><span class=\"line\"><span class=\"cl\">ssh -p <span class=\"m\">3227</span> -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n</span></span></code></pre><p>Note that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.</p>\n<h3 id=\"samba\">Samba</h3>\n<p><a href=\"https://superuser.com/a/1400920\">This</a> was an excellent guide! Also see <a href=\"https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/\">this</a>.</p>\n<p>Setting up Samba shares was rather easy in <code>/etc/samba/smb.conf</code>. Make sure you <a href=\"https://unix.stackexchange.com/a/562999\">do this to prevent Guest Access</a>.</p>\n<h3 id=\"sanoid\">Sanoid</h3>\n<p><a href=\"https://github.com/jimsalterjrs/sanoid\">Nice little Perl script</a> to automate ZFS snapshotting. <code>apt install sanoid</code> installs a <code>cron</code> script in <code>/etc/cron.d/sanoid</code>. Configuation in <code>/etc/sanoid/sanoid.conf</code> was as simple as this. I want snapshots of all child datasets <em>except</em> for one and this is what my config looked like (<a href=\"https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066\">reference</a>).</p>\n<pre><code>[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n</code></pre>\n<p>See <a href=\"https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options\">the options</a> for more info on each. Note that the defaults are <code>/usr/share/sanoid/sanoid.defaults.conf</code>.</p>\n<h3 id=\"glances\">Glances</h3>\n<p>Glances v3 won&rsquo;t work with Ubuntu Server v24 LTS. You need v4 and need to <code>pip install</code> the damn thing. Type <code>glances -V</code> to see some info about the version and the log file.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo apt -y gcc lm-sensors wireless-tools\n</span></span><span class=\"line\"><span class=\"cl\">mise install python@3.13.5\n</span></span><span class=\"line\"><span class=\"cl\">pip install --user <span class=\"s1\">&#39;glances[all]&#39;</span>\n</span></span></code></pre><p>Here&rsquo;s the service definition:</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># /etc/systemd/system/glances.service</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"o\">[</span>Unit<span class=\"o\">]</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nv\">Description</span> <span class=\"o\">=</span> Glances in Web Server Mode\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nv\">After</span> <span class=\"o\">=</span> network.target\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"o\">[</span>Service<span class=\"o\">]</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nv\">ExecStart</span> <span class=\"o\">=</span> /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t <span class=\"m\">5</span> -B 0.0.0.0 -p <span class=\"m\">8080</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"o\">[</span>Install<span class=\"o\">]</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"nv\">WantedBy</span> <span class=\"o\">=</span> multi-user.target\n</span></span></code></pre><h2 id=\"miscellaneous-notes\">Miscellaneous Notes</h2>\n<ul>\n<li>I use DuckDNS for Dynamic DNS</li>\n<li>No password on PiHole via <code>sudo pihole -a -p</code> followed by an <kbd>Enter</kbd>. It&rsquo;s how you set a password as well.</li>\n<li>Found myself not being able to run more than two containers at once. <a href=\"https://stackoverflow.com/a/39489432\">Docker Compose is strange</a>. Each <code>docker compose up</code> command needs to be given its own <code>-p</code></li>\n<li>To list the contents of a package, <code>dpkg-query -L package-name</code></li>\n<li>Needed to add this to get <code>fzf</code> working</li>\n</ul>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># shellcheck source=/dev/null</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"k\">if</span> <span class=\"o\">[[</span> <span class=\"k\">$(</span>uname<span class=\"k\">)</span> <span class=\"o\">==</span> <span class=\"s2\">&#34;Linux&#34;</span> <span class=\"o\">]]</span><span class=\"p\">;</span> <span class=\"k\">then</span>\n</span></span><span class=\"line\"><span class=\"cl\">  <span class=\"o\">[[</span> -f /usr/share/doc/fzf/examples/key-bindings.bash <span class=\"o\">]]</span> <span class=\"o\">&amp;&amp;</span> <span class=\"nb\">source</span> /usr/share/doc/fzf/examples/key-bindings.bash\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"k\">fi</span>\n</span></span></code></pre><h3 id=\"reset-homebridge-password\">Reset HomeBridge password</h3>\n<p>Remove <code>auth.json</code> in <code>/var/lib/homebridge</code> if installed on a RaspberryPi. Else you can find it in <code>$HOME/.homebridge</code>.<br />\nElse you can find it in <code>/var/lib/docker/volumes/homebridge</code> if running in Docker. (Else just reinstall the damn thing and keep better track of your passwords&hellip;)</p>\n<p>Then <code>sudo systemctl restart homebridge.service</code>. It&rsquo;s on <code>http://192.168.1.75:8581</code></p>\n<h3 id=\"remove-snap\">Remove Snap</h3>\n<p>Runs in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: <a href=\"http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package\">1</a>, <a href=\"https://haydenjames.io/remove-snap-ubuntu-22-04-lts/\">2</a>, <a href=\"https://www.baeldung.com/linux/snap-remove-disable\">3</a></p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Stop the service. You will have errors removing each snap if you don&#39;t.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl stop snapd\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># List things to remove</span>\n</span></span><span class=\"line\"><span class=\"cl\">snap list <span class=\"p\">|</span> grep -v <span class=\"s2\">&#34;^Name&#34;</span> <span class=\"p\">|</span> awk <span class=\"o\">{</span><span class=\"s1\">&#39;print &#34;sudo snap remove &#34; $1&#39;</span><span class=\"o\">}</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Remove each one.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove bare\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove core20\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove core22\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove cups\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove gnome-3-38-2004\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove gtk-common-themesÏ\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove lxd\n</span></span><span class=\"line\"><span class=\"cl\">sudo snap remove snapd\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Disable things</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl disable snapd.service\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl disable snapd.socket\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl disable snapd.seeded.service\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl disable snapd.autoimport.service\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl disable snapd.apparmor.service\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># AppArmor things</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\n</span></span><span class=\"line\"><span class=\"cl\">sudo systemctl start apparmor.service\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Find a list of snap mounts and remove them</span>\n</span></span><span class=\"line\"><span class=\"cl\">df <span class=\"p\">|</span> grep snap <span class=\"p\">|</span> awk <span class=\"o\">{</span><span class=\"s1\">&#39;print &#34;sudo umount &#34; $6&#39;</span><span class=\"o\">}</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Purge snap</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt purge snapd\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Clean things up</span>\n</span></span><span class=\"line\"><span class=\"cl\">rm -rf ~/snap\n</span></span><span class=\"line\"><span class=\"cl\">sudo rm -rf /snap\n</span></span><span class=\"line\"><span class=\"cl\">sudo rm -rf /var/snap\n</span></span><span class=\"line\"><span class=\"cl\">sudo rm -rf /var/lib/snapd\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Create configs for future installs like Firefox and Chromium</span>\n</span></span><span class=\"line\"><span class=\"cl\">cat <span class=\"s\">&lt;&lt;EOF | sudo tee /etc/apt/preferences.d/snapd\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Package: snapd\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Pin: origin *\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Pin-Priority: -1\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">EOF</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Make sure we&#39;re not using Snap for Firefox</span>\n</span></span><span class=\"line\"><span class=\"cl\">cat <span class=\"s\">&lt;&lt;EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Package: firefox*\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Pin: release o=Ubuntu*\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">Pin-Priority: -1\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"s\">EOF</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo add-apt-repository ppa:mozillateam/ppa\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Install things</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt update\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt install firefox\n</span></span></code></pre><h3 id=\"installing-google-chrome\">Installing Google Chrome</h3>\n<p>Note: do this after uninstalling snap.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">sudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub <span class=\"p\">|</span> sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\">sudo sh -c <span class=\"s1\">&#39;echo &#34;deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main&#34; &gt; /etc/apt/sources.list.d/google.list&#39;</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt update\n</span></span><span class=\"line\"><span class=\"cl\">sudo apt install google-chrome-stable\n</span></span></code></pre><h2 id=\"backups\">Backups</h2>\n<p>Made sure to do this to two external, encrypted drives. All datasets and snapshots. See <a href=\"/ZFS_and_Backups\">these</a> <a href=\"/ZFS_Notes\">two</a> pages for more notes.</p>\n<h3 id=\"creating-an-encrypted-backup-disk\">Creating an Encrypted Backup Disk</h3>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Make sure it&#39;s the right disk</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo lsblk -o name,size,model\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Wipe all filesystems</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo wipefs -a /dev/sdg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Create the Zpool. aes-256-gcm is the default for passphrase.</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Using gzip compression.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zpool create <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">encryption</span><span class=\"o\">=</span>on <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">keyformat</span><span class=\"o\">=</span>passphrase <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">compression</span><span class=\"o\">=</span>lz4 <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">keylocation</span><span class=\"o\">=</span>prompt <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">xattr</span><span class=\"o\">=</span>sa <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -O <span class=\"nv\">atime</span><span class=\"o\">=</span>off <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  backup-03 /dev/sdg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Export. Re-import, unlock to write to disk.</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zpool <span class=\"nb\">export</span> backup-03\n</span></span><span class=\"line\"><span class=\"cl\">sudo zpool import backup-03\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs load-key -r backup-03\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Lock the drive</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs unload-key -r backup-03\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Change the key</span>\n</span></span><span class=\"line\"><span class=\"cl\">sudo zfs change-key backup-03\n</span></span></code></pre><h3 id=\"removing-encryption-on-backup-drive\">Removing Encryption on Backup Drive</h3>\n<p>TODO: Finish this section.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Get the ID of the drives. It will look like</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\">#</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\">#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\">#</span>\n</span></span><span class=\"line\"><span class=\"cl\">zpool status\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Assume that my pool is called `backup`</span>\n</span></span><span class=\"line\"><span class=\"cl\">zpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n</span></span></code></pre><h3 id=\"exfat-on-backup-drive\">exFAT on Backup Drive</h3>\n<p>Wanted to use an 8TB external drive for backups. Didn&rsquo;t have much luck getting stuff formatted by <code>gparted</code> and <code>fdisk</code> and <code>mkfs</code> to work on macOS (i.e., it wouldn&rsquo;t recognize the partitions on the drive) so just used Disk Utility to format it.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># List all physical disks. The flag removes loops devices.</span>\n</span></span><span class=\"line\"><span class=\"cl\">lsblk -e7\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># or, for a longer and better view,</span>\n</span></span><span class=\"line\"><span class=\"cl\">fdisk -l\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Mount the disk</span>\n</span></span><span class=\"line\"><span class=\"cl\">mount -o <span class=\"nv\">uid</span><span class=\"o\">=</span>1000,gid<span class=\"o\">=</span>1001,umask<span class=\"o\">=</span><span class=\"m\">002</span> /dev/sdg2 /backup-02\n</span></span></code></pre><p><code>rsync</code> with the <code>-a</code> flag will preserve permissions. This would give me <code>chgrp operation not permitted</code> errors. This is because exFAT does not support permissions 🤷‍♂️. So,</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># I&#39;m lazy and don&#39;t want to look up the exact options. Hence the</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># &#34;add everything and remove what I don&#39;t need&#34; flags here:</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\">rsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n</span></span></code></pre><h2 id=\"references\">References</h2>\n<ul>\n<li><a href=\"https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/\">Migrating FreeNAS ZFS Pools to Ubuntu</a></li>\n<li>Mac VLANs\n<ul>\n<li><a href=\"https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/\">Fantastic Overview</a>   - <a href=\"https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\">2 Minutes to Docker MacVLAN Networking – A Beginners Guide</a>   - <a href=\"https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\">How to Create and Use MacVLAN Network in Docker</a>   - <a href=\"https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\">Docker Compose Sample</a>   - <a href=\"https://runnable.com/docker/docker-compose-networking\">Docker Compose Networking Overview</a></li>\n</ul>\n</li>\n<li><a href=\"https://github.com/davestephens/ansible-nas\">Ansible NAS</a></li>\n</ul>\n</article-content></article></main><footer><p></p><ul><li>20,938 bytes</li><li>Created on Friday, 6 January 2023 at 00:13 UTC</li><li>Modified on Saturday, 3 October 2026 at 14:13 UTC</li><br/><li><a href=\"https://github.com/afreeorange/wiki.nikhil.io.articles/edit/master/Home Server Notes.md\" title=\"Edit this article\">Edit this article</a></li><li><a href=\"https://github.com/afreeorange/bock\" title=\"View the project that generates this wiki on Github\"><span>bock 6.3.0-alpha</span></a></li></ul></footer></div><script src=\"/js/table-sort.js\" defer></script><script type=\"text/javascript\">\n        document.body.addEventListener(\n          \"keypress\", (e) => e.key === \"f\"\n          ? window.location.assign(\"/archive\")\n          : null);\n      </script></body></html>",
  "id": "80bd48b3-0a36-5b00-aadf-27c893286aa8",
  "modified": "2026-10-03T14:13:49Z",
  "revisions": [
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "afreeorange",
      "date": "2026-10-03T14:13:49Z",
      "id": "2e6ec18aa36a1602605b93fa24eb6ec7094d3079",
      "shortId": "2e6ec18a",
      "subject": "Remove orange\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n[[toc]]\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /zpool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /zpool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /zpool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi. Else you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker. (Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)   - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)   - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)   - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)   - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-05-28T13:06:18Z",
      "id": "5d8c8be4cc7367adabf738dc128c34d3f804cc04",
      "shortId": "5d8c8be4",
      "subject": "Formatting fixes -- Claude\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n[[toc]]\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi. Else you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker. (Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)   - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)   - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)   - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)   - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-02-04T16:39:00Z",
      "id": "795c1d8c5d37b57dbb94a651090bc108b25efcfd",
      "shortId": "795c1d8c",
      "subject": "Add TOC\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n[[toc]]\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-01-13T18:47:28Z",
      "id": "2436477560f26e23d00a24add1cbfeafdca4af78",
      "shortId": "24364775",
      "subject": "No compression\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-12-24T01:54:54Z",
      "id": "c4e461c770136732b33e6e9670ccc7e97083aa7d",
      "shortId": "c4e461c7",
      "subject": "Corrections and additions\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-12-23T18:06:32Z",
      "id": "deb643905ce75540df3763f9e819c7b81222cbed",
      "shortId": "deb64390",
      "subject": "Add section on encrypting external drives\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zfs export backup-03\nsudo zfs import backup-03\nsudo zfs load-key -r backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-07-26T20:27:34Z",
      "id": "52bffb1bacbaaba8e3a9cfb490d06c8534f0f244",
      "shortId": "52bffb1b",
      "subject": "Update Glances installation for 24 LTS\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-07-01T13:00:06Z",
      "id": "c52549b43a592cc1a7621e56fc085a63a48d614d",
      "shortId": "c52549b4",
      "subject": "Update link to Processor\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-06-16T03:19:40Z",
      "id": "ec9aa97b7020f7601d67ae312562fa3188e78b1d",
      "shortId": "ec9aa97b",
      "subject": "Fix links to PDFs\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-06-16T02:56:28Z",
      "id": "31bd73a366acca130a3cfb2d194178e7160fa501",
      "shortId": "31bd73a3",
      "subject": "Update links to manual, organize resources section\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-FO-manual.pdf), [quick reference]([manual](/assets/X11SSM-FO-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n  - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)\n  - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)\n  - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)\n  - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2025-06-03T19:29:56Z",
      "id": "bbbdc1dbf509041a5df4c4e1a84cfbb274f17fd1",
      "shortId": "bbbdc1db",
      "subject": "Some reorg on a fucking plane in a seat I am way too uncomfortable in.\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-12-27T23:30:31Z",
      "id": "a9c18b12944bbbdb95dceabe573daab90f04215e",
      "shortId": "a9c18b12",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-12-27T23:30:21Z",
      "id": "8ee3054ef045c088b5165e4ec56324112569b4e6",
      "shortId": "8ee3054e",
      "subject": "Initial commit\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-12-08T23:40:14Z",
      "id": "891069f4138c5150dfdfa661158b38d469decd5c",
      "shortId": "891069f4",
      "subject": "Notes on Archivebox\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-08-21T20:08:56Z",
      "id": "4c566b4ed4a65108e6d1f6d5da3f23172c94db50",
      "shortId": "4c566b4e",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-08-12T18:59:23Z",
      "id": "e2281546848ae4b7c4104a07566a546382b30ebf",
      "shortId": "e2281546",
      "subject": "Reorg backup section\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-08-12T18:01:08Z",
      "id": "0694260212721955cfe6dbcbfeef738d365491d9",
      "shortId": "06942602",
      "subject": "Add links to ZFS pages\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-06-26T10:57:17Z",
      "id": "e88b1161e751b88d199972763d6c5f8a3751dca6",
      "shortId": "e88b1161",
      "subject": "Note on the Sock\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-04-20T19:20:55Z",
      "id": "19b620b8eb5d898017cbdcf0a3f1491249edf5ab",
      "shortId": "19b620b8",
      "subject": "Updates\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-09-01T01:47:04Z",
      "id": "ddea7dcbef65214a1d4b07b23c12adf8718e309a",
      "shortId": "ddea7dcb",
      "subject": "Notes on Docker VLAN\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-07-17T14:38:36Z",
      "id": "03078912caf66b34fe8f8adff9c1e1acbf3c1de1",
      "shortId": "03078912",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-07-13T18:13:13Z",
      "id": "f581293330f400f7da6dfb78950ad18eed26241d",
      "shortId": "f5812933",
      "subject": "Notes on Google Chrome\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-07-13T15:28:56Z",
      "id": "bbe73d7071a75567320eca02bec177e56308b516",
      "shortId": "bbe73d70",
      "subject": "Notes on Snap\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# cat <<EOF | sudo tee /etc/apt/preferences.d/pin-xalt7x-chromium-deb-vaapi\n# Package: *\n# Pin: release o=LP-PPA-xalt7x-chromium-deb-vaapi\n# Pin-Priority: 1337\n# EOF\n# sudo add-apt-repository ppa:xalt7x/chromium-deb-vaapi\n\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\nsudo apt install chromium-browser\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-06-28T19:59:55Z",
      "id": "8dffd575f1af3ac3278bf58052e1ef4c8787bc08",
      "shortId": "8dffd575",
      "subject": "Update VNC notes\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-06-15T16:17:19Z",
      "id": "ba4ac5bceba2f2504ad337925f40ec919eb5d36f",
      "shortId": "ba4ac5bc",
      "subject": "Fix heading\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it. \n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-05-03T20:33:22Z",
      "id": "9298d00b5cea7590ea1254a8acc68782de27355d",
      "shortId": "9298d00b",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it. \n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-05-03T20:33:13Z",
      "id": "60f820f68e0471933fe5c62bdc42a1c98a1b6c64",
      "shortId": "60f820f6",
      "subject": "Initial commit\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-04-26T00:42:01Z",
      "id": "3cc17ecf5a086d4ff0e2a99cf3dec9d6d0ebbaae",
      "shortId": "3cc17ecf",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it. \n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-04-11T02:15:05Z",
      "id": "d3c728e01c5dd9e7bf11a51ee65b9faf225c4b12",
      "shortId": "d3c728e0",
      "subject": "Amount of memory\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it. \n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-03-30T00:15:37Z",
      "id": "4c4eca4e99fce25151597d98b94aed689720ed5f",
      "shortId": "4c4eca4e",
      "subject": "Add note on exFAT external drive\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it. \n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-27T01:24:09Z",
      "id": "c7de3a08eabbe124a1e3c5619142ea5fd740b239",
      "shortId": "c7de3a08",
      "subject": "Add more misc notes\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-26T23:27:12Z",
      "id": "14a618e13b550d9a7e329fd2e100cb36f9138e49",
      "shortId": "14a618e1",
      "subject": "Add note on Glances\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nType `glances -V` to see some info about the version and the log file. The one installed via `apt` needed some surgery.\n\n```bash\nexport GLANCES_VERSION=\"3.2.4.2\"\nwget https://github.com/nicolargo/glances/archive/refs/tags/v${GLANCES_VERSION}.tar.gz\ntar zxvf v${GLANCES_VERSION}.tar.gz\nsudo cp -r glances-${GLANCES_VERSION}/glances/outputs/static/public/ /usr/lib/python3/dist-packages/glances/outputs/static\n```\n\nHere's the service definition\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-22T16:46:16Z",
      "id": "25580ac30427c140e9fa9c6935a160a538077c10",
      "shortId": "25580ac3",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-03-09T02:51:54Z",
      "id": "d12cdb72dd2c0e7f8ad1e419e8e3716922965b3b",
      "shortId": "d12cdb72",
      "subject": "NeoVim instructions\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n    \n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-03-08T22:22:37Z",
      "id": "73ceff673d5126d6eefe82622b32e8f702d79c82",
      "shortId": "73ceff67",
      "subject": "Add neovim\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-06T18:23:50Z",
      "id": "4d5d97b9e142cf73eaaa590586609e65b6895267",
      "shortId": "4d5d97b9",
      "subject": "Note on null-snapshots\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-06T18:23:40Z",
      "id": "e7dc2ad8cdb172936d5af9f283695250d8c54588",
      "shortId": "e7dc2ad8",
      "subject": "Create BackBlaze B2.md\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "Nikhil Anand",
      "date": "2023-03-04T02:10:53Z",
      "id": "10833ef533a7cf707520b148b718c400bae22cab",
      "shortId": "10833ef5",
      "subject": "Add note on restarting containers\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /orangepool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /orangepool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /orangepool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-09T23:47:10Z",
      "id": "2197c124911f98047f2d2bcad43adfbd6a7cab89",
      "shortId": "2197c124",
      "subject": "Add note on Samba guests\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-09T21:58:12Z",
      "id": "8cf0b4a4a926fb8a65a809c720d6f738359706af",
      "shortId": "8cf0b4a4",
      "subject": "Refine note on ufw\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-09T21:51:34Z",
      "id": "bdf6ff131d1d66e315575306936c4c17b5dd7f28",
      "shortId": "bdf6ff13",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) = 64GB memory - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* [Samsung 860 PRO 256GB 2.5 Inch SATA III Internal SSD (MZ-76P256BW)](https://www.newegg.com/samsung-860-pro-series-256gb/p/N82E16820147685) for the boot drive.\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    unrar-free \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install \\\n    xfce4 \\\n    tigervnc-standalone-server \\\n    thunar-archive-plugin\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Glances\n\n```\nsudo apt install glances\n```\n\nThen added this to `/etc/systemd/system/glances.service`\n\n```\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0\n\n[Install]\nWantedBy = multi-user.target\n```\n\nThen had to follow [this thing](https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157) to get it to not display a blank page... :/\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-07T23:38:06Z",
      "id": "25bb5c3bb37992550d787ac9ebd704df2cbe243e",
      "shortId": "25bb5c3b",
      "subject": "Unrar notes\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) = 64GB memory - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* [Samsung 860 PRO 256GB 2.5 Inch SATA III Internal SSD (MZ-76P256BW)](https://www.newegg.com/samsung-860-pro-series-256gb/p/N82E16820147685) for the boot drive.\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    unrar-free \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install \\\n    xfce4 \\\n    tigervnc-standalone-server \\\n    thunar-archive-plugin\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Glances\n\n```\nsudo apt install glances\n```\n\nThen added this to `/etc/systemd/system/glances.service`\n\n```\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0\n\n[Install]\nWantedBy = multi-user.target\n```\n\nThen had to follow [this thing](https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157) to get it to not display a blank page... :/\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-07T08:20:16Z",
      "id": "e63e7407f574c39b0efbf31eef2c0390f04faed6",
      "shortId": "e63e7407",
      "subject": "Update hardware specs\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) = 64GB memory - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* [Samsung 860 PRO 256GB 2.5 Inch SATA III Internal SSD (MZ-76P256BW)](https://www.newegg.com/samsung-860-pro-series-256gb/p/N82E16820147685) for the boot drive.\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Glances\n\n```\nsudo apt install glances\n```\n\nThen added this to `/etc/systemd/system/glances.service`\n\n```\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0\n\n[Install]\nWantedBy = multi-user.target\n```\n\nThen had to follow [this thing](https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157) to get it to not display a blank page... :/\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-06T02:14:27Z",
      "id": "dfc868f8322d208ce733423dc308884ab46a09aa",
      "shortId": "dfc868f8",
      "subject": "Glances\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Glances\n\n```\nsudo apt install glances\n```\n\nThen added this to `/etc/systemd/system/glances.service`\n\n```\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /usr/bin/glances -w -t 5 -B 0.0.0.0\n\n[Install]\nWantedBy = multi-user.target\n```\n\nThen had to follow [this thing](https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157) to get it to not display a blank page... :/\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-06T01:46:57Z",
      "id": "4ce2028e0cf024069ee6afb7becf732245aa88ea",
      "shortId": "4ce2028e",
      "subject": "Formatting\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-06T01:44:03Z",
      "id": "01cf144324247f072a5bcd1245dab794246631cd",
      "shortId": "01cf1443",
      "subject": "Note on swap\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Disable Swap\n\nThe installer created an 8GB swapfile for some reason...\n\n```\n# Check if enabled\nsudo swapon --show\n\n# Disable if so\nsudo swapoff -a\n\n# Now edit /etc/fstab to remove swap\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2023-01-06T00:13:22Z",
      "id": "a3959e464be59abc712b74fe2d81c2d576174db9",
      "shortId": "a3959e46",
      "subject": "Updates from building server\n",
      "content": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](https://public.nikhil.io/X11SSM-FO.pdf)\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.newegg.com/Product/Product.aspx?Item=N82E16819117788)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots.\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    silversearcher-ag \\\n    ncdu \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### Firewall\n\nUsed `ufw` that shipped with Ubuntu. It does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container in the background (-d)\ndocker compose -f /path/to/service.yml -p service up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/).\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\nPAMName=login\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver :%i -alwaysshared -fg\nExecStop=/usr/bin/vncserver -kill :%i\nPIDFile=/home/%u/.vnc/%H%i.pid\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`.\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this.\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n# --- Templates ---\n\n[template_base]\n  frequently = 0\n  hourly = 0\n  daily = 30\n  monthly = 12\n  yearly = 1\n  autosnap = yes\n  autoprune = yes\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi.\nElse you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker.\n(Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- [Fantastic Overview of macvlans](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)\n- https://www.linuxtechi.com/create-use-macvlan-network-in-docker/\n- https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml\n- https://runnable.com/docker/docker-compose-networking\n- https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n\n"
    }
  ],
  "sizeInBytes": 20938,
  "source": "Migrated from FreeBSD v11 to Ubuntu Server 22.04. These are some notes from my migration.\n\n---\n\n[[toc]]\n\n## Hardware\n\nRead the [Community Hardware Guide](https://forums.freenas.org/index.php?resources/hardware-recommendations-guide.12/) to pick my components this time. Cheap shit causes headaches and I expect this build to last me a while.\n\n* SuperMicro X11SSM-F-O Micro-ATX: [website](https://www.supermicro.com/products/motherboard/Xeon/C236_C232/X11SSM-F.cfm), [manual](/assets/X11SSM-F-O-manual.pdf), [quick reference]([manual](/assets/X11SSM-F-O-quick-reference.pdf))\n* Intel [Xeon E3-1230 V6 Kaby Lake](https://www.intel.com/content/www/us/en/products/sku/97473/intel-xeon-processor-e31245-v6-8m-cache-3-70-ghz/specifications.html)\n* Seasonic [FOCUS Plus Series SSR-850PX 850W 80+ Platinum](https://www.newegg.com/Product/Product.aspx?Item=N82E16817151190)\n* 4 x Crucial [16GB ECC Unbuffered](http://www.crucial.com/usa/en/x11ssm-f/CT7982341) memory (`CT7982341`: DDR4-2133MHz PC4-17000 ECC Unbuffered CL15 288-Pin DIMM 1.2V Dual Rank Memory Module) - Finding additional memory was a _nightmare_.\n* 5 x Western Digital [4TB Red NAS Drives](https://www.wdc.com/products/internal-storage/wd-red.html)\n* [NZXT Source 210](http://www.amazon.com/gp/product/B005869A7K)\n* [Rosewill RFT-120](http://www.newegg.com/Product/Product.aspx?Item=N82E16811988015) fan filters. Used nylon 8-32 × ½ Phillips flat-head screws to install them.\n* An old Intel [80GB SSD Drive](https://www.amazon.com/Intel-SSDSA2CW080G3-Internal-Solid-State/dp/B00666SGRG)\n\nRan [`smartctl`](https://forums.freenas.org/index.php?threads/hard-drive-burn-in-testing-discussion-thread.21451/) short, conveyance, and long test with an ArchLinux ISO. [Two](https://www.orderfactory.com/articles/New-HDD-Testing.html) [more](https://github.com/Spearfoot/disk-burnin-and-testing/blob/master/disk-burnin.sh) resources on drive testing. Ran about 10 rounds of `memtest86` on the memory.\n\n---\n\n## Image\n\nGot it [from here](https://ubuntu.com/download/server). Verified via:\n\n```shell\necho \"10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb *ubuntu-22.04.1-live-server-amd64.iso\" | shasum -a 256 --check\n```\n\nFormatted FAT with GUID Partition Table in _Disk Utility_ on macOS. Then used [BalenaEtcher](https://www.balena.io/etcher/) (`brew install --cask balenaetcher`) to transfer the image.\n\n## Post Install\n\n### Basic Stuff\n\n```bash\nsudo apt update\nsudo apt upgrade\n\nsudo apt install \\\n    zfsutils-linux \\\n    docker-ce \\\n    docker-ce-cli \\\n    containerd.io \\\n    docker-compose-plugin \\\n    yadm \\\n    ntp \\\n    awscli \\\n    neovim \\\n    silversearcher-ag \\\n    ncdu \\\n    fzf \\\n    fd-find \\\n    tree\n\n# This is annoying\nsudo apt remove command-not-found\n\n# Install SSHD and change the default port\nsudo apt install openssh-server\n\n# Will install the NTP service and enable it as well.\napt install ntp\n```\n\n### NeoVim\n\nNeeded to build this from source since v0.8+ has Lua support and is pretty freaking awesome and the version of Ubuntu I installed only ships with v0.6 :/\n\n```bash\n# Install prereqs\nsudo apt-get install \\\n    ninja-build gettext \\\n    libtool-bin \\\n    cmake \\\n    g++ \\\n    pkg-config \\\n    unzip \\\n    curl\n\n# Build!\ncd\ngit clone https://github.com/neovim/neovim.git\ncd neovim\ngit checkout release-0.8\nmake CMAKE_BUILD_TYPE=Release\nsudo make install\n```\n\n### Firewall\n\n[Used `ufw`](/ufw_Notes) that shipped with Ubuntu. It's a wrapper around `iptables`, is simple enough, and does the trick.\n\n### Login Logo\n\n```\n\n  ____  _____            _   _  _____ ______  _____ ______ _______      ________ _____\n / __ \\|  __ \\     /\\   | \\ | |/ ____|  ____|/ ____|  ____|  __ \\ \\    / /  ____|  __ \\\n| |  | | |__) |   /  \\  |  \\| | |  __| |__  | (___ | |__  | |__) \\ \\  / /| |__  | |__) |\n| |  | |  _  /   / /\\ \\ | . ` | | |_ |  __|  \\___ \\|  __| |  _  / \\ \\/ / |  __| |  _  /\n| |__| | | \\ \\  / ____ \\| |\\  | |__| | |____ ____) | |____| | \\ \\  \\  /  | |____| | \\ \\\n \\____/|_|  \\_\\/_/    \\_\\_| \\_|\\_____|______|_____/|______|_|  \\_\\  \\/   |______|_|  \\_\\\n\n```\n\nUpdated this in `/etc/update-motd.d`\n\n### Set hostname\n\nScrewed this up during installation.\n\n```shell\nhostnamectl set-hostname newNameHere\n\n# Now edit this\nvim /etc/hosts\n```\n\n### Netplan\n\nSystem would hang on this for a while:\n\n> [**    ] A start job is running for Wait for Network to be Configured (XX / no limit)\n\nThis is because of something called `netplan`. Saw the config in `/etc/netplan/00-installer-config.yaml`, noted that I was not using `eno2` (using `ip a`) and added `optional: true` as shown.\n\n```yaml\n# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n    eno1:\n      dhcp4: true\n    eno2:\n      dhcp4: true\n      optional: true\n  version: 2\n```\n\nThis fixed the issue. I don't know what `netplan` is. I see YAML and smell 'Enterprise™'...\n\n### Importing the Zpools\n\n```bash\n# Look for all disks\nlsblk -o NAME,SIZE,MODEL,SERIAL\n\n# Look for zpools\nsudo zfs import\n\n# Import a zpool named 'tank'\nsudo zfs import tank -f\n\n# To see where things are mounted. In Ubuntu's case, it will be at /tank\nsudo zfs get mountpoint\n\n# See the list of upgrades to the zpools\nsudo zpool upgrade\n\n# Perform the upgrades to ALL zpools (YOU NEED TO KNOW WHAT THIS MEANS AND WHAT\n# YOU'RE DOING HERE.)\nsudo zpool upgrade -a\n\n# See when a snapshot is created. You can get other properties this way as well.\nsudo zfs get creation -t snapshot tank/dataset\n```\n\n### Groups\n\nFor the tank\n\n```bash\nsudo groupadd wheel\nsudo usermod -aG wheel nikhil\nsudo usermod -aG wheel root\nsudo chown -R :wheel /tank\n```\n\nACLs were trouble, however. I had to do this to prevent \"Operation not permitted\" errors when I was trying to setgid with `chmod`. [This post](https://old.reddit.com/r/Proxmox/comments/socxbb/permission_denied_when_i_chmod_on_a_zfs_dataset/) helped me.\n\n```bash\nzfs set aclmode=passthrough tank/dataset\n\n# Then this was OK\nchmod g+s /tank/dataset\n```\n\n### Cron Jobs\n\nPrefixed all of them with `custom__` to distinguish them from things that came with the system or were installed via packages.\n\nUsed this favorite as a preamble to any new jobs\n\n```shell\n# +---------------- minute (0 - 59)\n# |  +------------- hour (0 - 23)\n# |  |  +---------- day of month (1 - 31)\n# |  |  |  +------- month (1 - 12)\n# |  |  |  |  +---- day of week (0 - 6) (Sunday=0)\n# |  |  |  |  |\n```\n\n### Docker\n\n```bash\n# Get the keys\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n\n# Set up the Docker repo\necho \\\n  \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\\n  $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Update apt\nsudo apt update\n```\n\nGot all my images via the amazing [LinuxServer.io](https://github.com/linuxserver) project.\n\nNote that there _used_ to be a `docker-compose` command (a standalone Python script) but they made it a plugin to the `docker` command. Woo. So you omit the hyphen and rock and roll.\n\nYou will need a UID and GID that the containers run as. On a base Ubuntu Server system, these are `1000` and `1000` which map to the non-root user the installer had you create.\n\nCreated separate configurations for each of the services.\n\n```bash\n# Start the container with the service name in the background (-d)\ndocker compose -f /path/to/service.yml -p service_name up -d\n\n# Stop the container\ndocker compose -f /path/to/service.yml down\n\n# Restart the container\ndocker compose -f /path/to/service.yml restart\n\n# Tail logs\ndocker logs --follow <Container ID>\n\n# Check if a container is set to start at boot\ndocker inspect <container_id> | restart -A 5\n```\n\nWhen you make changes to the configuration YAML files, merely restarting the containers will not apply the changes! Say you made a change to the Plex server\n\n```bash\n# Find out the name of the service\ndocker ps\n\n# Assume it's called `plex`. Now stop it\ndocker compose -f /zpool/docker/plex.yml -p plex stop\n\n# Make your changes to the config YAML, and then bring **another** container back up!\ndocker compose -f /zpool/docker/plex.yml -p plex up -d\n\n# **** THIS WILL NOT APPLY CHANGES! ****\ndocker compose -f /zpool/docker/plex.yml -p plex start\n````\n\n[Review this](https://stackoverflow.com/a/67335047) for the differences between `always`, `unless-stopped`, etc.\n\nNetworking was a bit iffy. I want the containers to appear as if they were on the LAN. `macvlan` networks appeared to be the answer. There are two modes: Bridge and 802.1q Trunk Bridge. I tried the former.\n\n```bash\n# Create a simple bridge. The 802.1q stuff is a complicated PITA for your use-case...\ndocker network create -d macvlan \\\n  --subnet=192.168.1.0/24 \\\n  --gateway=192.168.1.1 \\\n  -o parent=eno1 \\\n  my-macvlan\n\n# Make sure it exists\ndocker network ls\n\n# Inspect it\ndocker network inspect <Network ID>\n```\n\nAnd now you add the bridge on the _host_ so it knows how to route traffic.\n\n```bash\n# ip link add $INTERFACE_NAME link $PARENTDEV type macvlan mode bridge\nip link add mac0 link eno1 type macvlan mode bridge\n\n# Assign an IP to this interface\nip addr add 192.168.1.100/32 dev mac0\n\n# Bring up the interface\nip link set mac0 up\n\n# Tell docker to use the interface to communicate\nip route add 192.168.1.0/24 dev mac0\n```\n\nThese should persist across reboots. People [configure stuff](https://old.reddit.com/r/docker/comments/amle59/docker_macvlan_setup_ubuntu_no_ip_address_on/) in `/etc/network/interface` but I didn't need to do that (which mystifies me...)\n\nSome containers didn't have the `ip` command. Install via `apt install iproute2`.\n\nConstrained on router to assign same IP based on MAC. Docker appears to assign `02:42:0a` as the OUI. So be it.\n\n[This is how you specify an external default network](https://github.com/docker/compose-cli/issues/1856#issuecomment-1108552064) in Docker Compose.\n\nSome other notes:\n\n- AFAICT you cannot edit networks. You gotta remove and add them.\n- To stop the Docker service, you must run `sudo systemctl stop docker.socket` (note the socket part!)\n- When you try to remove a network and get the \"[has active endpoints](https://github.com/moby/moby/issues/17217)\" error,\n\n```bash\n# Get a list of all the containers and look for the \"Name\"\ndocker network inspect my-macvlan\n\n# Now make sure you remove all the endpoints. Let's say the container\n# name is \"ubooquity\". Note that this is NOT the endpoint ID!\ndocker network disconnect -f my-macvlan ubooquity\n\n# Now remove the VLAN\ndocker network rm -f my-macvlan\n```\n\nNow re-run all the steps above and _remember to **remove** all containers and start them_! You cannot just restart them and expect them to work!\n\n#### Notes on ArchiveBox\n\nNeeded to run a command inside the running container and did this:\n\n```bash\nsudo docker exec -it archivebox /bin/bash\n\n# Inside the container, you cannot be root\nsu archivebox\narchivebox manage createsuperuser\n```\n\n### Desktop Environment\n\nMeant for this to be headless but I am a lazy person. Used my lovely XFCE4 and [TigerVNC](https://tigervnc.org/). Two important notes:\n\n1. You'll have to restart the VNC Server if you log out of your session. There [are solutions](https://unix.stackexchange.com/questions/43398/is-it-possible-to-keep-a-vnc-server-alive-after-log-out) but I did not use them.\n2. This configuration will only allow connections on `localhost`. You'll need an SSH tunnel to the server.\n\n```bash\nsudo apt install xfce4 tigervnc-standalone-server firefox\n\n# Set the password for the current (NON-ROOT) user\nvncpasswd\n\n# Upon connection via VNC, start XFCE4\ncat <<EOF > ~/.vnc/xstartup\n#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nexec startxfce4\n\nEOF\nchmod u+x ~/.vnc/xstartup\n\n# Create your own preferences for startup\ncat <<EOF > ~/.vnc/config\ngeometry=1280x960\ndepth=32\n\nEOF\n\n# Now create a service for the VNC Server. As root:\ncat <<EOF > /etc/systemd/system/vncserver@.service\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n# DO NOT BE ROOT FFS. The '-localhost' flag is important too.\n[Service]\nType=simple\nUser=nikhil\nGroup=wheel\nWorkingDirectory=/home/nikhil\n\nExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'\nExecStart=/usr/bin/vncserver -localhost :%i\nExecStop=/usr/bin/vncserver -kill :%i\n\n[Install]\nWantedBy=multi-user.target\n\nEOF\n\n# Tell systemd about it and bring it up at reboot. This is a single instance btw.\nsudo systemctl daemon-reload\nsudo systemctl enable vncserver@1\nsudo systemctl start vncserver@1\n\n# See some startup logs\njournalctl -u vncserver@1 -f\n\n# Now on the client, create an SSH tunnel\nssh -p 3227 -L 5901:127.0.0.1:5901 -N -f -l nikhil 192.168.1.10\n```\n\nNote that you will have to adjust the bit depth/quality on your viewer. This is not something TigerVNC controls.\n\n### Samba\n\n[This](https://superuser.com/a/1400920) was an excellent guide! Also see [this](https://linuxg.net/how-to-set-the-setuid-and-setgid-bit-for-files-in-linux-and-unix/).\n\nSetting up Samba shares was rather easy in `/etc/samba/smb.conf`. Make sure you [do this to prevent Guest Access](https://unix.stackexchange.com/a/562999).\n\n### Sanoid\n\n[Nice little Perl script](https://github.com/jimsalterjrs/sanoid) to automate ZFS snapshotting. `apt install sanoid` installs a `cron` script in `/etc/cron.d/sanoid`. Configuation in `/etc/sanoid/sanoid.conf` was as simple as this. I want snapshots of all child datasets _except_ for one and this is what my config looked like ([reference](https://github.com/jimsalterjrs/sanoid/issues/627#issue-837657066)).\n\n```\n[tank]\n  use_template = base\n  recursive = yes\n\n[tank/dataset-to-exclude]\n  use_template = none\n\n# --- Templates ---\n\n[template_base]\n  autoprune = yes\n  autosnap = yes\n  daily = 30\n  frequently = 0\n  hourly = 0\n  monthly = 12\n  yearly = 1\n\n[template_none]\n  autoprune = no\n  autosnap = no\n  daily = 0\n  frequently = 0\n  hourly = 0\n  monthly = 0\n  yearly = 0\n```\n\nSee [the options](https://github.com/jimsalterjrs/sanoid/wiki/Sanoid#options) for more info on each. Note that the defaults are `/usr/share/sanoid/sanoid.defaults.conf`.\n\n### Glances\n\nGlances v3 won't work with Ubuntu Server v24 LTS. You need v4 and need to `pip install` the damn thing. Type `glances -V` to see some info about the version and the log file.\n\n```bash\nsudo apt -y gcc lm-sensors wireless-tools\nmise install python@3.13.5\npip install --user 'glances[all]'\n```\n\nHere's the service definition:\n\n```bash\n# /etc/systemd/system/glances.service\n[Unit]\nDescription = Glances in Web Server Mode\nAfter = network.target\n\n[Service]\nExecStart = /root/.local/share/mise/installs/python/3.13.5/bin/glances -w -t 5 -B 0.0.0.0 -p 8080\n\n[Install]\nWantedBy = multi-user.target\n```\n\n## Miscellaneous Notes\n\n- I use DuckDNS for Dynamic DNS\n- No password on PiHole via `sudo pihole -a -p` followed by an <kbd>Enter</kbd>. It's how you set a password as well.\n- Found myself not being able to run more than two containers at once. [Docker Compose is strange](https://stackoverflow.com/a/39489432). Each `docker compose up` command needs to be given its own `-p`\n- To list the contents of a package, `dpkg-query -L package-name`\n- Needed to add this to get `fzf` working\n\n```bash\n# shellcheck source=/dev/null\nif [[ $(uname) == \"Linux\" ]]; then\n  [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]] && source /usr/share/doc/fzf/examples/key-bindings.bash\nfi\n```\n\n### Reset HomeBridge password\n\nRemove `auth.json` in `/var/lib/homebridge` if installed on a RaspberryPi. Else you can find it in `$HOME/.homebridge`.\nElse you can find it in `/var/lib/docker/volumes/homebridge` if running in Docker. (Else just reinstall the damn thing and keep better track of your passwords...)\n\nThen `sudo systemctl restart homebridge.service`. It's on `http://192.168.1.75:8581`\n\n### Remove Snap\n\nRuns in containers, checks for updates four times a day without my permission, is another thing Canonical can stop forcing us to use. Sources: [1](http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package), [2](https://haydenjames.io/remove-snap-ubuntu-22-04-lts/), [3](https://www.baeldung.com/linux/snap-remove-disable)\n\n```bash\n# Stop the service. You will have errors removing each snap if you don't.\nsudo systemctl stop snapd\n\n# List things to remove\nsnap list | grep -v \"^Name\" | awk {'print \"sudo snap remove \" $1'}\n\n# Remove each one.\nsudo snap remove bare\nsudo snap remove core20\nsudo snap remove core22\nsudo snap remove cups\nsudo snap remove gnome-3-38-2004\nsudo snap remove gtk-common-themesÏ\nsudo snap remove lxd\nsudo snap remove snapd\n\n# Disable things\nsudo systemctl disable snapd.service\nsudo systemctl disable snapd.socket\nsudo systemctl disable snapd.seeded.service\nsudo systemctl disable snapd.autoimport.service\nsudo systemctl disable snapd.apparmor.service\n\n# AppArmor things\nsudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real\nsudo systemctl start apparmor.service\n\n# Find a list of snap mounts and remove them\ndf | grep snap | awk {'print \"sudo umount \" $6'}\n\n# Purge snap\nsudo apt purge snapd\n\n# Clean things up\nrm -rf ~/snap\nsudo rm -rf /snap\nsudo rm -rf /var/snap\nsudo rm -rf /var/lib/snapd\n\n# Create configs for future installs like Firefox and Chromium\ncat <<EOF | sudo tee /etc/apt/preferences.d/snapd\nPackage: snapd\nPin: origin *\nPin-Priority: -1\nEOF\n\n# Make sure we're not using Snap for Firefox\ncat <<EOF | sudo tee /etc/apt/preferences.d/firefox-no-snap\nPackage: firefox*\nPin: release o=Ubuntu*\nPin-Priority: -1\nEOF\nsudo add-apt-repository ppa:mozillateam/ppa\n\n# Install things\nsudo apt update\nsudo apt install firefox\n```\n\n### Installing Google Chrome\n\nNote: do this after uninstalling snap.\n\n```bash\nsudo wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmour -o /usr/share/keyrings/google_linux_signing_key.gpg\n\nsudo sh -c 'echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/google_linux_signing_key.gpg] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'\n\nsudo apt update\nsudo apt install google-chrome-stable\n```\n\n## Backups\n\nMade sure to do this to two external, encrypted drives. All datasets and snapshots. See [these](/ZFS_and_Backups) [two](/ZFS_Notes) pages for more notes.\n\n### Creating an Encrypted Backup Disk\n\n```bash\n# Make sure it's the right disk\nsudo lsblk -o name,size,model\n\n# Wipe all filesystems\nsudo wipefs -a /dev/sdg\n\n# Create the Zpool. aes-256-gcm is the default for passphrase.\n# Using gzip compression.\nsudo zpool create \\\n  -O encryption=on \\\n  -O keyformat=passphrase \\\n  -O compression=lz4 \\\n  -O keylocation=prompt \\\n  -O xattr=sa \\\n  -O atime=off \\\n  backup-03 /dev/sdg\n\n# Export. Re-import, unlock to write to disk.\nsudo zpool export backup-03\nsudo zpool import backup-03\nsudo zfs load-key -r backup-03\n\n# Lock the drive\nsudo zfs unload-key -r backup-03\n\n# Change the key\nsudo zfs change-key backup-03\n```\n\n### Removing Encryption on Backup Drive\n\nTODO: Finish this section.\n\n```shell\n# Get the ID of the drives. It will look like\n#\n#      gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n#\nzpool status\n\n# Assume that my pool is called `backup`\nzpool offline backup gptid/66e2c3c2-2786-11ea-bc58-ac1f6b83246e.eli\n```\n\n### exFAT on Backup Drive\n\nWanted to use an 8TB external drive for backups. Didn't have much luck getting stuff formatted by `gparted` and `fdisk` and `mkfs` to work on macOS (i.e., it wouldn't recognize the partitions on the drive) so just used Disk Utility to format it.\n\n```bash\n# List all physical disks. The flag removes loops devices.\nlsblk -e7\n\n# or, for a longer and better view,\nfdisk -l\n\n# Mount the disk\nmount -o uid=1000,gid=1001,umask=002 /dev/sdg2 /backup-02\n```\n\n`rsync` with the `-a` flag will preserve permissions. This would give me `chgrp operation not permitted` errors. This is because exFAT does not support permissions 🤷‍♂️. So,\n\n```bash\n# I'm lazy and don't want to look up the exact options. Hence the\n# \"add everything and remove what I don't need\" flags here:\n\nrsync -avWHh --no-perms --no-owner --no-group --progress /source/ /backup/\n```\n\n## References\n\n- [Migrating FreeNAS ZFS Pools to Ubuntu](https://drechsel.xyz/posts/how-to-migrate-existing-freenas-zfs-pools-to-ubuntu-1804-and-higher/)\n- Mac VLANs\n  - [Fantastic Overview](https://gdevillele.github.io/engine/userguide/networking/get-started-macvlan/)   - [2 Minutes to Docker MacVLAN Networking – A Beginners Guide](https://collabnix.com/2-minutes-to-docker-macvlan-networking-a-beginners-guide/)   - [How to Create and Use MacVLAN Network in Docker](https://www.linuxtechi.com/create-use-macvlan-network-in-docker/)   - [Docker Compose Sample](https://github.com/sarunas-zilinskas/docker-compose-macvlan/blob/master/docker-compose.yml)   - [Docker Compose Networking Overview](https://runnable.com/docker/docker-compose-networking)\n- [Ansible NAS](https://github.com/davestephens/ansible-nas)\n",
  "title": "Home Server Notes",
  "untracked": false,
  "uri": "/Home_Server_Notes",
  "relativePath": "Home Server Notes.md"
}
