Some Bits: Nelson's log

43 posts about proxmox

Giving Claude the keys (Proxmox, Unifi router)

Claude Code is awfully effective if you give it full root access to a Proxmox server and/or a Unifi router. Or any Linux server. It’s scary and not a good idea for high value systems but for my low stakes homelab stuff it’s nice.

The safe way

I continue to get a lot of mileage out of using Claude Code to do sysadmin for me, particularly creating and managing containers in Proxmox. I have migrated or created some 25 containers to NixOS that Claude builds now and it’s been a great experience.

Up until last week I was doing this manually. I gave Claude limited access to Proxmox and my existing old containers, basically read-only. I did give it full root access on the containers it created. It’s been entirely responsible and effective with this access. It’s gotten old being the meat agent for Claude, pasting in commands to copy files and create containers. My eyes glazed over and I stopped reviewing the scripts it was telling me to run.

Proxmox YOLO

So I gave Claude root access to my Proxmox server. Not the important one in San Francisco where my life is hosted, just the little one I use for playing media in Grass Valley. And it’s magic. Claude is very good at doing Proxmox. It doesn’t need a skill or anything, it knows the Proxmox command line tools and APIs well.

The big surprise is Claude is quite facile with using pct enter to gain access to containers and inspect what’s going on inside them. A little alarming! But also very helpful. It also has a detailed understanding of Proxmox configurations including networking and system options I barely understand.

A small example of magic was this instruction to migrate a container:

I want to move 102 upsnap to a new nixos container you build and manage. I htink we have an upsnap container in sfpve so you can borrow from that, but you should pull the config from the new machine. there’s only one computer in it, gvld, see screenshot. I’d love it if the same password and tailscale identity and hostname were used in the new nixos system. I’m fine shutting down upsnap for some minutes while you make the new container. give it a 400s ctid.

It’s a simple task. Claude Opus 5.5 Medium handled it like a champ. It took less than ten minutes to oneshot the new system and shut off the old one. Total outage time was 46 seconds. It worked the first time. It helped that I’d trusted Claude to set up this exact same thing before and it was able to use some of its old notes. We’ve gotten good at doing NixOS containers together.

Router YOLO

The big example of magic was my network reboot that went poorly. I asked Claude “figure out what happened” and it did a good job at it. The main thing it did was use all the access I’d given to reach into systems and pull log files. Then cross-correlate timestamps to figure out what happened on my LAN. It’s all stuff I could imagine doing but it’d take me frustrating hours. Claude did it in a few minutes.

So far I haven’t let Claude make changes to my router or other network devices. I’m still just telling it what I want and then applying changes by hand. I wonder how long I’ll keep doing that.

The next big test will be in about five days when I replace my Ubiquiti router and a switch with new Ubiquiti gear. I’m going to do that process by hand, having Claude tell me what to do in the GUI. But I am wistfully thinking how nice it’d be to trust Claude to do all the work for me.

Safety

As I said above, these systems are pretty low stakes. If Claude screws up it’s not a big deal.

I have backups. Proxmox does nightly images of all containers so if something were to go wrong, I have an easy restore path. Proxmox can also take ZFS snapshots but I haven’t been using that. I am sure I could teach Claude to create snapshots when appropriate. NixOS has its own rollback too, Claude has used that a couple of times when a live system upgrade didn’t go right.

One key thing here is I’m trusting Claude not to be malicious. It would be very easy for the agent to use its access to subvert my systems, delete my backups, subtly corrupt things in ways I wouldn’t notice. But Claude doesn’t do that, it’s a tame text elemental. It only wants to help me. There’s still the risk of a mistake. Some sort of safety net is essential but it’s not as scary as I first thought.

Effect on me

I have mostly been using LLMs as partners in thinking, I’m much more comfortable collaborating with Claude to do stuff. But here I’m turning over the job entirely. I still have some influence in the way I frame requests and work on designs and requirements. But I’ve given up a lot of control. Also a lot of understanding, I really don’t understand how these systems it built work. I mean I think I know but it’s nothing like the understanding I’d have if I built them myself.

On the other hand building little containers for services like Upsnap is boring AF. Nice to not have to do the scut work.

GV network reboot: Unifi meshing, Emporia power

I rebooted my network boxes in Grass Valley today and it was a bit rough, took nearly 8 minutes for everything to come back. I rebooted by pulling the power from all the passive switches and routers I care about, also the Starlink dish. It did all eventually come back correctly.

I gave Claude access to all the systems I could and had it do a postmortem. This is my own writeup of what I learned from talking to it.

WiFi mesh loop

When the network switches went down I left the Unifi WiFi access points back up. They were configured in mesh mode, so they started building a mesh network. When the network switches came back up that created a network loop and there was a brief mess as packets flooded everywhere. The APs detected the loop after 12 seconds and turned off meshing. I’ve since disabled meshing in the network config, I never want it.

Proxmox server reboot

My little Proxmox server rebooted itself. I’m not sure why. But I did hear a power relay click. The Proxmox server is plugged into an Emporia smart network switch, so my best guess is it decided to toggle the power for some unknown and unlogged reason. Maybe it reacted badly to the network loop or just being offline for awhile? I dunno, it’s a bad failure mode! Fortunately it did turn on again. This power switch and one other fell off the wireless network and then rejoined it. Three others were fine.

Small stuff

It took my Unifi Security Gateway 3 or more minutes to boot, that was a big delay.

With the USG down nothing was answering DHCP. That wouldn’t ordinarily matter but after unplugging and replugging the switches my Linux box wanted a new DHCP lease. NetworkManager only tried to get a DHCP lease for like 45 seconds and didn’t fall back to just using the old address it had (with a valid lease). Supposedly it will retry again in minutes, but by then I’d unplugged and replugged the ethernet cable forcing a new lease.

I had to put my phone in airplane mode and back to connect to WiFi. Other wireless devices were fine.

Accessing Plex containers for Claude

I have like 20 containers in Proxmox now doing various services. I used to use Tailscale to access them all but my tailnet was getting cluttered up with stuff that only needed to be reachable for admin purposes, not regular use. This got untenable using Claude to do admin work.

The setup Claude came up with just requires LAN or Tailscale access to the proxmox host (pve). It then jumps through that via ssh to the each to container via a LAN connection. One added complication: Claude has to use an HTTP proxy for any ssh at all.

sandbox → HTTP proxy → claude@pve (over Tailscale) → ProxyJump → root@192.168.0.99:22 (the container)

Claude has its own ssh key that it’s managing. I am trusting this key with limited access to PVE and then full root access on the container. Scary but so far so good!

On PVE, Claude has a user account with a restrictive authorized_keys for Claude’s key. It limits what the key does to just proxying ssh PVE to the container. There’s one line like this for each container.

restrict,port-forwarding,permitopen="192.168.0.99:22",command="/bin/false" ssh-ed25519 AAAA… claude@desktop foo

On the container, root’s authorized_keys allows Claude in with full access.

In Claude’s shell environment, it has an SSH config with stanzas like this:

Host example
  HostName 192.168.0.99
  HostKeyAlias example-ct317
  User root
  ProxyJump pve

ProxyJump is a bit of ssh config magic that simplifies the process of sshing first into once place and then onto a second.

(I’m skipping over the details of how Claude uses the HTTP proxy to connect to PVE in the first place. This is necessary for any ssh at all to work, Claude Code seemed to have a solution for that workaround.)

This all seems baroque as I’m typing it all out (myself, not Claude) but it’s quite simple. Bottom line: Claude gets full root access to a container behind a firewall without tailscale on each container. Instead we use Proxmox as an ssh proxy but Claude only has minimal permissions on the Proxmox host.

BBR, Proxmox containers, and Starlink

I tried to sync a bunch of big data last night and only got 5MBytes/s despite 30MBytes/s being expected. The fix turned out to be enabling BBR congestion control on the Proxmox host and container I was syncing from.

In detail... I first learned about BBR congestion control three years ago. It’s an alternative TCP congestion control algorithm you enable on a server. It greatly improves performance for Starlink clients connecting to that server. Enabling BBR instantly boosted rsync performance from 5MB/s to 30MB/s for me: that is expected. It’s so extreme because of the high packet loss of Starlink. It’s probably the same for clients on cellular links.

To enable BBR in a container, the easiest way is just to enable BBR in the Proxmox host and then restart the container. On Proxmox:

# Load and enable BBR right now without reboot
modprobe tcp_bbr
sysctl -w net.ipv4.tcp_congestion_control=bbr

# Enable BBR on reboot
echo tcp_bbr >| /etc/modules-load.d/bbr.conf
echo 'net.ipv4.tcp_congestion_control = bbr' >| /etc/sysctl.d/90-bbr.conf

It is not necessary to explicitly enable BBR in containers. They will pick up the Proxmox host’s congestion control algorithm on restart. However any existing containers won’t switch immediately. You can run this in the container to switch without restarting:

sysctl -w net.ipv4.tcp_congestion_control=bbr

It is probably necessary to enable BBR in any VMs you have. I haven’t tested this but it must be this way since the VM has its own kernel and TCP/IP stack.

It is possible to have containers have different algorithms than the Proxmox server or each other. I didn’t test this but Claude Code was telling me I needed to load the modules in the Proxmox server and then set net.ipv4.tcp_allowed_congestion_control= reno cubic bbr. After than containers can choose their own algorithm.

(Claude Code was a big help in diagnosing and fixing this problem. I understand all the commands above and tested them myself.)

I continue to wonder why BBR isn’t the default on Linux. Apparently it can cause contention problems if every server isn’t using BBR. Also so much server traffic these days is QUIC and it has its own congestion control. The TCP setting doesn’t matter to a lot of servers.

Vault: my new file storage

After some 35 years of ad hoc carrying files around from place to place, I finally have all my important digital files in one well built storage system I’m calling “Vault”. More or less like a lot of people do with a NAS, but a little different.

Hardware

Vault is a Linux container running on Proxmox in SF. It stores files to three ZFS pools managed by Proxmox. One small volume for important small files on NVMe storage (two devices, mirrored). One large volume of large media files on spinning rust (again, a mirror). And one large volume of backups on spinning rust (single disk). There’s also offsite backups of everything but the video files to Backblaze B2.

Software

So far that’s pretty basic. The slightly unusual thing is what software runs on vault. Note this whole thing is LAN and Tailnet only, not on a public network. The setup was all built via AI but the big choices are mine.

  • Proxmox and ZFS for the hardware management. Tailscale for network access.
  • NixOS in a privileged LXC container for the vault operating system. Nix is my new thing for using AI to build servers. The declarative system seems a good match for coding agents.
  • No NFS or SMB. That’s the weirdest choice I made. I’ve never liked synchronous network filesystems, they are lies. It would be easy to add one of these but I don’t need it.
  • Syncthing. The most important volume I store is all my source code, about 15GB of my career over 35 years. I sync this to several different computers. I’ve been using Syncthing for years and it is a reliable workhorse. This is what I use instead of a network filesystem, particularly when working in Grass Valley.
  • sftp/sshfs. For needing to access a remote file outside of src. Purely for ad hoc use, this is very easy in the Linux Dolphin file manager. I could set up a FUSE mount too.
  • bind mounts and virtiofs. This is what allows a container on the SF Proxmox host to access the files in the Vault’s ZFS pools. Vault itself is working through bind mounts to the volumes. virtiofs is a relatively new option for the same thing for VMs. (I used to use NFS for that.)
  • Restic for backups. Both to a local disk and also offsite to B2.
  • File Browser for web access to files. Not sure I really need this, and the project just got shut down, but it’s there.
  • plocate for finding files. This is really not adequate: I have to ssh in and all it does is grep filenames. But it’s something. One big project I’m considering is some fancy full text indexing of all the contents and their metadata. That’s an endless project, I wonder if there’s something good off the shelf I can use.
  • ntfy.sh for notifications. What a great little service! I just use the public free tier, it’s enough for my needs and very easy to use

AI development

I bought the hard drives for this project in 2024. I even got halfway through building a Debian VM to manage everything, poorly, and then abandoned it because I couldn’t see a path forward to trusting this thing with my files.

I built the whole thing with Claude Code and Opus/High in 5 days.

Claude was active about 23 hours of that time. Me, maybe 10 hours? It used $205 in credits but all fit in the $20/mo subscription.

The process mostly went well. I had it come up with a design, then a work plan, then we stepped through tasks. I gave Claude more power than I have in previous projects and that was a good choice. But then I also had a lot of verification steps, including full backup tests outside Claude’s control. (I’m still trusting Claude somewhat: on my own I’m testing backup integrity and completeness but only spot checking identical files. Claude says it checked every single file.)

We made one major mistake. Part of the consolidation involved changing the UID for my files. I still have a VM that uses the old UID and so now it can’t write some files it used to be able to. (Unfortunately Proxmox’ UI for virtiofs doesn’t support any way to map UIDs.) It’s not a big deal, and I plan to shut that VM down entirely. Claude mostly was working to anticipate and avoid problems like this, as was I, but we both missed this one.

Overall the AI did a much better job than I would have. It got it done with no drama and with better testing and monitoring and backups than I’d ever manage on my own. I’m a total AI convert for this kind of project now.

Giving Claude Code the keys

I’m setting up a new server at home with Claude and NixOS. It’s a NAS-like thing for all my precious files, I’ll talk more about it later. Wanted to note here how I’m working with Claude.

In three devops projects I’ve gone from “talk to Claude and run all the commands myself” to “trust Claude to build a server VM but do all the config work by hand” to “trust Claude with access to Proxmox to create and maintain a server VM”. This Proxmox server is all my important stuff! It’s scary. But it’s also very nice letting an AI do the work.

I’m not insane, I do have backups of everything precious. A truly malicious Claude could probably destroy those backups too. But I’m trusting the agent isn’t adversarial. My goal is to just make it so an honest mistake isn’t catastrophic.

Protections

The first protection was giving Claude clear limits on what I wanted it to do. Don’t delete any data. Only work to make a single container with ID 300. Only use certain resources. Claude seems to be trying to obey those limits in good faith.

One simple protection: Claude mounted my precious data read-only to copy it into the new system. That was its idea and it’s a good one, I feel much safer that way.

I gave Claude an unrestricted ssh login with sudo access. One nice thing it did was make a very precise sudoers file. So for instance pct create 300 is allowed to create a container with id 300, but it doesn’t have general access to pct to manipulate all the containers. I’m not confident the sudo restrictions are complete. And I’m sure a malicious Claude could escalate privileges with the access it has. But it seems to help prevent accidents.

Claude has no trouble sshing to my box. I’m a little confused about this: the default sandbox restricts networking to localhost only plus one HTTP proxy. But Claude just happily writes a script to proxy ssh through HTTP (using the CONNECT command). I don’t know if this is Claude working as intended or if its entire mode of accessing my computer is an exploit.

One thing that did not work great is trying to get Claude to interactively ask me for any commands it runs as root. The new defaults in Claude let it run anything the heuristic checker approves. That’s a lot of things! Including ssh server sudo * (although there may be some restrictions on *. I want to review each command, so I overrode that by explicitly listing commands that I should be asked for. But that matching is very literal. And Claude keeps coming up with new ways to invoke ssh. So now I have something like this in the permissions file:

    "ask": [
      "Bash(ssh -F /home/nelson/.local/state/claude/ssh_config claude@sfpve:*)",
      "Bash(ssh -F /home/nelson/.local/state/claude/ssh_config sfpve:*)",
      "Bash(ssh -F ~/.local/state/claude/ssh_config claude@sfpve:*)",
      "Bash(ssh -F ~/.local/state/claude/ssh_config sfpve:*)",
      "Bash(ssh claude@sfpve:*)",
      "Bash(ssh sfpve:*)",
    ]

There’s nothing stopping Claude from coming up with yet another way to ssh into the box, bypassing these checks. Maybe this is fixable with a smarter glob, not sure.

Update Sep 21

After watching what Claude does some more I got nervous and decided to not give it this much access to Proxmox. I’m fine with it managing individual containers but Proxmox is too much.

For initial setup of a new container I’m having the agent write a shell script I run as root on Proxmox. I look at it closely. It’s basically just a single pct create in the simple case.

For managing a container that has tailscale, Claude has no more access at all to Proxmox. If the container doesn’t even have tailscale I’m giving Claude ssh access to sfpve but solely to run ssh -J to forward into the container via the local IP address. Something like this in the authorized_keys: restrict,port-forwarding,permitopen=”192.168.0.108:22″,command=”/bin/false”

Alarming behavior

Claude did two things that made me nervous.

  • Claude deleted some data despite being told to never delete data. It used rclone to remove something from Google Drive. We’d just established I had other copies of the data and wanted to delete it, so it was reasonable enough to delete the data, and really it only moved it to Trash anyway. But still, it violated a direct limit.
  • A new project went grubbing through other Claude project history, found the ssh key it had, and happily used that to give itself access to answer some questions about the Proxmox setup for something else. It was doing what I asked of it, and I did tell it to try to work autonomously and not bother me. But it got a little frisky letting itself in the door with its cousin’s keys.

Another major problem in my environment.. I use an SSH agent and SSH_AUTH_SOCK is available to Claude. I’m not sure it can normally access that. But Claude convinced me to give it "allowAllUnixSockets": true in its sandbox so it could do Nix things. That enables access to the SSH agent socket, too.

I’m currently testing giving it permission just to talk to Nix and no other sockets via "allowUnixSockets": ["/nix/var/nix/daemon-socket/socket"] but hit a snag. more tomorrow.

Proxmox secure boot: June apocalypse

The failed Secure Boot technology has a booby trap in it that might keep Linux boxes, including VMs, from successfully booting because some certificates start expiring June 24. The suggested fix is to enroll new security keys, which require a lot of BIOS fiddling. I was impressed Proxmox had a warning about this for your VMs and a tool for fixing it. Seems to work. It adds ms-cert=2023k,pre-enrolled-keys=1 to the disk options for the EFI partition.

Update: secure boot keys on PC hardware

I have some hardware I don’t have access to and I’m wondering if it will refuse to boot come June 27. Here’s some stuff you can do from a Linux CLI. RedHat also has decent docs on this.

mokutil --sb-state will tell you if secure boot is active at all. It looks like it’s disabled on both of my Linux servers. A little surprised at that, btw.

mokutil --db will show you the enrolled keys for secure boot. I don’t really know how to read all this, but you can find the problematic keys.

        Issuer: C=US, ST=Washington, L=Redmond, O=Microsoft Corporation, CN=Microsoft Corporation Third Party Marketplace Root
        Validity
            Not Before: Jun 27 21:22:45 2011 GMT
            Not After : Jun 27 21:32:45 2026 GMT

Apparently the good new key will say 2023, but I don’t have one to be sure.

Adding the new key is something you have to do in the BIOS. Installing a firmware update from the console is the surefire way. LVFS should also be able to do it, maybe as simple as fwupdmgr update. But that doesn’t seem to add a 2023 cert for me on my ASUS motherboard.

Looking in dmesg for things about X.509 certs may be instructive for what the Linux system is doing. That won’t tell you what the BIOS is doing though.

A fine rant

Secure Boot is a complete disaster. In theory it was supposed to protect against pernicious malware. In practice it’s been a complete sham since the beginning because all the implementations are deeply buggy. See here for some history on that. If BIOS malware were a real thing in practice we would have seen a lot more attacks against these buggy implementations using such things as CN=DO NOT TRUST that were trusted by every major PC manufacturer.

What Secure Boot did do was protect Microsoft’s monopoly. It continues to make installing other operating systems very difficult on PCs. About once a year I have to spend an hour+ dealing with some sort of secure boot fiasco in Linux. The most recent example: Nobara just doesn’t support it at all because they have no practical way to sign kernel packages in their build system.

So I’m disabling Secure Boot everywhere. Including in VM BIOS, what a farce. I had one old PC that caused problems if you disabled it though. If you turned off secure boot there was no way to use some other platform features, maybe the TPM? I haven’t run into that in awhile though.

Proxmox container for a Tailscale exit node

I want to set up a Tailscale exit node for me on the server with a good home Internet connection. This is a sort of poor-man’s VPN, routing all traffic through my home ISP connection. It’s pretty easy but I ran into a problem with IP forwarding.

First I set up a tiny Alpine container and used the Tailscale community script to set up Tailscale on it. You can install Tailscale by hand but this script handles the extra config needed to give an unprivileged LXC access to the tunnel device.

Then I set up Tailscale in the container to advertise as an exit node. The key thing there is sysctl configurations to enable IP forwarding inside the container OS. Very important! You also have to tell tailscale to advertise itself as an exit node.

Once I did this it worked. At least, I think it did. But it stopped working, maybe after a reboot?

To fix it, I also enabled IP forwarding via sysctl on the Proxmox server itself. I’m not 100% sure this is required or even a good idea. But when I enabled it, the exit node started working again. I’m a little confused about this but I think it’s OK.

Upgrading Proxmox 8.4 to 9.1

I updated my main Proxmox server today from 8.4 to 9.1. The big change is an upgrade from Debian bookworm to trixie. And of course lots of Proxmox changes on top of that.

This server is the one doing important work. And to make things spicy, it’s a little customized: I have it running an NFS server on the PVE host itself, with a special loop subnet for communication between the Proxmox guest systems (including NFS). I also have Tailscale installed, Proxmox has no first class support for that.

The upgrade went fine. A little scary, as always, but no real problems. They have good docs on it and a nice pve8to9 tool for testing as you go. It’s a little bit of a manual process, I don’t love running sed commands via copy-and-paste and being told “just look at the config file changes and decide for yourself what to keep”. But at its core it’s basically just a regular Debian update and that process is well tested. I did make a rookie mistake of upgrading via ssh without a screen session but I got away with it. (The upgrade process is smart enough not to kill your active ssh session!)

Little hiccups I encountered:

  • I had to hand-edit one apt source to get tailscale on trixie instead of bookworm.
  • I got a very confusing message from the upgrade about /etc/initramfs/post-update.d/systemd-boot being changed and which version did I want to keep. This issue is not in the Wiki (it should be) but it is discussed here. I went with “N”, keeping the old Proxmox version which just got stubbed out with This hookfile has been disabled by proxmox-boot-tool. I’m guessing its contents don’t matter as Proxmox overrides Debian’s boot setup.
  • After the install pve8to9 told me I should remove the systemd-boot package to prevent future upgrade problems. This issue is well documented on the wiki and removing it was fine in my case.

The boot hiccups are scary. Booting in Linux is confusing, Proxmox is doing something even trickier with its own bootstrap and booting from ZFS. And if this screws up your whole system is broken in a hard-to-repair way. But I think the underlying tools are pretty robust. The pve8to9 script also seems to have enough checks and safeguards in place it works as a safety net. I think.

e1000e: Detected Hardware Unit Hang

The Linux driver e1000e for Intel ethernet adapters has had a persistent problem for years. It can get in a state where it hangs and reports “Detected Hardware Unit Hang”. Sometimes it recovers on its own but recently on my system it started breaking my networking until reset.

Update Nov 2026: Proxmox kernel 7.0.14-28 seems to include a patch very specific to this bug.

The usual advice for fixing it is to disable hardware acceleration features on the adapter. This has a performance impact but is probably small and avoids the problems with the driver and/or hardware. A simple one-off fix of ethtool -K eno1 tso off gso off was enough to help my system, that turns off acceleration for segmentation of packets. But doing that once won’t persist for reboot, for that I like this systemd unit file. Note that script turns off a whole lot of other acceleration features too which may or may not be a good idea. See also discussion here and here and a whole lot of other places.

It’s not clear what the real underlying bug is. Some folks blame bad hardware design. But Linux drivers have lots of code for working around hardware problems, not sure why it’s such a problem in e1000e. The fact that segmentation may be a particular problem doesn’t surprise me. Segmentation is stateful: either the kernel or the hardware has to store some data while it breaks it up into packets and that probably involves locking.

The other confusion is why this bug started happening to me recently. The problem started when I upgraded to Proxmox 8.4.1 with their kernel 6.8.12-9. This bug discussion has a comment noting that one patch to the kernel didn’t get included in that build, maybe that was the problem. Proxmox has since released a 6.8.12-10 which says cherry-pick "bnxt_en: Fix GSO type for HW GRO packets on 5750X chips". But that patch is for “5750X chips”, which I think is a Broadcom part. So maybe not relevant to e1000e at all?

My guess is Proxmox had patched this problem in some kernels but it’s come back. Would love to understand why the upstream Linux release doesn’t have a fix for this once and for all. Even if it’s to default a bunch of hardware acceleration features to off in the driver.

Server outage postmortem

Some notes on a personal server outage. Highlights:

  • Smart power switches are great
  • Would love a remote console of some sort
  • Having any sort of remote shell other than the server would be nice
  • Remote Unifi is helpful
  • My Intel ethernet device / e1000e driver may have a bug
  • A second network interface?
  • I’d sure like a watchdog

I left San Francisco on the morning of Apr 18. At 2:38AM Apr 19 I got notified some of my services running on my personal Linux server there weren’t working. No problem, I thought! This is what Proxmox is for! Only I couldn’t reach the Proxmox hypervisor: the whole machine was down.

Long story short, today (Apr 22) I power-cycled the machine and it came back fine.

Smart power switch

My first thought on the 19th was to reboot the server. Then I went looking for the smart power switch I thought I’d set up and couldn’t find it. I have like 4 brands of switches and apps. And I forgot to check Emporia, the newest one. Mostly that’s my car charger but they have a nice set of smart power switches too. I finally found it this morning (while looking at a list of devices on my LAN), power cycled the machine, and the reboot worked. Yay!

Remote console

I’d sure love a remote console for this server. Something I can log into remotely. I’ve got another blog post coming on options for that, I think PiKVM might be my solution. Next time I buy a server I should buy something like an HPE Proliant with remote management.

Remote Unifi

My Ubiquiti router has remote management with a web interface. I’ve used this more than I thought I would. I used it on the 19th the moment I knew things were wrong. It let me confirm the house Internet was working and that the Proxmox host was no longer on my LAN.

Remote shell

Usually when things go wrong and I’m not home I log into a VM on my server and poke around with diagnostic tools. But with my server down I had no VM to log into. Kinda wish I had a second machine, a little RPi or something. I finally figured out you can get a remote ssh shell on the router via the Unifi console. The Linux environment you get there is very limited but at least I could run ping.

Second network

I should consider adding a second network device, a cheap WiFi adapter, just as a backup. Would be nice to bypass the ethernet switches too.

Watchdog

The root cause of the failure was the networking going down. It’d be nice if my Proxmox server had a watchdog to reboot itself. In this case the computer was fine, just not the network, so that’s a little trickier. In the past every time I’ve set up watchdogs it caused more problems than it solved. The real Proxmox solution is to cluster and use high availability, but I don’t really want to buy more computers.

Root cause / ethernet problem

So why’d it crash? I’m not certain, but here’s the big sign of trouble

Apr 19 09:06:59 sfpve kernel: e1000e 0000:00:1f.6 eno1: Detected Hardware Unit Hang:

That got logged once every two seconds once it started. tailscaled also started complaining it couldn’t connect to the network. Everything else more or less kept running fine, scheduled tasks and backups and stuff. Just no network.

Looking at my logs, this error message has been logged about 150 times in the past year and a half. But in previous times it’s been transitory, a few errors and then it recovers itself without a reboot. This last outage was the first time where it got stuck and didn’t reboot.

Looking online, this error is frequently asked about. I don’t have the stamina to read all the diagnoses of what might be wrong. I did ask some AIs though. The usual cargo cult advice is to do something like ethtool -K eno1 gso off tso off to disable various advanced ethernet device features like hardware supported checksums or segmentation. Also some thought that power management might be a problem. Kind of hate the idea of this. I thought Intel ethernet devices were well regarded and supported in Linux.

I updated Proxmox from 8.3.? to 8.4.1 a few days before this crash. If it happens again it might be a problem with this kernel (6.8.12-9-pve).

Updates

The server crashed again the same way last night at about the same time.

Apr 23 09:08:37 sfpve kernel: e1000e 0000:00:1f.6 eno1: Detected Hardware Unit Hang:

This is happening during the 2am busy cron job window, so it’s possible there’s system load involved. There’s a big backup job running of my primary VM which takes about 8 minutes. The backup does complete! And I’d hope it doesn’t generate network traffic. But who knows. FWIW I was able to run the backup job manually without causing a problem.

After that Apr 23 crash I turned off GSO and TSO and it hasn’t crashed the last two nights. Given the code I’ve read, I’m guessing segmentation is in fact the problem.

I’ve got a separate blog post just about this kernel problem.

Apr 29: got a crash late last night with GSO and TSO turned off. At 04:52:56 UTC (about 10pm local), so a few hours earlier than the previous crashes. So turning those features off helped but didn’t solve the problem. Going to try turning off many more options as in this unit file and see how I do. But still a one-off, I keep hoping Proxmox releases a fixed kernel.
/sbin/ethtool -K eno1 gso off gro off tso off tx off rx off rxvlan off txvlan off sg off

Hacking Proxmox boot process (ZFS)

I’m upgrading my main Proxmox home server from a single SSD with ZFS to two SSDs mirrored in ZFS. Some discussion here. The simple thing is just to reinstall Proxmox new but I’m going to try to do it in-place first. Either way requires careful backups.

The docs on changing a failed boot device are the in-place process I’m following. More or less. It boils down to “set up the new disk in ZFS, then run proxmox-boot-tool to make it bootable”. The blessing process is complicated. Booting with ZFS is always tricky. And Proxmox is rumored to have a special thing where it installs boot loaders on all mirror devices for redundancy. I want that with my new drive! This post is me learning about how it all works.

Summary: this worked very well and is simpler than imagined. Also Proxmox is remarkably well documented. Hurray!

How is Proxmox booting now?

A year ago Proxmox installed something that made it boot from ZFS. Works great. What’s it doing? The challenge is Proxmox has three different ways of booting and I’m not sure which mine is. These docs on using the boot tool are helpful. Some other useful docs here. I should just plug in a monitor and look at the boot process but no, I’m stubborn. The docs say proxmox-boot-tool status will show you the current boot method but the output is not illuminating.

System currently booted with uefi
4B96-7CDC is configured with: uefi (versions: 6.5.13-6-pve, 6.8.12-1-pve, 6.8.12-2-pve)

Yes, it’s UEFI, I knew that. But is that GRUB? Something else? Looking around for advice in docs and from Phind I got some other ideas to try, looking at the EFI boot options:

# efibootmgr -v
BootCurrent: 0002
Timeout: 1 seconds
BootOrder: 0002,0003,0001,0004,0005
Boot0001* UEFI:CD/DVD Drive BBS(129,,0x0)
Boot0002* Linux Boot Manager HD(2,GPT,55f108de-abfa-4dad-b478-641a6d640390,0x800,0x200000)/File(\EFI\SYSTEMD\SYSTEMD-BOOTX64.EFI)
Boot0003* UEFI OS HD(2,GPT,55f108de-abfa-4dad-b478-641a6d640390,0x800,0x200000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
Boot0004* UEFI:Removable Device BBS(130,,0x0)
Boot0005* UEFI:Network Device BBS(131,,0x0)

So that says it’s “Linux Boot Manager”, which is systemd (why doesn’t it say so?). Other docs I read suggest ZFS systems boot from a whole Linux system installed in the ESP. That may involve systemd too. In any case it probably does not involve GRUB. I finally hooked up a monitor and rebooted and saw a menu but it didn’t quite look like GRUB. I did see a message go by about EFI Boot Stub.

Bottom line: I think I’m booting with Linux Boot Manager which involves systemd and a Linux kernel on the ESP partition. Not GRUB.

It’s possible to inspect the boot stuff. It’s on partition 2, the ESP partition in a VFAT filesystem. It has stuff in it like EFI/BOOT/BOOTX64.EFI, EFI/proxmox, and loader/entries.

Identifying the disks

/dev/nvme1n1 is my existing Proxmox boot drive, a zpool with just the one disk in it. I want to add /dev/nvme0n1 to the pool and make it a mirror. But there’s many ways to name a device on Linux and you want a stable name. (Fun fact: the drives on 0 and 1 have swapped between reboots without me changing the hardware.) What’s best?

zpool status -v rpool tells me the status of my existing one disk pool.

        NAME                               STATE     READ WRITE CKSUM
        rpool                              ONLINE       0     0     0
          nvme-eui.002538b22140b542-part3  ONLINE       0     0     0

What is that EUI string? That’s another name for /dev/nvme1n1p3, the “Extended Unique Identifier”. A 64 bit ID, different from the UUIDs, serial numbers, and other identifiers I’ve used before.

I first found this same name with this query: udevadm info --query=all --name=/dev/nvme1n1. But I don’t really know what that tool is. Simpler is ls -l /dev/disk/by-id/ | grep nvme, which shows that nvme-eui.002538b22140b542-part3 is (currently) a symlink to nvme1n1p3. That I understand. So I looked for what linked to nvme0n1 and found that nvme-eui.002538bc3140272b-part3 is the name for the new SSD’s partition 3.

Adding the ZFS mirror disk

OK, time to do surgery on my machine. I am more or less following this guide.

Step 1: clone the partition table to the new disk. sgdisk /dev/nvme1n1 -R /dev/nvme0n1. After doing this the new disk has the same layout as the old one. blkid will show the partitions. (Although confusingly blkid doesn’t show filesystem types: fdisk showed they were labelled as VFAT etc, just like the original disk.) However the UUIDs of each partition are the same too which is not good, we’ll change that soon.

Step 2: give partitions unique UUIDs. sgdisk -G /dev/nvme0n1. Partitions are the same but now they have new IDs.

Step 3: attach the new SSD to the pool. zpool attach rpool nvme-eui.002538b22140b542-part3 $nvme-eui.002538bc3140272b-part3. Why attach and not add? (Edit: add expands storage, attach mirrors it.) Not sure but that’s what Phind told me to do. This pauses a couple of seconds and then returns. zpool status -v rpool shows what’s going on. The ZFS docs suggest that “attach” is a special thing that only directly mirrors devices. I would have guessed zpool add would have been the command to use but that seems to be a more general purpose thing for other configurations with vdevs and maybe RAID-Z.

  pool: rpool
 state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
        continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
  scan: resilver in progress since Sun Oct 27 19:49:41 2024
        114G / 114G scanned, 2.24G / 114G issued at 2.24G/s
        2.31G resilvered, 1.97% done, 00:00:49 to go
config:

        NAME                                 STATE     READ WRITE CKSUM
        rpool                                ONLINE       0     0     0
          mirror-0                           ONLINE       0     0     0
            nvme-eui.002538b22140b542-part3  ONLINE       0     0     0
            nvme-eui.002538bc3140272b-part3  ONLINE       0     0     0  (resilvering)

Just a bit later it reports resilvered 116G in 00:01:02 with 0 errors on Sun Oct 27 19:50:43 2024. Nice! These SSDs are fast.

At this point the ZFS stuff is all done. The system reboots fine. I did a zpool scrub for good measure and it reported no errors. I’m now getting most of the benefits of ZFS mirroring for data integrity. However there’s still only one boot device: if that fails, I’ll have to recover with some other boot media.

Installing boot stuff on the new disk

Proxmox has extra stuff for making boot more durable. proxmox-boot-tool manages it. See docs here.

Step 1: I verify that the new disk doesn’t have a boot ESP partition. Device names have changed on me after I rebooted, so /dev/nvme0n1p2 is the original bootable partition. /dev/nvme1n1p2 is the new one.

# old=/dev/nvme0n1p2
# new=/dev/nvme1n1p2
# mount $old m
# ls m
EFI  loader
# umount m
# mount $new m
mount: /tmp/m: wrong fs type, bad option, bad superblock on /dev/nvme1n1p2, missing codepage or helper program, or other error.
       dmesg(1) may have more information after failed mount system call.

Step 2: format the ESP on the new disk. proxmox-boot-tool format $new. After this there’s a brand new VFAT filesystem on the partition, it is empty.

Step 3: get Proxmox to install its boot process on the new disk as well as the old. proxmox-boot-tool init $new. This copies all the kernels, etc to the new disk and enrolls it so updates should be written to it. After running this both disks have nearly identical boot partitions.

Step 4 (option): refresh. proxmox-boot-tool refresh. Just a sort of verification thing, shouldn’t be necessary, but it writes the kernels again to all enrolled disks.

Rebooting

It works! On reboot it just loads like nothing’s changed.

In the BIOS I now see more EFI boot options. Linux Boot Manager is now on both disks, other entries are also doubled. The EFI boot menu is totally rewritten and has two extra entries.

# efibootmgr -v
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0002,0003,0004,0001,0005,0006
Boot0000* Linux Boot Manager    HD(2,GPT,63a5e06a-3206-4a55-957c-0878a2275a8c,0x800,0x200000)/File(\EFI\SYSTEMD\SYSTEMD-BOOTX64.EFI)
Boot0001* UEFI:CD/DVD Drive     BBS(129,,0x0)
Boot0002* Linux Boot Manager    HD(2,GPT,55f108de-abfa-4dad-b478-641a6d640390,0x800,0x200000)/File(\EFI\SYSTEMD\SYSTEMD-BOOTX64.EFI)
Boot0003* UEFI OS       HD(2,GPT,55f108de-abfa-4dad-b478-641a6d640390,0x800,0x200000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
Boot0004* UEFI OS       HD(2,GPT,63a5e06a-3206-4a55-957c-0878a2275a8c,0x800,0x200000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
Boot0005* UEFI:Removable Device BBS(130,,0x0)
Boot0006* UEFI:Network Device   BBS(131,,0x0)

The real question is what happens if the boot disk fails. Will the system still boot? In theory yes, if you have ZFS mirrors and Proxmox’ magic boot setup. I don’t want to pull the M.2 drive in my machine to test it so I don’t know if it works. There’s two genuine looking boot partitions both listed in the EFI boot menus so I think odds are good.

Things that cause hangs in Proxmox boot / shutdown

I love how Linux has (mostly) fast reboots, 10 seconds or less. So I’ve noticed some slow reboots, a minute or more, that are annoying. What’s happening?

One challenge: when you tell Proxmox to reboot it shuts down all the Proxmox PVE stuff like the Web GUI. That happens immediately. It also asks all the guests to also shut down (maybe at the same time) but that takes longer. Only now the UI is gone so you can’t see what’s happening. I only got some insight by staring at a console plugged in and then reviewing logs.

Another awkward thing: the “shut down all guests” task has no timeout from Proxmox. If one of your guests refuses to shut down I think Proxmox doesn’t reboot, just stays in a mostly-dead state. (Edit: maybe not, the docs mention a 180 second default timeout.) That makes sense in a high availability environment but is not great for my home single server. I don’t think this has ever bitten me but I have everything plugged in to an Internet power switch for just this eventuality.

Slow VM shutdown for a Linux guest

One thing I noticed is shutdowns sometimes take a minute+. The culprit is my big work VM takes forever to shut down Why? It NFS mounts a disk from an NFS server that’s running on the Proxmox host itself. So if the NFS server shuts down first, the client has a hard time unmounting it. (A weakness of NFS). The unmount does eventually time out after 90 seconds and the shutdown proceeds, but it’s a problem.

The root cause here is me running an NFS server on the PVE host: that’s not a great idea. But there’s a similar possible problem if the NFS server is in one guest, the client in another. Proxmox doesn’t do any sort of dependency inference itself although you can manually configure it. At least you can make a guest dependent on another guest, you can’t make it dependent on a rogue NFS server you installed on PVE itself.

I don’t have a fix for this now. I’m working on moving the NFS server to a guest, will revisit then.

Slow boot of Proxmox

Another problem I had started after I added a USB disk as storage, then unplugged it. On boot Proxmox waits to mount that disk again. It times out after 90 seconds. Fair enough but awkward.

Doubly awkward is it kept happening after I had removed the USB disk from the list of storage options. The disk is no longer referenced, why are we waiting? Turns out the mount job was left enabled. That may be a Proxmox bug? I manually disabled it with systemctl disable mnt-pve-extbackup.mount.

Vault: towards my own NAS

Working on rationalizing my file storage now that I’m in a Proxmox universe. The idea here is to put all my important stuff on a NAS VM running the following services:

  • NFSv4
  • Samba
  • Syncthing
  • Restic with BackRest

I’ve got a basic cut at it working (other than Samba) and it seems good. Some notes on what and why.

Contents

What am I storing on the NAS? Very little right now, but the plan is:

  • 14GB of source code. Most of this never changes and it’s mostly small files although some 1GB data blobs sneak in occasionally.
  • 7GB of Windows Documents. Random stuff here but it’s helpful to sync and backup.
  • < 1GB of files on mobile devices. I use Syncthing to get stuff off my Android devices.
  • 4TB of Media archives. NFS and SMB mounted locally. No Syncthing, no backups. Right I am manually rsyncing them occasionally to the second house. I may migrate this to backups (local only, Backblaze is expensive) and Syncthing.

Access over the Internet

The challenge here is I want my files accessible over the Internet, because I have two houses. My house with Starlink is 50ms away from the house with the server (and Sonic fiber). NFS and Samba are only good for LAN access. Those network file systems sorta work over the Internet but it’s slow and awful.

So instead I’m using Syncthing to maintain a working copy of files on my local machine. That makes my setup a lot like what Dropbox or other cloud drives is doing. I’ve done it for years with important stuff including all my source code and it’s worked fine. A key thing here: I am almost never modifying files in two places at once. Syncthing has a conflict resolution system for that but it’s a little primitive.

I’m using Tailscale for now to access the Syncthing server on the vault. That shouldn’t strictly be necessary.

Storage medium

Where are my files stored? On virtual disks that Proxmox provides. Those virtual disks are allocated on a ZFS pool that Proxmox maintains. That way the NAS VM doesn’t need to use ZFS directly, instead it just puts an ext4 filesystem on the virtual disks and it’s simple.

It’s a little weird that ZFS doesn’t see the individual files and the NAS is unaware of the ZFS pool status. But it turns out almost all the advantages of ZFS operate at the block level. Proxmox creates the virtual disk as a ZFS dataset, a block device, and ZFS will happily snapshot and compress and checksum and self-heal those blocks for me. There are a few filesystem-level ZFS features (like ACLs) but I don’t really care about them, so not having them in the NAS is no big loss.

The other option would be to pass through raw disk devices to the VM and let it run a ZFS pool itself. That’s more like what a TrueNAS setup does.

Still on the fence about what physical media I’ll use. So far I’m doing it on a single SSD in the Proxmox server. I think a pair of spinning disks with mirroring makes sense for the media archive but might be a little slow for the NFS clients accessing the source code.

I’m using Restic (with Backrest) for two sets of backups. One of everything to local disk, an extra disk in my Proxmox server. (See this pattern). One leaving out the media archives to Backblaze.

Product design

So far I’m at the “hack config files” stage of building this out. And that’s fine. Backrest and Syncthing already offer Web GUIs. I’d like to streamline the NFS and Samba configs so I don’t have to keep re-referencing the same disk volume over and over in several config files but eh, whatever. I could imagine making this into an actual product other people could use but it’d take a lot of configuration and testing. The VM might also make a good NixOS project.

Why not Cockpit for a GUI? It might actually be a good idea, I’ve never tried it.

Why not TrueNAS or OMV? Partly because I don’t like either very much. Also because neither supports Restic or Syncthing. You can install them in the VM but it’s kind of a kludge and really, I’m OK just managing NFS and Samba myself. TrueNAS can also manage a ZFS array which would be a different storage solution than what I’m doing.

As always with hacker projects there’s a lot niceties of monitoring and alerting I should be doing but haven’t set up yet. At least Proxmox ZFS will tell me if something catastrophic happens to the data.

Wrinkles

One problem with any NAS is managing file ownership. The POSIX file model is very clear for ownership and permissions. But SMB kind of screws that up. And so does Syncthing: it really wants to run as a single non-root user. (Although it has some support for multiple owners). For now I’m going to stick with POSIX files but they’re all just owned by me. That’s a good match for my data. OTOH I am allowing NFS clients to be root on the server, so maybe I can do more when Syncthing isn’t involved.

NFS still sucks for clients when the server fails. I’m mounting with noauto,x-systemd.automount,x-systemd.idle-timeout=60,soft,timeo=15,retrans=2 which first of all, lol, why aren’t the defaults adequate? And x-systemd really? But it seems to work; if the server is down the client will throw an error in under a minute.

Setup details.

The Vault VM is set up to use two vCPUs and 2GB of RAM. There’s a 4GB disk for the system volume (including 0.5GB of swap) and then as many user data volumes as I want.

I’m running Debian 12 on the VM with just the basics installed: nfs-kernel-server, samba, syncthing, backrest. The system seems to be using an actual 400MB of RAM, very little. I think the most RAM-hungry thing is Restic, it likes to do a lot of housekeeping when de-duping backups etc. It might make sense to give more RAM to the NAS just for it to cache files its serving.

Right now I’m mounting the datasets on virtual disks into /mnt/UUID, big ugly names. Then I have a second fstab entry to bind mount from /mnt/UUID to /export/friendlyname. Trying to reference the datasets everywhere else with the /export name.

Some specifics:

  • /etc/interfaces: modified to add 192.168.240.* subnet for sharing within Proxmox
  • /etc/fstab: edited to mount disks into /mnt and bind mount into /export
  • /etc/exports: individually names each /export filesystem so NFS will send them
  • /etc/default/nfs-kernel-server was modified to be NFSv4 only. Debian has some docs on this but they seem to be badly out of date.
  • Backrest config is mostly in ~root/.config/backrest, also the systemd unit file. The GUI manages that.
  • Syncthing runs as user nelson via systemd user (with loginctl linger enabled so it runs without me being logged in). The GUI manages configs, they are stored in /home/nelson/.local/state/syncthing

Setting up Gotify with Proxmox

Continuing my search for some sort of notifications infrastructure, I set up Gotify to use with Proxmox and other services like BackRest so I get messages in a central place from my servers when things go wrong. I don’t love Gotify but it’s what works with Proxmox so I’ll start there.

The goal here is to get https://example.com/gotify/ working both for the Web GUI and as an endpoint for Gotify clients including a message destination and the mobile app. I used to use Tailscale but it’s nice to have the Gotify server on a publicly accessible address. It looks designed to be secure for that.

Step 1: install Gotify as an LXC container in Proxmox with the tteck script. This ships with no config file but the defaults are reasonable (you configure passwords and stuff in the GUI). Note that means no SSL support. Gotify actually has reasonable SSL including Lets Encrypt integration but I didn’t use it.

Step 2: use Caddy as a reverse proxy to forward to Gotify. Not necessary but useful for my setup where I have a public Caddy server brokering access to other stuff. The Caddy config is a bit fiddly but is well documented here. Caddy has to strip the URL prefix so Gotify doesn’t see it.

Step 3: configure a new application in Gotify and make note of the token.

Step 4: in Proxmox go to Datacenter > Notifications and add a new target. Paste in your token. The URL will look something like https://example.com/gotify. Note the lack of trailing slash: if you leave it in both Proxmox and Gotify are dumb about it and you get a confusing error. Press “Test” to verify the messages get through.

While I’m here... looking for a good solution to get notifications in Gotify from emails. There’s a zillion SMTP-to-Gotify gateways out there that obviate the need to have actual working mail delivery. This one looked promising on last review, simple and updated recently. I haven’t tried it. It doesn’t seem to have any sort of authentication so a bit worried it’ll collect spam if you run it on a public address.

Update: a quick test shows smtp-gotify works fine for email. I built it as a Go program and then just ran the binary, configured via a few environment variables. The Dockerfile in the project helped figure it out. The simple way to use it is set it as you SMTP host to send mail to. Which I’ve forgotten how to do simply in random Linux machines, need to read up on it.

Using a simple USB disk for Proxmox backups

Trying a delicate thing here. I have a USB disk I want to write backups too. Mostly I want to back up precious data from a Proxmox guest system (an OpenMediaVault VM with user files, backups written to it with rsync and restic). I also want Proxmox to write backups of guest systems to it. There’s a bunch of ways to do this.

I decided to complicate it by having a constraint of simplicity. It’s important to me that the USB disk with the backups be as simple and ordinary as is realistic. That means no ZFS, no QEMU virtual disks, no weird partitioning. I want the USB disk to be as simple as possible so someone could plug it in to Linux box and get the files off it.

The solution I landed at was to use GPT partitions and ext4 filesystems. There’s a 1TB partition for Proxmox, it will connect it to storage as type “directory” and write backups to it. And there’s a 10TB partition for the OMV VM to write backups to with software running in the VM. It seems to work!

Preparing the disk partitions

This is all generic Linux stuff. I used gdisk on the PVE host to partition the disk. I just used fixed partitions: I didn’t use LVM or something to make the partitions more flexible. I also didn’t use any Proxmox tools to set up the storage because they all seemed complicated or unsuitable.

1TB Proxmox backup partition

This part’s also pretty generic Linux. I made a filesystem with mkfs.ext4 /dev/sdd1. Then I edited /etc/fstab on the PVE host to mount it:

UUID=6ad88c2a-3a59-4d8f-a887-344e69c6711d /mnt/12tb-backup-usb ext4 defaults,nofail,x-systemd.device-timeout=15s 0 2

I don’t love this part, I’d rather not customize Proxmox config files. But this seems unavoidable, Proxmox doesn’t have a managed GUI for “just mount this partition for me”. The fstab works fine, I’ve done something similar on another server for most of a year.

Once I mounted the new filesystem I used the Proxmox GUI to add a new Storage named “usbbackup” of type “Directory” and pointed it to /mnt/12tb-backup-usb. Now Proxmox’ backup systems will write backups to it. Yay!

10TB OMV partition

This part is trickier. Conceptually it’s not hard: I just pass through the disk partition to the VM for it to use. But it’s a little weird.

First thing is finding the partition. I don’t want to name it /dev/sdd2 on the Proxmox host because that could change. I finally figured out it has a more stable name in /dev/disk/by-partuuid/. Not /by-uuid/ which you normally use, that’s for filesystems and we don’t even have one yet, we want the partition.

There’s no way in the Proxmox GUI to pass through a partition to a VM guest. It’s got a great GUI for creating virtual disks or passing hardware devices. Fortunately there’s docs on how to do it with the command line. The command I used is:

qm set 101 -scsi2 /dev/disk/by
-partuuid/14db8691-9229-407f-bb55-a693c1a92f70,iothread=1,backup=0

Note I added options for iothread=1,backup=0. That matches the other virtual disks that Proxmox created for me, and I think those are good choices. (More efficient I/O and don’t include the disk in Proxmox backups.) Here’s what my virtual drives look like in the GUI afterwards. The other two disks are QEMU images Proxmox manages for me.

With this done the 10TB partition /dev/sdd2 that Proxmox has now looks like /dev/sdc in the OMV VM. Note there’s no partition number, as far as the VM knows that device is a whole disk and not just a single partition. But I don’t want to make a partition table in that /dev/sdc. I think you can nest GPT partitions but that complicates things.

So instead I just ran mkfs.ext4 /dev/sdc inside the VM to turn the whole (virtual) disk into a filesystem. Then it shows up in /dev/disk/by-uuid and OMV can also mount it and use it via the GUI. I probably could have used OMV to create the filesystem, for that matter.

As an extra test I also shut down the OMV VM and then mounted the partition temporarily on the Proxmox host. Just to verify I could read the files. A real test would be to take the drive to a different computer entirely but that would require me driving somewhere to touch it.

I love how flexible all these systems are. Also appreciate being able to mix my old school sysadmin knowledge with some modern virtual systems stuff. It’s all quite productive.

Accessing a Proxmox guest in ZFS from a rescue disk

Testing disaster recovery: what if my Proxmox server dies and I need to get data from a VM disk stored in it in ZFS? The simple thing is to boot Proxmox and use it to recover. But what if I don’t want to use Proxmox to get at my files? It’s possible, at least in theory, using generic ZFS and QEMU tools. I tried this and it seemed to work.

(An aside: I harshly unplugged my ZFS pool disks while Proxmox was running, then plugged them in later. Proxmox didn’t handle this very well, I ended up having to reboot the Proxmox server and then everything was back with no drama.)

Part 1: import the ZFS pool

The first step is to get the ZFS pool online in a rescue environment.

  1. Boot systemrescue-zfs on some computer.
  2. Plug the drives from your ZFS pool into the rescue machine
  3. Run lsblk to see that the drives are present.
  4. Run zpool import to see a list of pools. Your Proxmox pool should be there. Proxmox creates rpool on install, you may have others.
  5. Run zpool import -f poolname to import the pool.
  6. Run zfs list to see what the pool has in it

At this point any normal filesystems in Proxmox are mounted somewhere in the filesystem and you can cd to their directories, copy them as files, etc.

Part 2: access the QEMU virtual disks

I’m after data that’s in a guest virtual machine’s disk. And those aren’t stored in normal files. Instead they are stored in ZFS datasets with funny names like rpool/data/vm-100-disk-1. They are in QEMU disk image format. (I think raw, not qcow2, but I am not certain.)

There’s several options for what to do next. You could zfs send the data somewhere safe. In Proxmox you could access the virtual disks with the qm command line tool. There’s probably a way to use qemu-img dd to get your data. But here in systemrescue-zfs I’m going to mount it via a network block device.

I’m a little out of my depth here but I bashed my way into getting access like this

  1. cd /zvol. In here is filesystem access to the ZFS datasets (as symlinks to block devices)
  2. Find the virtual disk you want, say vm-100-disk-1
  3. qemu-img info vm-100-disk-1 to see if there’s a plausible disk image there.
  4. modprobe nbd max_part=8 to load a driver for network block devices
  5. qemu-nbd --connect=/dev/nbd0 vm-100-disk-1 to make the QEMU disk available as /dev/nbd0. Note this is the whole disk, not just one partition.
  6. fdisk /dev/nbd0 -l to see the partition table of the virtual disk
  7. mount /dev/nbd0p1 /mnt/hope to mount the partition 1 filesystem as /mnt/hope.
  8. cd /mnt/hope and there’s your stuff!

Proxmox notifications: gotify, email

Proxmox sends emails for important notifications, there’s nice docs. But email sucks in 2024, I have no idea how to get mail like this delivered. The only other option Proxmox supports is Gotify. I wish it had some generic HTTP post or something simple, looks like the Proxmox devs are adding webhook endpoints. ntfy.sh seems popularly requested but can be supported in a webhook. See also apprise and UnifiedPush.

Gotify

Gotify is a little self-hosted server that receives notifications and does things with them. It has very nice docs. Gonna tinker by installing it in an LXC in Proxmox. This server should really be hosted elsewhere, ideally a cloud service, but those seem to start at $9/mo so let’s just hack in a container for now.

Installing was easy with the tteck script. I added tailscale and had to manually wangle the LXC config to allow access to the tunnel device, per usual. With that gotify’s web server was available. The default login is admin/admin.

AFAICT tteck doesn’t install any config script. There’s a systemd unit to start it and the software is in /opt/gotify. I think /etc/gotify/config.yml would be a reasonable place for a config. It actually seems OK with no config file? It must have reasonable defaults, like sqlite3.

Getting Gotify up and running with Proxmox isn’t too hard. You create an application, take the token, then set up a notification destination in Proxmox. I also told Proxmox’s notification matcher to deliver to gotify. Test messages post immediately and are visible in the webapp. The Android app works but I don’t like the design: I want something else connected to Gotify and just delivering push messages to my phone.

I could also use some other delivery options. Deliver to RSS in particular. There’s a bunch of plugins and contrib stuff. No Atom or RSS! There’s a Slack plugin but it’s 5 years old and doesn’t work with modern Slack tokens.

Lots of interesting plugins for receiving notifications too. A zillion RSS receivers. Support for webhooks, yay. Also an SMTP gateway. Also appreciate this reverse proxy so I could use a public IP instead of Tailscale.

I dunno, I’m left thinking the core Gotify message router is pretty good but usability and features are not. The default message view is very limited (no time filtering, doesn’t even show the application). The Android and other delivery options look limited. I’ll keep using Gotify for now because it’s all Proxmox supports but once PVE adds webhooks or something I should re-evaluate.

Email

The default configuration has you specify an Internet email address that root mail should be forwarded to. But they don’t do anything to actually help you get email delivered. The default config will gamely just try to SMTP deliver the mail but of course no modern mail system relays mail from strangers. The mail just disappears into a postfix queue until it times out.

How about local delivery? I first tried making root’s forwarding address root, the empty string, root@localhost, or other variants. None worked: either invalid or a mailer loop. I then fixed it by removing ~root/.forward. Now postfix will write to /var/mail/root. Not ideal but at least it’s not disappearing.

Another local option is to create a second user account on the PVE host (like “nelson”) and forward root’s mail to it. But I’m trying to avoid that.

Remote delivery should be possible, in the past at least it was possible to get Gmail to relay mail for you if you were authenticated enough. But every time I look at doing that it gets harder. Screw it.

Migrating Proxmox to a new install

After my Proxmox disk failed I managed to clone the disk before it died entirely and boot from it. But that’s temporary hardware, now I want to set up Proxmox again on a new permanent disk, a 256GB 970 EVO I had lying around.

I’ve decided to go for a full rebuild, installing PVE and configuring it as if new. Then restoring all my guests from a backup. There’s a simpler path where you just restore /var/lib/pve-cluster/config.db /etc/hosts /etc/hostname but I kind of want to redo the setup. I did this before in January for a different server. This post is my boring careful notes here on exactly what I did.

Backing up old host

First thing is to back up everything on the old host disk while the old host is still working. I stopped all the guests and did a full backup of every single one. This is the precious data, what I’ll be restoring.

Second is to back up /etc and /var/lib/pve-cluster/. Note that /etc/pve is special and backed by a live-mounted database in pve-cluster. I’m backing up the stuff in /etc/pve as if they were normal files (for future diffing) and taking a backup of the database with sqlite3 config.db ".backup 'config.db.backup'.

After shutdown I’m going to unplug the old host disk for safekeeping, if things go badly I can use it to restore. Note it’s awkward to read the files on it because after you install a new Proxmox you end up with two ZFS pools named rpool that both want to mount to /. zpool import -d -R should help with that but I found it tricky. Instead I’ve backed up the files I want to read to the backup disk.

Installing new Proxmox PVE server

Do the regular Proxmox install from USB. There’s very few options there, I love how simple the Proxmox installer is. But this is what I did:

  1. ZFS RAID0 as the filesystem, with the one internal SSD
  2. United States, UTC timezone, US English keyboard
  3. Password and email as nelson@monkey.org even if I never have set up outgoing mail
  4. Hostname gvpve. Verify IP address is correct (thank you DHCP).

Improving Proxmox install

These are my generic customizations to any new Proxmox install

  1. Add my ssh key to ~root/.ssh/authorized_keys. Don’t disturb the key for root PVE made!
  2. Run the tteck helper script “Proxmox VE Post Install” and accept all defaults. This does a few things to make a new install nicer.
    • enable no-subscription repositories
    • disable the nag message
    • disable the high availability services (pve-ha-lrm, pve-ha-crm, corosync)
    • software update to Proxmox (takes a few minutes)
  3. Reboot
  4. Install some useful software. apt install joe sudo avahi-daemon
  5. Install tailscale. Start with tailscale up --accept-dns=false. Disable key expiry in Tailscale console.

Restoring my guests

Proxmox can do all this automatically if you have a cluster, this task just becomes a migration. (Automatic, if you have HA configured.) But it’s nice to do it manually as a recovery exercise.

  1. Plug in the USB disks for backups and USB media and verify with lsblk
  2. Restore /etc/fstab mounts for these disks (look at backup file from old server).
  3. Mount /mnt/backup and /mnt/usb-media
  4. Under Datacenter > Storage, add my Proxmox backup volume
    id: backup, type: Directory, Content: VZDump backup file, Path: /mnt/backup
  5. Remove “backup” as a content for the storage named “local”
  6. Under Datacenter > PVE > Backup, locate the files for the backups I took just before shutting down old host
  7. Restore each one manually (a lot of clicking!). Re-type the guest IDs instead of taking newly assigned ones. Probably unnecessary.
  8. Reboot to start all the relevant guests.

The restores all went pretty well, Proxmox backs up the configuration of the guest as well as the guest’s disk images. For some reason the config for a TrueNAS VM changed, it added back the ISO for the install media. This could actually break the guest although it’s easy to fix. The vmgenid also changed on every VM.

Finishing up

  1. Add my Influx DB as a system metrics server
  2. Create a new backup job on Proxmox
    All guests, 9am, keep 6 monthly / 4 weekly / 7 daily
  3. Test a manual backup. MISTAKE. The daily retention policy means this manual backup erased the reference backup from earlier today. I’d already used those to restore all my systems, so it’s probably no big deal, but definitely not the right thing to do.

I tried diffing the old server’s /etc/pve (on backup disk) to the new one. Didn’t learn anything really. Lots of differences but most of them are what you’d expect, new security keys. Also missing config files because I looked before I restored the guest hosts. I did spot the config change for the TrueNAS VM though, still puzzled by that.

Proxmox split disk idea

A setup I did not pursue, but seemed an interesting idea.

Proxmox by default installs itself to a disk and takes over the whole disk. You can set it up with ext4 (LVM) or zfs and use that disk usefully for guest disk images, ISOs, backups, etc. But the whole thing belongs to Proxmox.

What if instead you install Proxmox to a small partition, it only needs 16GB. And then allocate the rest as a ZFS pool? That seems like a clean separation. It also means you can use ext4 for Proxmox which might make recovery simpler.

I went down this road, following notes similar to this guy. I told Proxmox to install to 32GB ext4. It creates a partition #3 with LVM. Inside is 3.8GB for swap, 13.6GB for root, and two 11.6GB marked “pve-data”. The rest of the disk is then unused.

So I used fdisk to add a partition of type bf01 (zfs). The next step would be creating a zpool on it, then telling Proxmox to use that as storage for things. But I realized in the end I’d just be replicating more or less what Proxmox does by default with a ZFS install, only with non-standard names and setup for questionable benefit. So I stopped.

There’s something vexing about systems having very capable but unreliable SSDs as their install drives. I want to use that storage better!

Some ZFS exploring, disk recovery

My BOSGAME N100’s boot SSD failed. So I learned some ZFS to recover the files. I don’t think too much important is on this disk. Proxmox has been faithfully backing up system images to another drive and I have no reason to doubt them. But I’d like to rescue the Proxmox system itself, particularly since I don’t remember what all I customized on it (and don’t have a backup).

Summary

This post is more scattered than usual and unlikely to be interesting. This is what I learned:

  • You can boot off a dd clone of the Proxmox ZFS boot disk and it will work fine.
  • My disk failed with random access reads but I could use dd to clone it still. Weird.
  • You can recover the files on a ZFS pool with a system rescue disk. The key command is zfs import which brings the pool online in a new operating system.
  • zpool list and zpool status give you basic info. zdb is useful if you can’t get a pool online
  • Cheap SSDs are not to be trusted.

Lots of details

The big help here was the SystemRescue-ZFS fork. That’s the venerable Linux SystemRescueCD modernized and with ZFS installed for you.

ZFS docs are confusing. There were a bunch written really well by Sun and/or Oracle in the early days. But that was over a decade ago. OpenZFS has good man pages but I’m missing an overall gestalt of understanding the system. And ZFS is complicated, it’s a comprehensive implementation of a lot of data storage concepts.

Claude was a big help for me exploring ZFS. So was this StackOverflow post which has some recovery commands to try. And this recovery book was mildly helpful but is mostly about how to recover from partial failures where your pool still exists. My whole pool is gone because I’m using ZFS on a single disk, shame on me. These Proxmox docs for ZFS are also helpful.

One ZFS concept I’ve learned: ZFS doesn’t really have fsck. It’s constantly fixing itself (hopefully), there’s no big check-the-thing-offline. (scrub is the closest it gets.) A second concept I’m only getting now: ZFS has a notion of “imported” pools, where the ZFS system becomes aware of some storage. It’s a little like mounting a filesystem but it is not just mounting into Unix namespace, it’s also enabling all the access to the pool, datasets, filesystems, etc.

Another key concept: Proxmox creates a ZFS pool called rpool for its system boot disk. That’s what’s not working for me.

Using SystemRescue

SystemRescue is great, and the ZFS fork is perfect for me. Try setfont -d if the console font is too small. Remember that Linux lets you have multiple console windows: Try Ctrl-Alt-F2 to switch to window 2. Even better set a root password and then systemctl stop iptables.service so you can ssh in from a humane terminal emulator.

Cloning the bad disk

I suspected hardware failure so first thing I did once I had the rescue system booted was dd if=/dev/sda of=/dev/sdc bs=1M to do a block by block clone of the disk. This worked with no hitches, suggesting maybe the disk is not entirely gone. I unplugged the backup, that may be crucial since ZFS might be confused by having two copies of the same pool.

Exploring the problem disk with SystemRescue

I booted SystemRescue and first thing I tried was zpool status. It says no pools available. Same thing with zpool list. Um, is that bad? (I’d briefly tried Proxmox rescue too and it said the same thing). So I asked some AIs to go deeper and got to the ZFS debugger. zdb -lu /dev/sda3 does find some ZFS labels and stuff that I need. So the data is there and at least a little ZFS-shaped.

Asking more AIs I learned that you have to “import” a pool: presumably this SystemRescue ZFS system has never heard of this ZFS pool and so didn’t import it. Sure enough zfs import finds my missing rpool. It doesn’t want to import it by default because it wasn’t cleanly exported by some previous system. But I can zfs import -f rpool to force it. Which I have done and it takes an alarmingly long time to respond! What’s it doing? After a couple of minutes it gives up and says cannot import 'rpool': one or more devices is currently unavailable. That’s bad right?

Yes, it’s bad. journalctl has the news. The kernel module ata2, the driver for the SSD, is reporting errors. A lot of them, but the bad ones are failed command: READ FPDMA QUEUED, hard resetting link, COMRESET failed, and eventually ata2: reset failed, giving up. At which point zio and sd 1:0:0:0 start complaining about read errors. Also I have to reboot now, /dev/sda is no longer a working device.

This sure seems like a hardware failure to me! I wonder why the dd worked though? Maybe it’s just random access reads that fail? Or maybe zpool import was trying to write and it’s the writes that are failing? But those errors were triggered by reads... I tried again with zpool import -o readonly... and got the same errors. I think this disk is cooked.

Exploring the cloned image

I took a gamble and tried to import the backup cloned disk image disk. It worked immediately! zpool import -o readonly -d /dev/sdc3 -f rpool. Note I’m using the -d option to specify what device to import from because I think I have two different disk devices with an rpool on them (one of which is offline.) Also that readonly turns out to be a lie.

I think zpool import tries to mount all the filesystems where they were last time. But there was some error about rpool/ROOT/pve-1 not mounting, I assume because it wanted to mount to /. So nothing mounted. I can manually mount other filesystems with zfs mount but I really need pve-1 and it really wants to mount to /.

In theory zpool import -R /tmp/restore should mount everything under /tmp/restore. But I kept getting confusing errors. I finally got the thing mounted by doing zfs set mountpoint=/tmp/rr rpool/ROOT/pve-1. Which mounted it under /tmp/restore/tmp/rr, not what I wanted, but close enough. (Note this edit was permanent, written to the disk, despite the pool being imported readonly. I had to undo it later.)

Anyway all this hackery later and I have access to my files! They are mounted and I can make a backup of my Proxmox boot disk.

Backing up Proxmox PVE itself

One annoying thing about Proxmox is it has no system for backing up Proxmox itself. Everyone says “don’t customize it, just run guests and back those up” and mostly that works but still, it’d sure be nice to have a backup for situations like this.

Here’s a five-year-old gist backup script. The discussion there is more valuable than the script. It backs up a bunch of stuff in /etc one by one. Me, I just took all of /etc.

The Proxmox docs for Recovery are also useful. They suggest backing up /var/lib/pve-cluster/config.db /etc/hosts /etc/hostname.

Big gotcha here: a lot of configs are in /etc/pve. But those aren’t normal files stored in ZFS. Instead that’s a FUSE filesystem Proxmox runs (keyword pmxcfs) so in my non-running system here /etc/pve is empty and my tar got nothing. Those files are backed by a sqlite database in /var/lib/pve-cluster/, as the docs above discuss. With the system offline you can just copy those files. With it online and live something like sqlite3 config.db ".backup 'config.db.backup'" is safer.

Setting up a replacement Proxmox

Now that I have a backup of my files I’ve got several options to bring something back online.

  1. Try jiggling the SSD a bit, maybe it’s just a loose connection? This problem started after I opened the case, maybe I disturbed it. Nope, no such luck.
  2. Try booting off the clone I made. That might Just Work, actually. Probably should make a second clone first. Yep, this worked!
  3. Reinstall Proxmox on clean disk, then follow those recovery notes to do a quick restore. But I have to re-apply whatever other customizations I did myself, too. And manually restore all the guest hosts.
  4. Reinstall Proxmox and just configure it again. May not be much more work than #3.

No matter what I do I should replace that SSD, I’m never going to trust it. Was a cheap one anyway.

New Install

Option 2 worked so I have a working server again. I ran zpool scrub just to be safe and it found no errors.

But I’d like to install cleanly on a new SSD. So I ordered a 1TB WD_BLACK 1TB SN850X based on these reviews. I used to be a Samsung partisan but they really screwed up with the 980s and 990s. There’s an argument that you should just use a tiny scratch drive to install Proxmox on, or maybe a fancy enterprise-grade SSD instead. Eh, I’ll go with this. (No one makes high quality 512GB SSDs anymore!)

I will probably go with option 3 on this new install. Reinstall Proxmox, but then clone the config by copying a few files around. If I’m patient I should do option 4 and change the way some things work on my system. This was the first Proxmox install I did and I could do a cleaner job the fourth time around.

Bonus: Exploring a healthy Proxmox install disk

Before I worked on the bad disk I took a look at what a good disk looks like in ZFS. Here’s some things I learned from a working Proxmox system with no problems. Proxmox is installed to a single 2TB SSD with default ZFS options.

The physical disk is /dev/nvme0n1. Proxmox created three GPT partitions. fdisk tells me nvme0n1p1 is about 1M big and is labelled “BIOS boot”. p1 is 1GB big and is “EFI System”. The rest of the disk is in partition 3 labelled “Solaris /usr & Apple ZFS”. lsblk -o +PARTTYPE will show the GUIDs for the types and that partition 3 is 6a898cc3-1dd2-11b2-99a6-080020736631. Which honest-to-goodness has two meanings in this reference table. (Neither of which are “OpenZFS” or “Linux ZFS”, lol.)

lsblk also shows the SSD partitions and a couple of USB drives I have. And a bunch of /dev/zd* devices, which I gather are device names for ZFS snapshots or datasets or something. Presumably I shouldn’t mess with them.

zpool status shows that I have one pool named rpool, that’s what Proxmox created. It has one device in it, nvme-eui.002538b22140b542-part3, which corresponds to my SSD partition. zpool list shows me a basic status of rpool, how much disk space is free and the like.

zfs list shows me a whole bunch of datasets in ZFS, I think this is the top list of every thing in this pool. Most of these are under rpool/data and are either filesystems (for containers) or disk images (for VMs). But there’s also a few extras that I think are related to the PVE host: rpool/ROOT/pve-1 is the important one, also rpool/var-lib-vz. rpool/ROOT and rpool itself exist but seem pretty empty, mostly there to hold the subdirectory rpool/ROOT/pve-1.

zfs list -t snapshot shows snapshots, just snapshots and not the primary datasets.

mount | grep rpool shows me a bunch of ZFS things mounted in various places. rpool/ROOT/pve-1 is mounted on /, that’s my root filesystem. Most other things are mounted under /rpool and include a bunch of subvolumes for containers filesystems.

zfs get all rpool/ROOT/pve-1 gives me a very deep list of properties for the root filesystem. Not much of interest here but it’s exhaustive.

zdb -l /dev/nvme0n1p3 is a low-level ZFS debugger, it shows the labels on the disk device. I have a single one, “LABEL 0”, with the name rpool, a hostname that matches my PVE host’s name, and a bunch of stuff I don’t understand. Mostly looking at this because it was helpful with the broken disk since zpool wasn’t even showing it.

Debian 12 slow login in Proxmox

On my Proxmox 8.1.10 server if I create a privileged Debian 12 container, logins work but hang for 25 seconds before getting a shell prompt. There’s a good discussion of the problem in this forum post.

The clue was this error in journalctl:
Jul 28 16:43:23 transcode dbus-daemon[98]: [system] Failed to activate service 'org.freedesktop.login1': timed out (service_start_timeout=25000ms)

Looking more closely there’s a bunch of errors in systemd-login saying it can’t start. Kind of amazed I ever get a shell.

Unfortunately the recommended fix of setting ProtectControlGroups=no in the systemd-login definition did not work for me. Tried it, still broken.

The other ideas discussed are an unprivileged container (can’t do) or a nested priviliged container (can’t do). There’s also a mention that Ubuntu has a special patch for systemd preventing this error. I think that’s my next step, try Ubuntu instead of Debian.

Sometimes this computer stuff sucks.

Towards a Proxmox NAS

After trying out OpenMediaVault and TrueNAS I’m still left wanting a good NAS for Proxmox. It seems odd to me that the Proxmox folks don’t have their own product. They’ve got most of the pieces already, and a similar product in Proxmox Backup Service. They also bet heavily on Ceph but that’s a high performance distributed storage system, not a simple SMB or NFS server.

Update: HexOS might be worth keeping an eye on. It’s TrueNAS with usability stuff on top for ordinary users.

Now I’m wondering if I should just roll my own NAS services in a container or VM. I’m kind of doing that already, it works fine. I’m not going to make a fancy GUI for it, I’ve been editing /etc/exports and /etc/samba/mb.conf for 20+ years, why stop now? Although Cockpit and the file-sharing plugin might work?

The key thing here is Proxmox can manage ZFS itself. It seems strange to pass through disk hardware devices to a VM to have a separate kernel manage the disks when Proxmox can do it. So here’s the idea:

  1. Create a ZFS pool in Proxmox for NAS data.
  2. Create datasets for network file shares in Proxmox.
  3. Do not make filesystems or mount the network file shares in Proxmox itself
  4. Install Debian in a VM, maybe with Cockpit as a GUI.
  5. Pass the network file share datasets in as VirtIO-SCSI single disks to the VM.
  6. Configure samba and NFS in the VM to share the disks
  7. Bonus: disks can be shared on a private Proxmox-only bridged network for other guests to access them.
  8. Optional: install syncthing in the VM
  9. Optional: enable Restic backups of the file shares in the VM

The part I’m not entirely clear about is the “VirtIO-SCSI” part. I like the idea that ZFS is in Proxmox. What I don’t know is how good performance is virtualizing it t his way. And you don’t have ZFS-level features available in the VM like snapshots and stuff, you would want to use simple ext4fs or something. (ZFS-in-ZFS is possible but can quickly cause problems.) That’s not ideal, ZFS snapshots (for instance) are great for backups. OTOH you can use Proxmox own backup software for the datasets.

Another option would be to create and mount the filesystems in Proxmox and then pass them to all the guests with virtiofs. You wouldn’t even need SMB or NFS if you aren’t sharing data outside Proxmox! But virtiofs isn’t fully baked yet, Proxmox kinda supports it but not fully.

I’m also not clear if a VM is necessary; you might be able to do this all in a container. In that case you’d make the filesystems and mount them in proxmox, then pass them through with a bindmount.

I think there’s a potential product here, a new NAS operating system. Designed to be used as a VM inside Proxmox with Proxmox managing the storage. Just a small thing to publish network shares. Building a real product is a lot of work though, particularly if you want a GUI.

But maybe I’ll make this VM for myself just as a hack. Honestly I’ve done most of the pieces in different ways already, the difference here is being more systematic with managing the storage in Proxmox. I bet in two hours I could have NFS and Samba fully set up and going.

I wonder if this would be a good NixOS project?

OpenMediaVault first use thoughts

I’m looking for a good NAS system to run inside Proxmox. Proxmox is great at managing disks but doesn’t have anything for SMB/CIFS, NFS, etc. There’s lots of ways to add a NAS as a guest system in Proxmox. TrueNAS is very popular but is complicated and overkill. So I gave OpenMediaVault a try.

OMV is good but not great. My biggest issue is it’s not very professional, particularly when it comes to docs. Also system design. But it is a solid complete product and has a lot of plugins. There’s an active user community but often the advice you find in forum threads is pretty amateurish.

Basic setup is straightforward but has a lot of steps. I found this guide useful. Basically you install OMV. Then to add a share you add a new drive (not the system drive), create a file system, then create shared folders in it. Then you make users (or allow guest access). Then you configure SMB or NFS or whatever to serve the share. By default the system supports NFS, Rsync, SMB/CIFS, and ssh. It all works pretty well and it’s nice having a complete product in a web GUI.

Where things get creaky is extending it. Take backups. There’s no built-in backup system for data drives (a bit of a surprise!) There’s several plugins: rsnapshot, timeshift, borgbackup, ... There’s also a “USB backup” that I can’t find any real docs for. But the description says “Automatically synchronise a shared folder to an USB/eSATA/SAS/SD device” and that leaves me wondering if they’ve confused synchronization for backups.

Another example of sloppiness: the flashmemory plugin, an OMV extra, that replaces directories like /var/log with a folder2ram filesystem so you don’t wear out a flash drive with write amplification. Nice idea! It works fine. But if you look closely it looks like it never automatically syncs the logs to disk, so when you reboot you lose them. Maybe? I tried testing it and got inconclusive results.

I’m also disappointed OMV doesn’t support ZFS. There is support for a plugin, and maybe that works great, but having it not in the core makes me nervous. (The outdated “not for public” docs don’t reassure!) Proxmox supports ZFS great, so one option is to have Proxmox manage the disk pool and pass through virtual disks to OMV instead of hardware devices.

I’m using ext4fs in OMV for now. It also supports btrfs, that’s it’s fancy filesystem, but that’s not the one I’d choose.

OTOH there’s a lot of plugins for OMV and it’s all easy to get working! Some curious omissions: there’s support for S3 and OneDrive for instance, but no generic rclone support which would support so much more. On the good side someone literally started working on a Restic backup plugin today. Does it work? Can I trust it? Probably not!

It’s all just a bit more fast and loose than I want for a store of precious user data.

So now I think I need to try TrueNAS again. I tried it briefly and it felt like overkill. But OMV feels like underkill, so... TrueNAS is really confusing right now though. Their old TruNAS Core FreeBSD product is being phased out with TrueNAS Scale (Debian) taking over. OK, fine. But somehow it has Kubernetes inside it? Also TrueCharts has historically been a big part of the ecosystem with their add-on apps but there’s crazy 🤡 drama there. The whole thing still feels like overkill, particularly when it comes to them having their own hypervisor features.

I just want a nice little web UI wrapper for SMB, NFS, SFTP, and Restic.

I pushed Claude to suggest some less well known products. It came up with Rockstor, XigmaNAS (NAS4Free), EasyNAS, and Openfiler. Also Unraid (not open source but not very expensive) or Nextcloud (does a bunch of other things I don’t need).

Maybe I give up and just run a Debian VM with old fashioned text file configs like we’ve been doing for decades.

Setting up a new Proxmox server

Some notes on setting up a new Proxmox server for the non-profit I’m helping. There’s almost nothing to do, got to be the simplest install ever. Still a few steps:

Hardware tasks.

  1. Enable BIOS to boot on power restoration
  2. Quick run of memtest from Proxmox boot ISO
  3. Quick run of s-tui from Linux to heat test

Basic Proxmox setup

  1. make a USB installer
  2. boot it and use the graphical install
  3. installer options:
    choose ZFS Raid0 for the simple filesystem on the SSD
    choose UTC timezone
    type a simple to remember root passwrd
  4. after reboot, open web console and set root password to a strong password from 1Password

Root shell customizations

Make as few changes as possible on the PVE itself. But a few are useful, log in with ssh as root.

  1. Add an SSH key to ~root/.ssh/authorized_keys
  2. Run the tteck post install script and accept all its defaults
  3. Run the tteck microcode installer, I picked 3.20240514.1~deb12u1
  4. Install Tailscale
  5. Run pveam update to update the list of templates for containers

GUI customizations

  1. node > System > DNS: update search domain and DNS servers
  2. node > local > CT Templates: pick templates for containers

Proxmox / KVM cpu types

When you create a VM in Proxmox it gives you a bunch of options for what CPU to emulate. The right choice is probably “Host” if you’re not using Proxmox’ machine migration features.

I’ve always chosen the default, x86-64-v2-AES QEMU, without knowing why. There’s a zillion options for various small differences in Intel and AMD CPUs, also QEMU virtual processors. Turns out the right setting for me is “Host”. That means no particular emulation, just pass through whatever the hardware has.

It should be more performant but I’m not sure how much. I doubt the emulated CPUs are doing a full interpreter environment, but OTOH they talk about emulating microcode so it has to be at least somewhat complicated. This blog post has some measurements showing Host is 3-10% faster than KVM64.

This is all well documented, see “CPU Type”. The important parts:

Usually you should select for your VM a processor type which closely matches the CPU of the host system, as it means that the host CPU features (also called CPU flags ) will be available in your VMs. If you want an exact match, you can set the CPU type to host in which case the VM will have exactly the same CPU flags as your host system.

Why isn’t this the default? Because it makes migration awkward.

This has a downside though. If you want to do a live migration of VMs between different hosts, your VM might end up on a new system with a different CPU type or a different microcode version. If the CPU flags passed to the guest are missing, the QEMU process will stop. To remedy this QEMU has also its own virtual CPU types, that Proxmox VE uses by default. ... If you don’t care about live migration or have a homogeneous cluster where all nodes have the same CPU and same microcode version, set the CPU type to host, as in theory this will give your guests maximum performance.

With the QEMU CPU, /proc/cpuinfo in the VM shows “QEMU Virtual CPU version 2.5+”. With the CPU type set to “Host” it shows whatever the actual hardware has (ie, “Intel(R) N100”).

I’ve apparently been running one VM as Host for months now with absolutely no problems. I converted the other one from QEMU to Host.

Proxmox production container for linkblog

Starting to containerize some stuff that I originally migrated to a VM. My linkblog, for a start. I need a generic Linux environment that’s fairly beefy; libc, not musl. Ideally I’d bake all this into a reusable container but I’m rolling it by hand for now. Here’s my notes.

Container creation

  • Create a unprivileged container with hostname “blogs”
  • Add root password, my SSH key
  • Use the Ubuntu 22.04 (or latest) template. Ubuntu so I can get deadsnakes for Python versions. I’d like latest Ubuntu but can’t because Playwright (the screenshot library I need for the app) only supports LTS releases.
  • 16GB of disk, 4 CPU cores, 16GB of RAM, 1GB of swap. Or more, these are all soft limits so it may be better to set these higher
  • Default networking but enable DHCP instead of static.
  • Consider adding access to vmbr1 for the NFS server.
  • Edit the container options to make it start on boot

Linux configuration

  • Start the container, launch a console, log in as root with password
  • apt update; apt upgrade
  • apt install joe sudo curl avahi-daemon git zip unzip rsync webp sqlite3
  • locale-gen en_US.UTF-8
  • Install tailscale
    curl -fsSL https://tailscale.com/install.sh | sh
  • Shut down container
  • On the Proxmox hypervisor server, modify /etc/pve/lxc/???.conf to give access to tailscale in the container
  • Start the container
  • Log in on console again
  • tailscale up, approve the URL to join the machine. Consider disabling tailscale key expiry in the web console.
  • Use ordinary ssh client to log in as root@ ts.net tailnet name.

(not sure avahi-daemon is working here, I can’t use the .local DNS name I am expecting. I tend to use Tailscale to connect to things anyway.)

Linkblog configuration

Specific to my application, but some generic notes here also about creating a prod environment for anything.

User setup

  • As root, make a user for the project.
    adduser linkblog; adduser linkblog sudo;
  • Log in as linkblog@ with password
  • ssh linkblog@localhost, to create the ~/.ssh directory.
  • create ~linkblog/.ssh/authorized_keys

Linux configuration

  • sudo apt install python-is-python3 python3.10-pip
  • Install Node18 from nodesource

App configuration

  • mkdir ~/prod
  • cd ~/prod
  • rsync -a nelson@sf.somebits.com:~nelson/somebits/linkblog/prod/ .
  • rm -r venv
  • python3 -m venv venv; source venv/bin/activate; python3 -m pip install -U setuptools pip wheel
  • pip install -r requirements.txt
  • sudo venv/bin/playwright install-deps
  • shot-scraper install

Testing and running for real

  • ./update.sh -f
  • cd site-generated; /usr/bin/python3 -m http.server 9191
  • Test HTML load in web browser
  • Push site manually and accept ssh host key.
    ./update.sh -f -p
  • Install crontab entry to run update.sh for user linkblog

Feed2toot for @somebitslinks@tech.lgbt

Separate cron job to update a Mastodon account from the RSS feed. Does not depend on any of the linkblog code, just the RSS feed.

  • As user linkblog...
  • mkdir ~/mastodon; cd ~/mastodon
  • python3 -m venv venv; source venv/bin/activate; python3 -m pip install -U setuptools pip wheel
  • pip install feed2toot
  • copy over the install from the old system. This gets credentials, config, and state.
    rsync -av --exclude=venv nelson@example.com:~/src/mastodon/linkblog-toot/ .
  • run a quick test, should show posting nothing if there are no new stories
    feed2toot -n --debug -c feed2toot.ini
  • Install crontab entry to run go.sh for user linkblog

TODO

  • Package linkblog as a proper Python package so deployment is better
  • Write linkblog code to manage crontab (or at least emit the line)
  • Write linkblog code to run test server

Intel QuickSync GPU transcoding in Proxmox

Notes on video hacking, efficiently transcoding H.264 to H.265 video. I’m updating my old to65 function to work in my new Proxmox environment. The key idea here is to use jellyfin’s build of ffmpeg with Intel QuickSync codecs to transcode video faster. The challenge is making getting a Proxmox guest OS that can use that. Both to set up the container and also to make sure it has the permissions necessary.

The expedient solution I set up was to use a tteck script to install jellyfin. That’s a whole server environment and is overkill but it installs the /usr/lib/jellyfin-ffmpeg/ffmpeg I need. It also sets up the container to access the Intel GPU. The main thing it does is make the container privileged: not ideal (nor necessary) but sure smooths things over. There’s also some entries in /etc/pve/lxc/104.conf for mapping the necessary devices, particularly /dev/dri/renderD128.

Anyway installing with that script is really all I needed. With that my i5-12600K server is transcoding a 1080p video at about 4x speed. Using 40% of one CPU core and intel_gpu_top shows me the Render engine is pegged at 100% (encoding?) with the Video engine also at 20% (decoding?). That’s more or less what I remember doing on the old native hardware, no surprise.

tteck also has a tdarr package. I should try that again; last time I did I couldn’t figure out tdarr’s UI. It’s perfect for what I need but I was scared it’d aggressively transcode all my video files, I really want to only transcode a few things.

Backing up Proxmox itself

Proxmox has great systems for backing up your guest OSes, VMs and containers. Including their configurations. But it has no affordance for backing up Proxmox itself. Mostly you don’t do much configuration on Proxmox but you do some, it’d be nice to be able to recover it. I finally found some docs on migration and restore hidden in the 7 -> 8 upgrade docs. A summary:

Backup: “all files in /etc”. Specifically named: files in /etc/pve, as well as /etc/passwd, /etc/network/interfaces, /etc/resolv.conf

Restore: /etc/pve/storage.cfg. Firewall configs /etc/pve/firewall and /etc/pve/nodes/<node>/host.fw 

It’s nice they tried but these instructions aren’t complete. At least in my reinstall I also had to pay special attention to jobs.cfg which configured the backup schedule. Also /etc/fstab.

And while I try not to put too much into Proxmox itself I at least need to install Tailscale for access. And an NFS server for one machine (although I may yet move that to a container). Those are outside the scope of the product so backing them up really is my problem.

Proxmox moving to a new server

I migrated my first Proxmox system to a new server. It went very well. Basically you just back up all the containers and VMs, restore them, and Bob’s your uncle. Took under an hour, more because I did a test run installing to an external USB disk first. Really I’m migrating to the same server, I just wanted to switch from btrfs to zfs.

Proxmox backups include not only the guest OS image but also Proxmox’ own configuration. The restore is smart enough to adjust the config to, say, handle that the virtual disk image now lives in ZFS. The only place anything failed is that my VM had a virtual CDROM mounted; the restore still referenced the image via BTRFS. Then again the CDROM didn’t even exist in the new zfs server, I no longer needed it. No big deal: the error message was clear and I could easily edit the config to remove it.

The other hassle was restoring Proxmox itself. There’s no way to back up a Proxmox server, just its guests! I think they’re idea is you’re using a cluster with several servers and so if one fails you just add a new host and have it learn what to do. Still seems like they should have a backup option.

For a small home user it’s good discipline to do as very little on the Proxmox server itself as you can. I made a checklist of things to set up on the new one, here’s a quick list:

  • update repositories and upgrade
  • configure /etc/fstab to mount my disks
  • configure backup disk as new storage type
  • set up guest backup schedule in the GUI (again)
  • add a system metrics server
  • apt install joe sudo avahi-daemon
  • install a user nelson for convenience but try not to use it
  • install tailscale and remember --accept-dns=false

I tried a couple of things to verify the new Proxmox was configured the same as the old without a lot of success. I was hoping that comparing /etc/pve would tell me more, that’s where Proxmox keeps its configs. But mostly it was stuff you’d expect to be different: crypto keys, details related to file system storage. Hard to find meaning in the noise. I was glad to find jobs.cfg though with a record of my backup configuration. (Note that /etc/pve is actually a pmxcfs FUSE filesystem for clusters; the actual truth lies elsewhere.)

Really pleased at how all this was. Virtualization is great! Next time will probably take half an hour at most and most of that time is waiting for disk images to copy around.

Installing a Valheim server

Now that I have Proxmox I can easily spin up VMs or containers for things I would ordinarily be suspicious of running on my real server. I’ve been enjoying the game Valheim recently so I ran a server there following these instructions. In detail.

First, I took a detour through Game Server Managers that ended up being a dead end. These are special OS installs optimized for installing game servers, often Linux-based. I was hoping for something with a button to press that said “install Valheim”. I didn’t find anything Proxmox specific. I liked the look of AMP but it’s proprietary. I installed this TurnKey GameServer and tried to get it working but ran into a lot of problems. I finally decided using a manager was adding unnecessary complexity, particularly since I have Proxmox as a VM manager already.

So I installed Debian 12.4 in a VM on Proxmox. Then I followed these instructions for installing Valheim which more or less worked although read the comments on the gist for some updates since the instructions were written. It’s all pretty straightforward except for the use of steamcmd, a new-to-me tool. That’s a command line version of Steam for running servers and the management of authentication, etc is a little opaque. Since these instructions were written Steam has added an anonymous mode for game servers that might be easier.

It all basically just worked. Last thing I had to do was forward port 2456 on my router so I could connect from elsewhere.

Proxmox makes this kind of tinkering a pleasure. I like how I can snapshot a guest OS and try something with a chance of recovery. I also like the full isolation of a VM. I should set up some sort of subnet so that I can install things like this that can’t access my main home LAN. Only it still has to be able to talk to the Internet through the router. That’s tricky but I think Proxmox has some help for doing that.

I’m trying to use Debian instead of Ubuntu for this kind of project. It’s surprisingly different, like it doesn’t use netplan for network config by default. Here’s a list of packages I installed that I’ll probably want in any Debian system:

sudo joe chrony curl screen net-tools avahi-daemon

Proxmox disk wear

Does Proxmox 8.1 wear out my disks? Maybe. A fairly idle Proxmox server is writing 40GB a day and I think most of that is wasteful. My SSD will last 10+ years at that rate but maybe I can make it better. So I looked more closely and in the end concluded most of the write activity is related to the guest operating systems I’m running, not Proxmox itself. Proxmox alone is writing about 50KB/second of data.

Wear is a concern with consumer SSDs; even a high end Samsung 980 Pro is rated for only 600 TB of writes for a 1TB drive. (Enterprise SSDs are 3x that or more.) It should be enough for an ordinary home server not doing a whole lot but a misbehaving system could make things bad. There’s several kinds of misbehavior with different solutions.

The Proxmox subreddit is full of posts like this or this with people noting high wear on their SSDs. The discussions are muddled. Someone says “it’s a problem!” and several people immediately respond “not a problem for me”. Inevitably someone says “buy an expensive enterprise SSD you fool”. Out of that noise I’ve found some pattern: Proxmox can write a lot of data.

Measuring disk writes

How do you measure the problem? The easy way is to use the Proxmox GUI to look at “Disks” for the host; the last column is “Wearout”. That’s current state of use and comes from SMART data. (Or should; my cheap N100 server doesn’t have the info.) Take a look, you may be surprised! I haven’t run Proxmox long enough to really know, my old Ubuntu server was running for a year+ without Proxmox and is only at 1%.

You can also get more insight by setting up system metrics on Proxmox. That has it export data to an Influx database when you can then visualize with Grafana.

More hands-on, you can measure write load with various Linux IO tools. Good old iostat is one way, ZFS has its own version of that:

$ zpool iostat

capacity operations bandwidth
pool alloc free read write read write
---------- ----- ----- ----- ----- ----- -----
rpool 72.4G 1.74T 28 21 1.91M 727K

That tells me the ZFS pool on my SSD has averaged 727KB a second since the last reboot. Watching zpool iostat 60 for minute-by-minute reports it’s averaging about 500KB a second on both Proxmox hosts I have. That’s about 40GB a day or 16TB a year. That still gives me decades before the device wears out. But it seems pretty wasteful, what’s doing all that writing?

Another tool is iotop or pidstat -d which show per-process IO stats. fatrace is also interesting, it gives you a log of file access.

Guest system write load

A simple explanation for the writes is the VMs or Containers running as guests on Proxmox may be writing to (virtual) disk, doing real work or writing logs. That’s got nothing much to do with Proxmox.

Proxmox has a nice tool for understanding disk I/O in guests; a graph right there in the GUI.

On my BTRFS machine the graph above tells me the Ubuntu VM guest is writing about 200KB/s. Another graph shows only one of the three containers has sustained writes, it says about 15KB/s. FWIW if I stop just the containers the iostat on the hypervisor goes from 500KB/s to 350KB/s, suggesting the three containers are writing 150KB/s between them. If I then also shut down the VM it saves another 300KB/s. The numbers don’t quite add up but I’m willing to believe that most of the disk writes are things the guest systems are doing. The Proxmox host itself is only writing 50–100KB/s, a small enough number I can ignore it.

On the ZFS machine where I measured 500KB/s writes, the VM itself says it was writing about 100KB/s. That still leaves 80% of the write load coming from the Proxmox hypervisor and maybe a mystery. Or maybe not, like I said the numbers don’t always add up.

Write amplification

A systems problem, write amplification is when writing (say) 1GB of application data results in a lot more than 1GB of write operations on the disk. Pathological systems can have 100x write amplification, a real problem. There’s various possible causes for this, I don’t really understand it.

On a simple test using iostat and dd I verified that writing 100MB of data from /dev/urandom in a VM resulted in about 100MB actually being written to the ZFS pool. Careful how you test; if something’s compressing the actual write might be less than the application data.

I think write amplification is a particular concern with ZFS depending on what RAID configuration you choose. Particularly if you run ZFS in a guest on a virtual disk backed by a physical ZFS pool. The VM itself can also be relevant, see zoned-storage for instance in QEMU. One drawback of virtualization is you’re so far removed from the hardware that things can get out of hand quickly.

Proxmox itself

On to the real question, does Proxmox itself write too much to disk? I’ve got a measurement that it’s only 50–100KB/s. Still, why that much? The Internet is full of advice on how to make Proxmox write less; this guide is particularly good.

The suggestion I was hoping would work is stopping services related to clusters if you only have a single node. The usual suggestion is to stop four: pve-ha-crm, pve-ha-lrm, pvesr.timer, and corosync. Of those only the two pve-ha services were even running. Stopping them didn’t really change the write load.

Another suggestion is to install log2ram and use that for /var/log instead of the real disk. Which could be a nice solution but you lose your logs in case of a hard system crash. Along those lines I’ve used tmpfs before for temporary directories. It helps as long as no one is expecting /tmp to be big.

Another recommendation is to change the vm.swappiness property; apparently Proxmox preemptively starts swapping things to disk when RAM is just 60% full. I don’t have any swap configured so that’s not going to change anything. Memory thrashing to swap could very quickly overwhelm an SSD.

File access details on Proxmox

I tried using iotop, pidstat -d, and fatrace to better understand what was going on. iotop is hard to read or possibly useless because ZFS or BTRFS themselves dominate the reports. pidstat -d is similar to iotop but different packaging. fatrace is a neat tool, and new to me. It shows which files are being written over the whole system. Sadly not how much are being written. Also it can’t show writes to a ZFS volume like my VM is stored on, since those aren’t files.

Shutting down all guests I’m left with proxmox itself. I’m still at 50KB/s or so, it’s hard to be sure exactly. fatrace tells me disk writes go to the following places:

  • pmxcfs: /var/lib/pve-cluster/config.db-wal. This is the PVE High Availability stuff I talked about turning off earlier. Even with those two services turned off there’s still some writes there.
  • pvescheduler: /var/lib/pve-manager/pve-replication-state.lck. Something related to a replication feature I’m not using. There are instructions on how to turn this off but they don’t seem to apply to modern versions.
  • pvestatd: /var/log/pve/tasks/.active.lock. Presumably an important part of PVE’s task scheduler.
  • pvestatd: /var/lib/rrdcached/journal/rrd.journal... Guessing this is the database for the nice graphs in the UI.
  • tailscaled: /var/lib/tailscale/tailscaled.log?.txt. Tailscale writes data briefly to its own log before pushing it to journalctl and removing it. This discussion has some notes about moving or disabling it. It seems to be about 30 writes a minute, 100 bytes at a time.

So that’s that. Most of my writes are coming from guests. Proxmox could be a little more efficienct, so could tailscaled, but what it’s doing now is not awful. And the amount of writes isn’t significant enough to worry about my disk lifespan.

QEMU virtual disks: clearing unused blocks

How do I get Proxmox VM backups to back up actual data and not disk blocks that were written once but no longer used?

Update: the answer for me was to enable the “Discard” option in the hardware options for the VM disk. That’s documented here in the Proxmox manual and for some unknown reason the default is off. After enabling this, trim in the guest OS propagates up to the storage; running fstrim -va in the guest resulted in the ZFS volume in the hypervisor dropping from 167G used to 64G used. This works with VirtIO block devices although next time I set up a VM I’ll still prefer using VirtIO SCSI. (On the other machine which I created with a Clonezilla clone it dropped from 69G to 24G. I wonder if Clonezilla cloned all the blocks even when they weren’t being used.)

Update 2: I also had to add the discard option in fstab for my ext4 filesystem. It’s not the default. I think it may be the default for btrfs and other file systems, not positive.

I ran into a funny problem today. The Proxmox backups of my main Linux VM were taking a tidy 56GB, about as much data (compressed) as there actually is on the 2TB virtual disk. Then I accidentally created a 100GB file (all of Wikipedia in ZIM format). I removed it, df shows its gone. But now a VM backup is taking 156GB. Presumably it’s backing up all the unreferenced blocks that were deleted but still have data on them. I suspect the QEMU clones I started with weren’t copying unused blocks.

You can see how much space ZFS has reserved for a virtual disk like this

root@sfpve:/home/nelson# zfs get used rpool/data/vm-100-disk-1
NAME PROPERTY VALUE SOURCE
rpool/data/vm-100-disk-1 used 167G -

I want that 167GB to be more like 67GB.

I tried using trimfs in the VM guest but it didn’t do much. It’s not clear the trim command ever makes it to the hypervisor host OS. Anyway, fwiw: /: 35 GiB (37617963008 bytes) trimmed. Right after a reboot I ran it again and got /: 139.2 GiB (149456355328 bytes) trimmed, but the second time it was back to 35 GiB. I have no idea what any of this means.

The Proxmox docs have details on how to make trim work in VMs get through to the host OS. They require the virtual disc be of type virtio-scsi and unfortunately I created the VM with a virtio-block. Apparently the SCSI storage type is the more modern and capable one. Also note this wiki page is 4 years old and I can’t quite tell if it’s really relevant now.

virt-sparsify is a QEMU tool for removing unused blocks from an unmounted virtual disk image, see here for more details. This looks perfect for what I need. But it’s not installed by default and installing it includes bringing in all of X11 in Debian, so I’m reticent. Also it requires operating on a file and Proxmox stores VM disks in block storage as a ZFS volume.

That same old Proxmox wiki page also has another solution; just use qemu-img convert to copy the virtual disk and you’re done. The qemu tools seem to be filesystem aware and smart about avoiding unreferenced blocks, I suspect I benefitted from that when I first created the VM disk by cloning my physical disk. But again this requires operating on files and Proxmox has them the disk image as a volume.

This discussion has some notes on using qm disk instead of qemu-img to operate on disk images; it’s able to work with volumes as well as files and presumably is just calling qemu-img to do the real work. I think it’d be as simple as using import to create a new disk that’s a clone of the existing one.

My fear with any of these methods is that they might change the block IDs or device names on my Linux guest and then it won’t boot. Updating /etc/fstab is easy enough but updating Grub is harder. (See my notes here, section “Fix the block IDs”).

The current state is not awful; backups are taking 3x as long and 3x the space as they should, but they all still work. But the problem will only keep getting worse. I think I’ll let it go for now but if I come back to this, ideas to try:

  • Switch to virtio-scsi for the VM and enable the trim command. See if that fixes it.
  • Make a qm disk import clone of the VM disk image and see if the new one is smaller. I can test that entirely with zfs get.
  • Clone the VM disk image to a file and use qemu-img or virt-sparsify to fix it.

Proxmox and data management

Still loving Proxmox but I’ve run into one product limitation: it doesn’t really have a good way of sharing filesystems across guest operating systems. If you want a disk managed by Proxmox to be available in a VM, or to share files between VMs, you pretty m uch have to use a network filesystem like NFS or CIFS (Samba). And Proxmox doesn’t run those itself servers. It seems like a gap in the product.

Proxmox has a fantastic system for managing storage for itself. You have your choice of filesystems but it really wants you to use ZFS. And it uses ZFS great. You can hand Proxmox a bunch of disks and it’ll set up ZFS, create ZFS datasets for container filesystems and volumes for VM disks, etc. It’s very nice.

But if you want to make, say, your home directory as a filesystem and share it to several VMs you’re on your own. There’s a bunch of ways to do this. What I’m doing now is I just make it a normal filesystem (or ZFS dataset) in Proxmox. Then I export them with an NFS server on the Proxmox hypervisor server and NFS mount the filesystem in VM guests. With all the overhead and (virtual) network awfulness NFS implies. Container guests have it easier than VMs, they can access the filesystem more or less directly with a bind mount.

The bummer here is I have to install and manage the NFS server manually on Proxmox. It’s easy enough to set up an NFS server as a Debian package but now I’m outside the Proxmox product, it has zero support for it. Same goes if I chose to use Samba for CIFS instead. For that matter Proxmox GUI doesn’t know about bindmounts for containers either although it’s easy enough from the Proxmox CLI, they even document it.

There’s fancier possible setups. One interesting possibility is to install TrueNAS in a guest VM in Proxmox. And use that as the NFS server with its management GUI. But then how does TrueNAS access the disks? The simple way would be to make a big virtual disk for the TrueNAS VM (backed by ZFS on the Proxmox hypervisor) and use it. But.. yuck! You lose most of the advantage of TrueNAS managing physical disks. The other choice would be to not use the physical disks at all in Proxmox and just pass the hardware through to the VM and let TrueNAS manage them. I may yet end up setting that up.

Another option coming is virtiofs. That’s a way for a hypervisor to share filesystems to a VM without a network filesystem. I think it’s pretty fully baked in Linux now but not quite ready in Proxmox.

A third option fully supported by Proxmox is Ceph, a distributed storage system. I haven’t looked at it, Ceph seems far too big and complicated for my needs.

The NFS server on the Proxmox hypervisor is working OK with me. Mostly I hate how abstracted it becomes, how far removed a disk write on a Linux VM is from what the actual hardware is doing. Performance went to shit yesterday on my system when I moved a 100GB file from a virtual disk in a VM via NFS to a physical disk. The VM’s IO response went to multi-second latency. Load average on the proxmox server went to 9 as a bunch of nfsds sat there hanging in device wait. To be fair, the disk copy happened at max speed so it did complete reasonably but it sure reminded me of the cost of all these abstractions and virtualization.

tailscale, Magic DNS, proxmox, and LXC

Frustrating interaction. tailscale MagicDNS breaks LXC under Proxmox. The solution is to start tailscale with --accept-dns=false on the Proxmox server. This is well documented by Tailscale but I missed it. In detail...

I have tailscale installed on the Proxmox hypervisor host, with MagicDNS enabled. If I start an LXC container then DNS doesn’t work at all in the container’s guest operating system.

The underlying issue is how tailscale does MagicDNS, how it answers DNS queries to supply its own answers for your hosts at *.*.ts.net. On Linux it does this by rewriting /etc/resolv.conf setting nameserver 100.100.100.100. The details of how it does this are complex because so many other things on a modern Linux box are also trying to overwrite that file. (Yes, systemd is involved). But it seems to work fine on the Proxmox server.

What doesn’t work is MagicDNS inside an LXC container. When you launch LXC it seems to start with a copy of whatever /etc/resolv.conf is in the Proxmox host. (Every time; if you reboot the container it gets a new copy.) So if tailscale is running it can pick up that 100.100.100.100 nameserver. Unfortunately the LXC guest operating system does not have access to that IP address (nor to any of your tailnet, it shouldn’t!) So DNS doesn’t work.

The simple fix is to turn off tailscale on the proxmox server: tailscale down. But it’s nice to have tailscale to access the server! If you run tailscale up --accept-dns=false then there’s no MagicDNS on the Proxmox server and /etc/resolv.conf is left alone. This setting seems to be sticky, it’s persisting even though I didn’t edit any config files.

Another option the docs mention is writing a /etc/.pve-ignore.resolv.conf file in the LXC container’s filesystem. That’s part of a general mechanism to have Proxmox not overwrite files in LXC guests.

Making a private subnet for Proxmox guests

I want a second private subnet just inside my Proxmox host, for the guests. Main immediate reason is I want to export an NFS filesystem with root access from proxmox to guests but I’m too lazy to set up Kerberos. I trust my LAN but not quite that much; I don’t want any dumb device in my house to be able to be root here. So I set up a second bridged subnet just for Proxmox guests.

By default Proxmox sets up a bridge vmbr0 connected to the LAN of the Proxmox server itself. Guest VMs can just use that interface (often named ens18 in the guest) like it was an ordinary ethernet, do DHCP to get an address, route packets to the Internet via it. it’s very convenient. Mine is configured on 192.168.0.0/24.

But it’s pretty easy to set up a second bridge. The manual is quite thorough but not quite a cookbook. I used the GUI to do it.

First, on the Proxmox server, I used the Network config to add a new bridge named vmbr1. (I set an advanced option that’s not visible, mtu 9000.)

Then, in the hardware definition of the VM, I added the bridge there.

Finally in the Ubuntu VM’s Netplan configuration, I set up a static config. vmbr1 seems to be called ens19 in the VM:

network:

version: 2
ethernets:
ens19:
addresses:
- 192.168.240.2/24

Proxmox will live reload the server config if you press the button. I forgot how to reconfigure netplan in Ubuntu so I just rebooted. And it all worked: now the two hosts can talk to each other on 192.168.240.0/24 addresses without involving the ethernet LAN at all. Now I can configure the NFS server and client to use those addresses instead and have some extra isolation.

I’m not certain what would happen if a malicious actor gained access to my physical ethernet and then started trying to talk to the supposedly private 192.168.240.0/24 subnet. I think they wouldn’t get very far, since none of my hosts have the bridge connected to the ethernet? But I haven’t tested it. I’m not worried about that aggressive of an attack, mostly just trying to prevent accidents.

As a bonus I configured the MTU on the bridge to be 9000. This is an often-recommended setting for NFS performance, I think because NFS itself will use up to 8KB data packets for things.

Update

This has been working well for me. I did some simple testing of performance in August 2024. First, the network interface itself:

  • 0.15ms ping latency
  • 50Gbits/s iperf3 throughput

So the virtual network is plenty fast. I don’t know how to test actual I/O throughput properly for an NFS server. I did a simple fio command an AI suggested and came up with a number of about 1.12GiBytes/s which is 10x faster than the spinning disk that’s being served. The NFS daemon on the server got to about 15% CPU while doing it.

My conclusion is “fast enough for anything I’ll do”. It’s more than double the speed of a good SSD plugged in locally, so I don’t think the networking inside Proxmox is a huge problem. At least for max throughput, not sure about lots of little file operations.

# fio --name=test_network_throughput --ioengine=libaio --rw=read --bs=64k --numjobs=1 --size=100m --runtime=60 --time_based --end_fsync=1 --direct=1 --filename=./testfile.fio

test_network_throughput: (g=0): rw=read, bs=(R) 64.0KiB-64.0KiB, (W) 64.0KiB-64.0KiB, (T) 64.0KiB-64.0KiB, ioengine=libaio, iodepth=1
fio-3.33
Starting 1 process
test_network_throughput: Laying out IO file (1 file / 100MiB)
Jobs: 1 (f=1): [R(1)][100.0%][r=1161MiB/s][r=18.6k IOPS][eta 00m:00s]
test_network_throughput: (groupid=0, jobs=1): err= 0: pid=975385: Fri Aug  9 16:37:31 2024
  read: IOPS=18.4k, BW=1149MiB/s (1204MB/s)(67.3GiB/60001msec)
    slat (usec): min=2, max=803, avg= 3.97, stdev= 1.38
    clat (usec): min=16, max=4110, avg=50.14, stdev=13.62
     lat (usec): min=35, max=4114, avg=54.12, stdev=13.82
    clat percentiles (usec):
     |  1.00th=[   40],  5.00th=[   43], 10.00th=[   45], 20.00th=[   46],
     | 30.00th=[   47], 40.00th=[   48], 50.00th=[   49], 60.00th=[   51],
     | 70.00th=[   52], 80.00th=[   53], 90.00th=[   56], 95.00th=[   61],
     | 99.00th=[   81], 99.50th=[   92], 99.90th=[  143], 99.95th=[  165],
     | 99.99th=[  375]
   bw (  MiB/s): min= 1016, max= 1373, per=100.00%, avg=1148.65, stdev=42.11, samples=119
   iops        : min=16266, max=21978, avg=18378.44, stdev=673.71, samples=119
  lat (usec)   : 20=0.01%, 50=56.83%, 100=42.80%, 250=0.35%, 500=0.01%
  lat (usec)   : 750=0.01%, 1000=0.01%
  lat (msec)   : 2=0.01%, 4=0.01%, 10=0.01%
  cpu          : usr=1.55%, sys=9.94%, ctx=1102796, majf=0, minf=27
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=1102756,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: bw=1149MiB/s (1204MB/s), 1149MiB/s-1149MiB/s (1204MB/s-1204MB/s), io=67.3GiB (72.3GB), run=60001-60001msec

Post-virtualization thoughts

Phew, my physical to virtual server migration using Proxmox mostly worked. I’ve now moved my main life server, the one I’ve been maintaining or evolving over 25+ years, for the first time into a VM. And it mostly works! Some collected thoughts after the fact.

Checkpoints and backups at the VM level are nice. Really looking forward to that.

This plan of virtualizing a server by first making one giant VM is nice. I can now hive off services to run in specific containers or VMs at my leisure.

Jeff N talked me into trying ZFS on the Proxmox host and so far I’m glad for it. ZFS seems complicated to me but Proxmox is clearly built to take advantage of it. Checkpoints already work better than on BTRFS.

I’m still working out where stuff should live and how it should be shared once I start containerizing services. The obvious thing is to put the primary home for everything in a ZFS pool maintained by the Proxmox server itself (just with ZFS, no Ceph.) My home directory, my Music library, my Video library, a place for backups. Share to containers via bindmounts. Sharing to VMs is harder. I think NFS is the best solution for now until virtiofs in Proxmox is a bit more finished.

Yes, I said NFS. Ugh. I’ve got it working with an NFS server on the Proxmox host itself and the VM mounting it. Setting up automount gave me bad flashbacks to the 1990s, although of course systemd has its own way of doing things. But NFS implies a lot of overhead. Also the confusion of user ID mappings. I’ve never really administered NFSv4 which has some nice things but I may gouge my eyeballs out of I have to set up Kerberos. OTOH I’m really not comfortable letting anything on my LAN mount stuff with root privileges. A work in progress.

Syncthing is working OK in the VM right now. Syncthing is peer to peer but I think of it as hub-and-spoke, with this server being the hub. I think I want to hive that Syncthing hub off to its own container. I see myself possibly also setting up a separate Syncthing instance in some containers or VMs but that sure seems dumb. More work in progress.

Syncthing + NFS is scary. The risk is that NFS is unreliable, so the directory for a synced folder might disappear. And in a bad case Syncthing might interpret that as a command “Delete all the files” and propagate that to all the clients. This really happens in practice and is very bad. They have a sentinel file to protect against this, the .stfolder. I still can’t help but think that syncthing is best run on a local filesystem and not a networked one.

I’ve got Plex running in a VM. Right now it doesn’t have access to the Intel GPU, so it can’t do hardware acceleration of transcoding with Quicksync. There’s ways to make that work but I think I should prioritize moving Plex first into a container, the tteck scripts work with hardware transcoding.

Backups are a big question mark. I’ve generally used rsnapshot but that requires root access to work well, since it’s setting file ownership. And root access to NFS is a no. I’m thinking of switching to Restic for backups instead. How this will work depends a bit on my “who should own what files” question.

I also want to make VM and container backups in Proxmox itself, separate from my personal data. And I’d like to back up the Proxmox server configuration itself; it’s crazy there’s no tool for that.

I need to rethink using RAM for tmpfs in the VM. Also using a swapfile. It’s all working but I bet it’s not optimal.

Proxmox physical to virtual take two (QCOW2 and tar)

I had so much success with Proxmox for my little home server that I decided to install it for my big home server, the one doing the important stuff. Like before I’m going to ease the transition by first cloning the whole Ubuntu server into a VM in Proxmox, then work on migrating individual services out to their own containers or VMs one at a time. Much thanks to Jeff N for email support learning how to do this.

The interesting thing here is various methods for cloning a physical Linux system into a Proxmox VM and making it bootable. I did this once already using Clonezilla. This time I’m trying two other methods: cloning with a QEMU disk image and cloning using tar on the root filesystem. I’ve now gotten all 3 methods to work. I think the QEMU disk image is my favorite route, it’s relatively compact and straightforward. Every method could be useful though.

Battle plan

The server I’m starting with is this one, with this hardware. The challenge is I want to replace the Ubuntu server OS on the machine with Proxmox, with the former server now running as a VM under Proxmox. The nerds call this a P2V clone. The general challenge is how do you clone a Linux system and make it bootable? A particular challenge is I’m trying to do it in-place, I don’t have a second server to clone to. And in particular I want to re-use the existing 2TB SSD, and even though I’m only using 80GB or so of that any simple full mirror will take forever and waste the other 1920GB.

I’m particularly scared of the moment where I install Proxmox over the old server’s filesystem. Once that’s done the clock is ticking to get the new VM up and running so I have my important services back. So first I did a couple of dry runs installing Proxmox on an external USB drive I had lying around. Here’s the plan I came up with:

  1. Remove unneeded files from the server like the apt cache or the systemd journal.
  2. Make simple tar and/or rsync backups of all the files and put them in a safe place. This is the “in case of disaster” recovery option.
  3. Turn off some services on the server that I don’t want to start immediately when the server wakes up as a VM.
  4. Shut down the server and boot a Linux system rescue disk.
  5. Use the rescue disk to clone the old system disk via either qemu (path 1) or tar (path 2) to an external USB disc. See below for details.
  6. Install Proxmox on an external USB disc on the server hardware. Don’t wipe the old server system! We’re going to test stuff is basically going to work before committing.
  7. Create a VM in Proxmox for the newly virtualized server
  8. Copy the clone into the disk for the virtualized server. See below for details.
  9. Boot the clone VM and get it working.
  10. Once satisfied, repeat the whole process but install Proxmox onto the SSD instead. Burn the boats!

It helps to have some spare fast SSD USB discs lying around for these 80GB copies of things. I used several. One for copying server clone images to. One to install Proxmox on (temporarily). And a couple of small jump drives for booting Proxmox and rescue disk images.

What I’m not doing is what I did last time using Clonezilla to make the clone. That requires two running servers (the original and Proxmox). Also the destination disk needs to be as big as the source disk and have room left over for Proxmox; not possible with my replace-in-place plan.

One thing I mostly didn’t do was try to resize the root partition or disk image to be smaller, closer to the 80GB I actually need instead of the 2TB of the source disk. It would probably make things go smoother but all the various resize options are a little scary. I did experiment with this once I got the VM working, see notes here. For the real thing I did resize the btrfs filesystem itself to 200GB, but the partition and the disk are both still 2TB.

OVMF bios notes

I’m trying to do all this with EFI and Secure Boot. It worked on my physical server, it should work on the Proxmox VM too. Some notes on that:

  • For EFI you must select the OVMF BIOS when creating the VM in Proxmox. It’s not the default.
  • The OVMF EFI shell is weird. It’s a 5 second timeout, then a command line I didn’t understand, and then if you exit that you get to a simple TUI BIOS menu like you’d expect. You can also hit ESC to bypass the 5 seconds and command line.
  • There’s a bunch of confusing boot config options. If you’re just trying to boot a specific thing, try Boot Maintenance Manager / Boot From File and then browse the filesystems. Ubuntu’s boot works from EFI/ubuntu/shimx64.efi
  • I could not get OVMF secure boot to work in a VM with the System Rescue ISO. You’d try to launch it and it’d just return. It works if you turn off secure boot in OVMF. Maybe it’s an issue with the ISO virtualization.

Path 1: QEMU image clone of the whole disk

This method creates a .qcow2 file which is conceptually an image of every block on the source disk. I got the idea to try this from a Reddit discussion. You make the .qcow2 file and load that in to QEMU/KVM on Proxmox and you’re done. It’s pretty straightforward but some details tripped me up.

Making the QCOW2 file was relatively easy with these directions. The key command is qemu-img convert -O qcow2 /dev/sda disk.qcow2. Note this clones the entire disc, not just one partition, which means the partition table, GRUB, and the EFI stuff stays intact. Fortunately the QCOW2 format is smart about unused sectors so my 2TB disc resulted in a 80GB QCOW2 file and was relatively quick (10 or 20 minutes?). (There’s also a -c to compress which might help?)

Using the QCOW2 file on Proxmox was a bit trickier. These notes were useful to me. Basically you create a new empty VM in Proxmox with no install media, no virtual hard drive. Then you use qm disk import to create a new disk from your clone. It converts the QCOW2 file into whatever format Proxmox wants. In my case that was a 2TB raw file on BTRFS. Thankfully it’s a sparse file so it only uses 80GB of the disk. (ls -l shows 2TB, du and btrfs filesystem du show 80G. ZFS also makes sparse files.) This new disk had two partitions cloned from my Ubuntu install: /boot and /. But I didn’t have to do anything special for each partition to make them work.

There’s some subtle configuration things I had to do in Proxmox:

  • It’s essential to select the OVMF BIOS for the VM so that EFI booting works.
  • Proxmox wants an “EFI disk” configured. That seemed to be the default once I told it to use the OVMF BIOS. It’s only 500KB, not sure what’s in it, maybe the BIOS? It’s not your system’s boot partition.
  • It’s important to specify a cache policy for a BTRFS disk image. The default is “no cache” which apparently causes corruption issues; I used “write back”. No need if you’re using ZFS on Proxmox.
  • I had to fiddle with the boot order of things in both Proxmox and maybe the BIOS to get it to actually boot the partition for the cloned Linux system.
  • I did not have to disable secure boot. It worked with my virtualized GRUB setup from the clone without changes.
  • I had to set the CPU type to “host” for KVM virtualization to work, so that my Ubuntu system could load the kvm_intel module that snapd wanted. This might cause a problem if you want to migrate a VM to another host in a Proxmox cluster. But it might also give a performance boost.
  • The graphical console was a bit wonky under Ubuntu; sometimes it’d be distorted early in the boot and then fix itself in a couple of seconds. I tried setting the graphics hardware to “VMWare Compatible” and that fixed the distortion, but then sometimes boot would fail mysteriously. See below.

With all that in place, the cloned system booted in a VM! The old familiar GRUB menu and Ubuntu loaded like a champ. Really this was pretty easy.

I initially created a VM with no network device because I knew that DHCP meant my Proxmox server had now stolen the IP address the old server was using. Not good having a VM boot and use the same IP as its host! Fortunately systemd boots pretty nicely if there are no network devices. It gets messier if there are network devices that aren’t configuring themselves; there’s a 120 second timeout for that.

I had to make some changes to the newly virtualized Ubuntu server to make it cooperate better. I did this with Ubuntu’s own recovery mode, a rescue disk would also work. I did these without networking, then rebooted for networking.

  • setfont Uni1-VGA32x16 to make the font readable in the Proxmox graphical console
  • Remove fstab entries for other physical disks. (Note this can prevent your system from booting if you don’t, in which case you need a rescue shell.) In the new setup I’m going to mount those disks in the Proxmox server and then NFS mount them in to the Ubuntu guest.
  • Edit /etc/netplan configs to use DHCP (for now). Also the new VM ethernet device is named ens18.
  • Disable Syncthing in the guest VM. The Syncthing data is no longer mounted and I was scared it’d propagate a “delete all files!” message. I’ll need to get this set up again eventually, ideally as a new Proxmox container just for Syncthing.
  • Disable all my cron jobs for things like blog updates, backups, etc. Again these need to be set up eventually or migrated to special purpose containers.
  • Eventually I should install the qemu-guest-agent and enable it in the Proxmox config so everything plays nice together.

Update on Path 1

I redid this whole process for the real server and ran in to some new problems.

The graphical console was giving me trouble. As noted above, there’s some bug in the default graphics hardware where the Ubuntu boot has a corrupted display for the first couple of seconds. That was hiding an error message, so I switched to “VMWare Compatible” graphics hardware. That looked fine but then my main Ubuntu system wouldn’t boot, displaying an error “hardware has no pitchlock” which froze everything in the Ubuntu boot sequence after about 0.6 seconds. Note this error was only findable in journalctl, it had long since scrolled off the screen. Switching back to “Default” display console the system boots. I should learn about SPICE and serial consoles.

The underlying error I was trying to find in the console is my restored virtual disk wasn’t mounting cleanly. There was a complaint about the GPT tables. I’m very grateful I went through the partition shrinking exercise because I sort of understood this; somehow the virtual disk changed size just a bit (a few megabytes?) from the physical disk, which breaks the secondary GPT table at the end of the disk. Fixing this isn’t too hard, this time I did it just by running fdisk and then issuing the w command with no changes. That rewrites the partition table and all seems well. gdisk is another option for fixing it, and maybe parted could. All this is very spooky. I can’t think why it failed the second time. I did resize the btrfs partition to 200GB before taking the new QCOW2 snapshot. But that shouldn’t change the full disk size and certainly not by just a few MB.

Path 2: tar clone of the root filesystem

Disk images are unwieldy; why not just clone the Linux root filesystem with tar or rsync or cpio? In theory this should work just like it would have in 1975. In practice it’s tricky because EFI booting and GRUB are such a mystery.

I found a nice blog post laying out how it should work. Basically you use tar on the whole system to create a snapshot (ideally when it’s offline). Then make a new disk with a bootable EFI partition and a root partition. Unpack the tar into the root partition, then ✨ just use grub-install ✨ to magically populate the EFI partition.

The GRUB step is the confusing bit. The guide above recommends using a chroot to run grub-install as if your old system were live. That’s what ended up working for me. (SystemRescue has its own idea for repairing GRUB. I couldn’t make either method work and it looks like the docs there may be several years out of date.)

Here’s the steps I followed.

Clone the old machine

  • Boot the system with the server to a rescue shell so the filesystem is not live.
  • Mount the rescue filesystem somewhere out of the way like /tmp/source
  • Tar the entire filesystem to an archive on an external USB drive. IIRC this is really as easy as cd /tmp/source; tar caf /mnt/usb/disc.tar.zst --one-file-system . The /dev/ files are harmless, tar is smart about those. Because the disk is not being used live there’s no need to exclude sys, proc, etc, even the one-file-system is probably redundant (but harmless).

At this point you have a clean tar archive of your server. It’s a nice backup!

Create the new VM and get it ready

  • Create the VM. I used systemrescue as the ISO for the boot media, then configured an empty disc for my new virtual server. See notes from Path 1 about OVMF BIOS, disk cache policy, and “host” CPU type.
  • On the Proxmox server command line set it up so the USB device containing your root filesystem tar file is passed through to the new VM. (There’s no doubt other ways to get the data into the VM.)
  • Boot the VM. In the OVMF bios menu, disable Secure boot in OVMF bios. Shouldn’t be necessary but it was the only way I could get the system rescue ISO to boot.
  • Boot system rescue and get to a Linux shell
  • Use parted to set up the new virtual disc. It starts completely empty.
    • Label the disk as GPT partition
    • Create one EFI system partition of 1GB. (See here).
      mkpart p fat32 0% 1GiB
      set 1 esp on
    • Create a BTRFS partition for the rest of the disc
      mkpart p btrfs 1GiB 100%
    • Create filesystems on the partitions
      mkfs.fat -F 32 /dev/sda1
      mkfs.btrfs /dev/sda2

Now you have an empty Proxmox VM all ready to go to have your filesystem transplanted into it.

Copy the filesystem in

  • While still in the rescue shell, mount the guest VM’s disc (/dev/sda2 in above) to somewhere like /tmp/dest and mount the USB source with the tarball.
  • Use tar to unpack the entire root filesystem from the USB disc. cd /tmp/dest; tar -xaf disc.tar.zst should do it.

At this point your VM’s disc has a clone of the server, from the tar file. All we have to do is get it to boot! In theory you can do this from a rescue disk right away, but let’s go ahead and install a proper boot system. But first...

Fix the block IDs

First it’s necessary to fix a few files in your new virtualized server’s root partition. The problem is the block IDs of your filesystems have changed and anything that refers to them by ID has to be updated.

  • Boot a rescue disk and mount the root filesystem to /tmp/dest
  • use blkid to identify the new blockids of the newly prepared filesystems.
  • edit /tmp/dest/etc/fstab to refer to these new block IDs. (or just use the /dev/sda names for now.)
  • edit /tmp/dest/etc/grub to include a line naming the block ID for the new filesystem.

Make the VM disk bootable

The last part is to let grub-install do its thing to set up the boot partition.

  • Boot the rescue disk and mount /tmp/dest
  • Prepare bind-mounts into /tmp/dest per step 7 of the guide.
  • chroot /tmp/dest and get a new shell in the Upside Down
  • Mount the boot partition: mount /dev/sda1 /boot/efi
  • Cast a magic spell for the ✨ EFI variables ✨
    mount -t efivarfs none /sys/firmware/efi/efivars
  • Run update-grub to pick up the new block ID you configured in /etc/grub
  • Run grub-install /dev/sda to install the EFI partition needed to boot
  • Exit the chroot shell and shut down the VM
  • In the Proxmox VM config, remove the SystemRescue ISO and the USB
  • Edit the VM options to include your new boot device
  • Boot!

This all actually worked and I had a working system. The downside is you have to make new partitions, new filesystems, and then install grub in a very weird way. The changed block IDs complicate things too. Overall this was much more complex than just making a disk image clone with QEMU or Clonezilla. But conceptually it might be “better”. I’m glad I learned how to do this but it’s not going to be my preferred method.

Path 3: restore from Proxmox backup

This is cheating, it’s not cloning a physical system. But just for comparison I tried using the Proxmox GUI to back up a working VM of my server to a USB disc and then restore it. It was very easy! This is the reward at the end of the tunnel. Next time I upgrade hardware I won’t have to reinstall anything other than Proxmox. Then I can just backup and restore VMs and containers. Or migrate them live in a cluster, maybe.

The backup of the ~80GB of actual disk data (160GB disk) was fairly quick (10 minutes?) and created a 56GB .vma.zst file. The restore took 20 minutes and took up 62GB of data on a ZFS volume.

Everything static was restored but the system had to be rebooted. Proxmox does support live system migration but that’s not what the backup does.

Thoughts

So that’s it, I now have tried four ways of migrating a working Linux server to new hardware. I’ve made all this sound very complicated. Honestly, it was complicated while I was figuring it out. I imagine half the readers are rolling their eyes saying “duh” and the other half are saying “wut?”. I’m not quite at the “duh” stage but I’m glad I’ve gotten past “wut?”. In particular I’m much more comfortable with manipulating Proxmox VMs, adding and editing hardware and disks and the like. And maybe GRUB is a little less of a mystery to me.

It’s remarkable how resilient a Linux install is to the hardware it’s running on. Virtualizing like this means changing every single hardware device, replacing them with virtual ones. Discs are entirely different. And yet everything still mostly works; putting in the new name for the network adapter was the only manual change required.

Proxmox: sharing files to container with snapshots

I finally figured out how to mount a directory in a container without making Proxmox refuse to do snapshots. The trick is to use lxc.mount.entry instead of a bindmount. Thanks to this Reddit hint. In detail...

I have a USB disc mounted on the Proxmox host as /mnt/usb-media. I want to share it to a container running a media server. When you look online for how to do this you quickly find that bindmounts are the way to do this. Basically it says “take this directory in the host and make it available to the guest”. This is the config in /etc/pve/nodes/pve/lxc/110.conf I was using:

mp0: /mnt/usb-media,mp=/mnt/usb-media

This works fine but has the side effect of Proxmox refusing to take a container snapshot. There’s an error in the GUI console saying “The current guest configuration does not support taking new snapshots”. I don’t know quite why that’s a problem, maybe it is concerned it can’t snapshot the contents of the mounted files? I’d be fine skipping those!

Anyway, the solution is a different config line:

lxc.mount.entry: /mnt/usb-media mnt/usb-media none bind,create=dir 0 0

This makes the files available, just like the bindmount did, but Proxmox will still take snapshots. The snapshots still seem to work. I didn’t test what they did with files on the mounted directory. In this particular application I should probably mark the mount read only...

The format is documented in the LXC man page but all it says it’s like an fstab entry. Note it’s very important that the third word, the destination directory, has no leading slash. It’s a relative path, relative to /, mnt/usb-media in this case. If you make it an absolute path there will be no error message but nothing is visibly mounted.

Proxmox’ docs are really not very helpful here. I have no idea what all a bindmount might do or how it’s more than the plain LXC entry. Someone else suggested trying to add replicate=0 to the bindmount options to make snapshots work. That didn’t work for me.

Anyway, I can play my mp3s and still snapshot the container, so mission accomplished.

Proxmox Linux container sizes (Alpine etc)

Continuing my Proxmox explorations, I’m looking for the smallest reasonable Linux container I can install to then do other things with. My starting point is Proxmox templates. Easiest to install with Proxmox tools but you can see the image sizes at the downloads here.

I’m mostly comparing the sizes of “df /”. That may not be a good measure. But for me it’s not just a measure of disk space, it’s also a proxy for memory usage and complexity. Of course I’m comparing systems without GUIs.

Alpine 3.18: 10MB

The gold standard for small Linux, really a lovely thing in just 10 MB. Hilariously almost half the storage (4MB) is in /lib/libcrypto.so.3, OpenSSL. I guess no one’s made a svelte SSL. Alpine gets to be so small by using libmusl instead of libc and replacing most of the userspace tools with busybox. The init is the very simple OpenRC. Despite that it has a huge number of packages you can easily install on top of it.

The downside is those replacements are very limited. The user space shell environment is enough to install something but can be frustrating. MUSL is also limited, see this post as an example of an obscure performance problem. It’s not bad, really it’s an impressive accomplishment, but it’d be nice to have an option that was both small and yet GNU libc based.

Debian 12: 540MB

Debian seems to be the default for a lot of Proxmox applications, but it’s half a gig on disk. From what I’ve read this is fairly pared down. Still it’s hard to quite understand where all the space is going. Some of it is just general system size. 136MB is shared libraries. 20MB for Perl, another 30MB for Python. Some of it seems superfluous: 50MB is locales (all of them?), 60 MB for the dpkg database, etc. It adds up.

One thing that’s encouraging is the Debian images keep getting smaller. Debian 12 is half the size of Debian 10!

Ubuntu: 640MB

No surprise, Ubuntu is bigger than Debian. More or less the same shape of things but just a little more of it.

Centos 9: 436MB

Not a fan of RedHat OSes but it’s a reasonable choice. Smaller than Debian but with similar sources of size. The locale library is 74MB! Also a 65MB GeoIP database that I bet isn’t necessary.

OpenSUSE 15.5: 178MB

I’d forgotten about OpenSUSE, to be honest, and am not sure whether it’s a good choice in 2023. It’s nicely small though! The bulk of it is binaries in /usr/lib64/ and /usr/bin. It’s still systemd and GNU libc. But there’s locale library at all, no python by default.. It meets the critera for “smaller”. Might be worth investigating what tradeoffs it implies.

Gentoo: 1800MB

Another distro I’d forgotten about, I picked this because in theory it supports musl. But not this template. And whoever built this was clearly not worried about size, it’s huge! There’s copies of package repos, SGML docbook, a 100MB test suite for Python, ... clearly no one spent time optimizing size here.

Other options

I should look beyond Proxmox templates. There’s a lot of other folks who’ve been working on the “smaller Linux for containers and VMs” idea. I should learn more about them. Docker’s got a bunch of them, in particular I keep seeing references to a “Debian Slim” that sounds promising. Docker’s overlay filesystem takes some of the sting out of bigger containers though, since the base OS storage can be shared.

Conclusions

I guess my ideal would be something with GNU libc but without systemd and without extra locales and binaries I don’t need. Ideally neither Perl nor Python required. Maybe what I want is “Alpine but with glibc and bash”. I’m willing to trade off some space for quality. I wonder if it’s realistic to be able to use pre-built Alpine MUSL packages for some things and glibc for others?

I’m probably overoptimizing. 540MB for Debian is probably what I should be using when Alpine won’t work, or maybe that 178MB OpenSUSE.

Proxmox what I installed

Following on my general post about Proxmox here’s a list of specific things I installed on my new home LAN server. As always this blog is mostly written for my own notes, but maybe other folks will find it interesting where I ended up.

Proxmox hypervisor

In general the idea is to customize the Proxmox host itself as little as possible, all my stuff should be going in guest operating systems. But Proxmox itself is a full Debian system with super cow powers and you can install other stuff. I kept it to a minimum just for administering the hypervisor:

  • apt install stress-tui stress-ng lm-sensors hwinfo joe sudo
  • Tailscale so I can access the management GUI from anywhere
  • The user “nelson” with my usual environment. Not really necessary.

I hand-mounted a USB disk of my media files by editing /etc/fstab. Proxmox seems to have no tool for managing USB disks. It doesn’t even automount them although I bet there’s some Debian thing you can install for that. As always be sure to use nofail in the fstab so it’ll boot without the disk.

I also wrote a script that uses pct list and pct exec to run a command in each container to print out their IP address. It’s kinda hard to find all your guest images in Proxmox’ UI if you’re using DHCP to assign addresses. (I wonder if there’s a way to get Proxmox to manage DHCP for its guests. Part of me wants a separate subnet for all the Proxmox hosted stuff.)

Ubuntu VM: old server clone (240GB, only 30GB used.)

My old server is virtualized now, see this blog post. I plan to migrate everything out of here and shut it down eventually but it’s real nice to not have to do that all at once.

Hacking container: Ubuntu template (1.4GB)

I have one container that’s just for general hacking projects. I suspect I’ll rebuild this from time to time other than preserving my home directory. I used the Proxmox Ubuntu template to make it, making sure to turn DHCP on. It’s unprivileged (which breaks ping). Here’s some stuff I did after install:

  • locale-gen en_US.UTF-8
  • apt install joe avahi-daemon git zip unzip rsync openssl webp ripgrep pigz python3 python-is-python3 python3-venv python3-dev pkg-config build-essential sqlite3 keychain curl
  • tailscale: have to enable tun access in Proxmox to make this work
  • My usual home directory environment.

Plex container: tteck (4.6GB)

I installed the Plex media server using tteck’s Proxmox helper scripts. These are a set of shell scripts to install a container in an OS and then the apps. Not sure why they don’t just distribute a template instead. I chose Ubuntu 22.04 instead of Debian and then it installed whatever Plex itself needs.

My media files are on the USB drive I mounted on the host OS. I used a bindmount to make the directory available in the container. Note that bindmounts break Proxmox’ snapshot mechanism, but backups still work.

The resulting image works great. Intel QuickSync, the GPU accelerator for transcoding, just worked with no effort on my end. Plex itself is easy to set up. I configured Plex to not run scans, intro detection, etc every night so it wouldn’t use all that CPU and disk I/O. But those jobs work fine.

4.6GB seems huge. over half of that is in Plex cache directories that were generated after it started running. I only gave this container 8GB, I wonder if it’ll run itself out.

Unifi container: tteck (2.1GB)

The Ubiquiti device management controller. Another tteck script, with Debian 12 this time. Also installed Tailscale myself. Ubiquiti’s system requires you migrate devices from an old controller to a new one which is fairly simple, basically making a backup of the config and copying it over. The actual migration process is a little scary, if it goes badly you might have to hard reset your devices.

Samba container: Alpine template (0.07GB)

A network fileserver for my music files, for Sonos. I did this one fully manually, starting with the Alpine 3.18 template. it was really easy, basically just apk add smb. I had to bindmount the media drive just like Plex. I wrote a new config file from scratch, smb.conf gets a lot more readable if you remove the hundreds of lines of comments from it. Dimly remembered the special downgrades Sonos requires to work (unix extensions = no).

Docker VM: manually (32GB not all used)

I set up a Debian VM to run Docker and Portainer using these instructions. I wanted to see how Portainer worked but I don’t know that I’ll keep using it. It’s not even running right now.

Monitoring container: TBD

The main thing left in my old server’s VM is a bunch of custom scripts I wrote to log monitoring data. I set this up a couple of year ago with Telegraf + InfluxDB + Grafana and it works well. So well I keep adding monitoring hacks without being careful about it, so now it’s a bit of a hairball.

I think the migration path is to set up Debian or Ubuntu on a new container, then install Telegraf + InfluxDB + Grafana there. Then somehow migrate all my Influx data and Grafana configs over. And all my monitoring scripts in Telegraf. That’ll let me turn off the VM versions of those things without much data loss.

But I’m sorely tempted to also improve things as I move them. Productize the monitoring scripts a bit so next time I move them it’s simpler. And maybe move off of Influx to TimescaleDB (a Postgres extension). That’d be more fun and having the VM working gives me time to do that.

I’m also unclear whether I should set up a separate container for each monitoring process, plus an extra for influx + grafana, and write the data with a network socket. That’s maximal containerization but seems like overkill, I probably won’t bother.

Backups and snapshots

One annoyance: there’s no tool for backing up the Proxmox server itself. Most people say “eh, just reinstall” but it’d sure be nice to have a copy of the configuration. Some folks have hacked things by copying off the config files with a script.

Proxmox does have backup tools for VMs and containers which are basically filesystem copies. I’m not certain how hard they are to restore but the web GUI has a “restore” button so presumably push-button. There’s a nice set of backup options trading off consistency vs disruption. If you stop the guest entirely you can make a cleaner backup but you don’t have to. Backups can be run manually or scheduled.

Proxmox also has “snapshots” which not only capture disk state but also memory. This seems to work great with a VM; I could snapshot, rollback, and my running processes are back in the old state. There’s also snapshots for containers but they don’t work as well. Bindmounts disable them entirely. And the restore of a container is not confidence inspiring; it took 30+ seconds and only restored file state, not memory or running processes. That all makes sense given what a container is, but makes me wonder whether container snapshots are useful.

Note that a backup run in “snapshot” mode is a different thing from a “snapshot”.

Proxmox, first impressions

So I’m setting up a new server and for the first time in my life I’m using containers and VMs instead of just installing a bunch of stuff into one Linux system and hoping for the best. It’s working pretty well so far, wanted to write down what I’ve learned so far. I’m new to all this, not an authority.

These notes are about the Proxmox Virtual Environment, a hypervisor OS you install directly on the bare metal. Its main purpose is to then host LXC Containers and/or KVM virtual machines which are running guest operating systems for your services. It also manages storage and some networking. Proxmox has been around 15 (!) years now.

Overall Proxmox has been a good experience. It hasn’t done anything dumb or frustrating and has some very useful capabilities. I’m glad I’m trying it.

Hypervisor choice

Why Proxmox? I picked it because it’s popular in the home lab / hacker communities and I have friends who use it. I definitely don’t want or need some enterprise-grade Kubernetes solution that’s designed for managing a fleet of hundreds of machines. I’ve got one $200 server, a couple of small disks, and very low requirements. But I do want it to be easy and fun to hack. Proxmox meets that market.

One special thing about Proxmox: it has equal support for full virtual machines and simpler LXC Linux containers. You can mix both with no problems. Of course you could run KVM in any Linux system, and you can also run containers in a VM with Docker or LXD or something. But Proxmox puts both front and center as equally supported options and I like that.

There’s a bunch of other choices for hypervisors or similar setups. I briefly looked at XCP-ng (a fork of XenServer), see this analysis. But it’s a little too new and I think doesn’t directly support containers. I also gave Portainer a quick try, it’s a GUI for Docker containers, but that’s really all it is and it doesn’t quite manage a whole system. Incus does have both VMs and containers, it’s a fork of LXD, but is too new for me. VMware ESXi is popular but proprietary, I wanted open source. There’s also a lot of solutions that are more command line / config file oriented, I was looking for something with a web GUI.

Finding guest systems

One thing that worried me in picking Proxmox was where I’d find images to use for containers. I want to install a Plex server: is it going to be a lot of work manually installing or can I just push a button? I think Docker Hub sets the standard for sharing images and was worried Proxmox’ use of LXC would be a problem.

No problem. Proxmox itself comes with some templates for generic Linux systems like Alpine or Ubuntu. tteck’s helper scripts are a popular way to install some complex products: I use it for Unifi and for Plex. Turnkey Linux also works well with Proxmox, it’s a set of cross-platform VM images.

Also creating a custom guest system from scratch is really not hard. For instance I wanted a guest Samba share for my music files. So I set up Alpine, then installed Samba in 15 seconds, then configured it with a text file and I was done. Now I have a 65MB container that’s serving my music. This was certainly no harder than installing Samba on bare metal and the ability to checkpoint and tear down / rebuild this one service made it easier than worrying I might break something.

BTW Alpine is a real pleasure if you want a lightweight Linux. It’s based on Busybox, so not a great general purpose environment, but plenty good enough to run a simple server or two. A new install in a container is 10MB of disk and 2MB of RAM and has almost nothing installed but you can bootstrap from there, there’s 20,000 packages or it. A VM install is 130MB of disk and 80MB of RAM.

There’s lots of other choices for Linux in a container. See this set of images and this discussion for some other ideas. I have a couple of Ubuntu guests for a richer experience. I haven’t tried doing anything GUI.

Various choices and learnings

I am trying to enforce a rule of one container per product / service. I currently have containers for Unifi, Plex, and Samba. I need to set one up for a collection of Grafana monitoring hacks I have. I currently have a grab-bag VM which is a virtualized clone of my old server that I’m migrating stuff off of. And I also have one scratch Ubuntu container for random hacks / interactive shell stuff and one VM that is running nothing but Portainer and Docker that I’ll probably end up never using. Creating a new container in Proxmox is under 10 seconds of effort, making new ones is fun!

Proxmox has a bunch of storage management options. RAID arrays, ZFS, LVM, Ceph. I opted out of all of that. I have one simple BTRFS partition for Proxmox and one external USB drive simply mounted into the host system and then bindmounted into the guests that need access to it. Guest systems are all on virtual disks, which Proxmox manages (files in the BTRFS partition, I presume.) I will revisit my storage setup at some point, the extra stuff adds complexity but I think there’s benefits. Maybe I’ll finally have a useful full system backup. There’s even options for migrating guests and something they call “high availability”.

I’ve almost exclusively been using Proxmox with its Web GUI. That’s remarkably complete, the only thing I’ve needed a shell command for so far was creating a bindmount. But Proxmox has an extensive command line interface which most of the docs treat as the primary product. I should learn it. It also has a rich API but I’m not sure what other clients that are that use it. I need to learn this. I haven’t even read the docs through yet! The GUI is good enough I can find my way to most things. (Except changing the font for the shell terminal emulator; that was hard to find.)

I’m mostly using containers for things instead of VMs, in the theory that they are lighter weight. The LXC containers are not really inescapably secure, something you mostly mitigate by not letting the containers have anything like root access on the hypervisor (“unprivileged”). VMs are fully virtualized and more secure but also add the overhead of running an extra kernel. I don’t really care about security; my alternative here is running all the processes in a single Linux system. But I do care about enough isolation to keep things understandable.

I’m not really clear on how much overhead all this encapsulation is costing. So far I haven’t come anywhere near the limit of my 16GB of RAM, 512GB of storage, or 4 relatively slow CPUs. Proxmox puts a cap on each guest’s resources but doesn’t preallocate them, so my various service containers are only using ~10–500MB of RAM each and no appreciable extra CPU. The one full Ubuntu VM is using most of the 2GB of RAM I gave it, but half of that is for disk cache (does a VM mean I cache the same disk blocks in both the host and the guest?).

There’s also latency and jitter overhead. But maybe not much? I run some 50 millisecond-scale timing code as part of my Starlink monitoring and I have no idea how much uncertainly the containers will add to those measurements. Just eyeballing the graphs, running in a VM (on an unloaded host) doesn’t add any noticeable delays. And I’m guessing LXC doesn’t add any significant delay either.

It’s annoying how every guest OS wants a root password. There is support for ssh or direct console login but that password is still there as a primary authentication. That feels very old fashioned.

File ownership and user IDs are a total mystery to me. The Unix user model is really not very helpful in the one-container-per-service model. I’ve been ignoring the problem and using root or whatever user the image I installed created. It’s going to be an issue when I share files on disks between containers though, like that USB drive with my media on it.

I’m not sure exactly what the containerization is really getting me. End of the day I have more complexity for the same services. But.. it feels right having each product isolated. Like that’s an important simplification. Also Proxmox has the ability to checkpoint and backup guests which could definitely be an improvement over what I used to do. I think it’s worth the investment and the overhead isn’t too high.

Things I’m missing

Here’s some things I haven’t figured out yet or that don’t exist. I haven’t read the Proxmox docs through yet, so maybe it’s there for me to discover.

Every container has its own IP and hostname. But Proxmox has no facility for helping you track those, does not provide any sort of automated DNS for them. I’ve been installing avahi-daemon in some containers so .local mDNS names work but that seems silly. I’m also a little worried about running out of addresses in my /24. I guess I could expand the home subnet.

It feels like Tailscale could also be integrated in to Proxmox somehow. The main option seems to be to install Tailscale in each container and treat it as a separate host on the tailnet. (Which requires some config for unprivileged containers). That’s probably the right model but feels a little awkward. Also Tailscale’s binaries are 50MB, or 5x the size of the Alpine container ;-)

I still haven’t worked out how to share files across containers. Web searches suggest networked file systems: SMB or NFS or even 9P running as a server on the host and mounted on the guests. Yuck! I’m using a bindmount for a USB disk right now, that basically just shares the Unix directory from the host to the LXC guest. (You can also pass the USB device itself through and mount it only in the container, but that’s not really sharing.) I’d like some general solution for sharing disks, need to research. Maybe there’s an answer in Proxmox’ storage system which I’ve been ignoring so far.

Cloning a physical Linux system into a Proxmox VM

Working on replacing my failing server hardware with a new server running Proxmox. Finally realized I could just clone the whole OS off the old system rather than laboriously rebuild every service in a new way as containers on the new server. Clone first, then migrate later. Easy right?

Actually not too hard. The Proxmox wiki has several ways to do what they call “Physical-to-Virtual”, the primary one being “use Clonezilla to clone the entire disk into a KVM on Proxmox”. That’s what I ended up doing but it took about eight tries.

First, though, a minor complaint. It should totally be possible to move a Linux system solely by copying the files with rsync, not the physical disk block by block. I know this can work. But in practice the challenge is making it bootable. I think the modern way to do this is to install Grub in a second UEFI partition, then configure / use it to invoke the kernel on your main system. But the details of that are fiddly and opaque. So I cloned the disc.

The instructions on the wiki more or less worked. I wasted time on a few tries trying to migrate to a smaller virtual disk on the new server: the old server had 20 GB of data on a 256 GB partition. Proxmox has various options that look like this should work but I never could make it work, made doubly exciting by the way the clone tool doesn’t even check if you have space on the receiving disk for what you are cloning. (It worked for 15% and then failed on a seek error, lol.) Anyway, here’s my detailed notes during the process:

  1. Did a quick cleanup on the old server of disk usage, removing old log files etc to get the size down.
  2. Used Clonezilla to back up the whole disk to a USB drive as a safety measured.
  3. Booted Clonezilla remote source on the old server per these instructions.
  4. Booted Clonezilla remote destination on the new server
  5. Tried cloning to smaller partition. First time failed immediately (with no resizing options) without a clear error. Second time I told it to resize partitions proportionally; that failed a couple minutes in on a seek error, presumably trying to write past the end of the new smaller partition.
  6. Fortunately Clonezilla is fairly quick. It’s smart about not cloning unused space, also uses zstd. My copy operated at a nominal 12GB/minute (over gigabit ethernet from SSD to SSD).
  7. Finally gave up and allocated a destination partition bigger than the source. Clone succeeded but it didn’t boot; hung with 1 core at 100%.
  8. Searched the net for advice, found my way to this thread which suggests using an EFI BIOS in the VM instead of the default legacy Seasonic BIOS.
  9. First time cloning to EFI BIOS failed with a bit error on the copy. (Did I mention the old hardware is failing?) Filezilla detected the error, then ignored and made a valiant effort to recover from it. The resulting image was incomplete and did not boot.
  10. Cloned a second time and it worked! The new VM successfully booted to my Linux partition.
  11. systemd hung because fstab was trying to mount a hard drive on the old server that didn’t exist in the VM. Used rescue shell to remove those entries from fstab.
  12. Reboot did better, but got stuck getting network configuration up.
  13. Used a rescue shell to edit /etc/netplan/10-nelson.yaml to rename the ethernet device. (Use “ens18” instead of old “eno1”.)
  14. Reboot, comes up, but now no networking. Realize I’d left the old system running on the same IP. Ooops.
  15. Turn off old system, reboot VM and it works! I have successfully cloned the old server.
  16. apt install qemu-guest-agent. Not strictly necessary but helpful. Despite what the wiki says you can’t start this with systemctl in Ubuntu 23.04. It seems to start automatically somehow if you’ve enabled it in the Proxmox host options and reboot.

Clonezilla does work, and it is free. But oof is it old fashioned and clunky. I could see it totally being worth paying money for a nicer system cloning tool if you did this more than once every few years.

Boy does the BIOS make things complicated. I sort of understood the old legacy boot process but UEFI and GRUB are complex enough they make me nervous. I have zero motivation to sit down and really learn them.