Some Bits: Nelson's log

17 posts in January 2024

Pixel cases vs Android gestures

Current phone design drives me crazy. They make these beautiful devices that look great in product shots with fancy glass backs. That are so damn slippery you immediately have to put some ugly case on the phone so it doesn’t fly out of your hand. They never show the necessary case in the product marketing shots.

Worse, the trend to slab-of-glass means there’s nothing really for the case to grab on to on the front of the phone. Cases have to have a little rim that extends above the glass. Which then gets in the way when you try to make swipe gestures from the edge of the screen, your thumb hits the raised case edge and misses the edge of the glass. This was particularly bad in the brief trend towards curved glass on the sides so there was no bezel at all.

The swiping is a real usability issue. Android makes heavy use of swipe gestures: from left for back, from right (sometimes) for delete, from the bottom to switch apps. And every single time I tried to do them the case got in the way. The raised lip is a help for protecting the phone, particularly if you drop it on its front, but it makes the phone harder to use.

Anyway, I tried a bunch of cases. Here’s a few.

  • Peak Design: the winner! This case is super thin in front, a very low profile. It’s still raised a tiny bit but so little over the phone it doesn’t get in the way. Unfortunately none of their product marketing shots show the front of the case, probably because they want to downplay the relatively ugly plastic frame that holds it on. But here’s a still from a video I made that shows it.
  • Ringke Onyx: the runner up. It’s cheap and pretty ugly. But there’s cutouts on the sides that help with side swipe gestures, see this shot. Even so the bump on the sides is still annoying enough to interfere. And there’s an enormous raised lip on the bottom which makes swiping up really awkward.
  • Caseology Nano Pop: a disappointment. Raised rim all around, no effort made to accomodate a swipe.

I considered giving up on a case entirely and just putting some sticker on the back so I could still hold it. Something like Dragon Grips. But they are so ugly. I did try ordering a dbrand skin which was a terrible waste of money. The sticker I got is still slippery. And the edgelord marketing extends all the way to customer support, the installation video has a dumb joke where the instructions to align the sticker should have been. I got a condescending response from their support when I asked for help. Screw those guys.

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.

Starlink latency improvement

Interesting trend here; starting around the first of the year the latency of my Starlink connection has gone down, as measured by IRTT pings to a server I run at BlueVPS in LA very close to my Starlink’s terrestrial egress.

IRTT latency measurement

I think this effect is real. Comparing the week starting 2023-12-11 to the week starting 2024-01-08, the mean went from 47ms to 39ms. That’s 8ms or almost 20%! I think worst case performance is better too, I can’t quite quantify it but the 99% is a lot less spikey and the maximums are lower. (See graphs at bottom) Looking at data for a year this is a major new change; it was steady at about 47ms for a whole year.

Update: a tweet from the SpaceX CEO: “Significant improvements have been made to @Starlink latency (ping) & many more to come. Target is <20ms.” Guess that confirms what I observed.

I don’t see any corresponding change in packet loss. Averaged about 0.56% packet loss in both weeks.

I don’t have a good way to guess why this might have improved. There’s basically no measureable latency between the first hop I can see after Starlink and my monitoring host at LABlue; I’ve always assumed they’re in the same datacenter. My memory is it was never more than 2-3ms at most.

There’s a similar effect visible in Starlink’s own reported latency number (from the gRPC debug data). That should rule out any question of my IRTT monitoring, Starlink’s own numbers show the same pattern.

Starlink gRPC latency

A simple explanation is improvements to Starlink itself. Either they’ve lowered the latency of their infrastructure or they have more capacity and so my packets are getting buffered less. Possibly the improved 95% performance suggests less buffering but I wouldn’t bet heavily on that guess.

Interesting that it’s a downward trend over a week, not a drop in one day. That suggests it’s maybe a gradual change in capacity rather than a step function change in routing setup.

Here’s detailed graphs of before and after.

Before, 2023-12-11
After, 2024-01-08

And a graph of a whole year:

(For completeness, I should note I changed my IRTT monitoring setup around December 10 when I migrated the server from a physical machine to a virtual machine inside Proxmox. But this change clearly post-dates it. Also if anything the virtualization should cause more latency or packet loss although I’ve seen no evidence of that.

8bitdo SN30 Pro controller vs Steam

I have an 8BitDo Sn30 Pro game controller, a nice little portable Bluetooth / USB game controller that works in various modes. I had some initial flakiness but now it’s working well. The best discussion I’ve found is this Steam forum thread; if you read past all the rude people flaming each other there’s some useful info.

Working with a USB wired connection is easy. Working with Bluetooth seems to work reliably for me, at least right now. But I had to remove and re-add the device in Windows Bluetooth settings at least once, for awhile it was acting flaky.

The first insight is that the 8bitdo controller works in several modes that you can switch between depending on how you turn it on / use it.

  • Start+Y: Nintendo Switch mode.
    Windows sees this as “Pro Controller”, Steam sees this as “Nintendo Switch Pro Controller”. It seems to work pretty well for PC games although Steam may have to remap some inputs for you because few PC games support this directly.
  • Start+B: “Android mode”, which I think is the older DirectInput API.
    Windows says “8Bitdo SN30 Pro”, Steam says “Bluetooth Wireless Controller”.
    Steam made me set up the button mappings, pressing each button in turn. All of them worked except the last share button.
  • Start+X: “Windows mode”, which I think is the newer XInput API.
    Windows says “8Bitdo SN30 Pro”, but gives it a different listing in the Bluetooth devices from the Android mode entry. Steam says “XInput Controller”. Works well but no share button.
  • Start+A: “macOS mode”.
    Windows calls it a “Wireless Controller”, Steam calls it a “PS4 Controller”. The buttons all seem to work as expected.

The second insight is that these modes look like completely different Bluetooth controller entries in Windows. It’s like you own four separate devices depending on which way you turn the controller on. You have to configure each one individually in Windows. (Or pick the one you want and stick with it). I think one time it got confused and that’s why removing the Bluetooth device and re-adding it helped.

I think XInput mode is probably the best choice for most PC games.

There’s a small Star button in lower left on the 8bitdo. This works as a regular button in Nintendo Switch mode. But in XInput mode (and DInput?) this is a Turbo button, if you hold it down with a different button it toggles that input rapidly. In that mode the button itself doesn’t seem visible to the PC. Not a big loss but it means you won’t have a Share button.

One extra quirk: I bought the Switch edition of the SN30 Pro which has Nintendo’s bizarro button layout painted on the controller. So the button at the bottom of the cross on the right says “B”, not “A”. Steam has you identify buttons more by position than the labels so it’s not too big a deal to adapt.

PS: a big raspberry to Sony whose PS5 controllers are prone to stick drift. I used Steam to see the numeric outputs from the device. The stick gives reading from -32767 to 32767 with ideally 0 when at rest, or at least close to 0. My stick regularly jumps between -20000 and 0 with no input at all. I can’t even set a deadzone easily, Steam’s max is 18000. (And mapping 2/3 of the range to 0 is not a great experience anyway.) This flaw is common among PS5 owners. They aren’t cheap at $70.

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

GRUB alternatives

I’ve never liked GRUB much. I don’t understand it and it makes me anxious. I never have good experiences using GRUB, I don’t want to use GRUB at all really. I want to use Linux. The only time I think about GRUB is when something goes wrong and my system is broken.

Anyway, there’s alternatives to GRUB in the modern UEFI world. EFI itself really was designed to be a boot loader, it’s weird we only use it to boot a second boot loader. Why not boot Linux directly?

One reason is drivers and filesystem support. EFI supports FAT12, FAT16, and FAT32. If you want to put your kernel on a more Linux-native filesystem you need something to load a driver for it in EFI first.

EFISTUB. The option with no extra boot loader. You build the Linux kernel with an option that makes it directly bootable from EFI. There is no boot firmware or OS at all; the EFI BIOS directly loads the Linux kernel. You put the kernel and initial ramdisk in the existing EFI partition, which is probably a FAT32 filesystem. Then you use efibootmgr from Linux to tell EFI about your kernel and the command line options to boot it. This seems remarkably straightforward.

systemd-boot. Yes, systemd also comes with a boot manager, a whole mini-OS. You install systemd-bootx64.efi in the EFI partition as an EFI boot manager. You put an ordinary Linux kernel and init ram disk in a XBOOTLDR boot partition and systemd-boot calls them. You can also have systemd-boot load drivers for devices and filesystems to get to your Linux kernel.

rEFInd (formerly rEFIt). Another boot manager. It has some built-in support for some filesystems and can load drivers. This one boots EFISTUB kernels, not normal kernel images.

So three different boot managers all roughly similar. Or boot the kernel directly via EFISTUB. I’m not sure in practice any of these buy me much over using GRUB. They all seem simpler than GRUB, that seems like a small advantage.

I think all of these are tricky with Secure Boot. One nice thing about GRUB is it has a binary signed by a key that commercial computers already recognizes, no work required. For the other options there’s some magic tool called sbctl that seems to be able to sign binaries so Secure Boot will boot them. There’s a step of “enroll keys”; you create your own your own signing key that you then install in the BIOS as a one time thing. Then with sbctl you can sign any binary. (Here’s some notes on a manual process instead).

With all of these alternatives you need to evaluate what your plan is to getting to a rescue mode or single user if you have to. Honestly for me my plan is usually “boot from USB”, not relying on whatever GRUB has access to. But I think all 3 boot loader OSes have some menu or command line editing. EFISTUB direct is trickier, but maybe the BIOS EFI shell can do.

Now that I have Proxmox set up it’d be easy to create VMs to experiment with this. I wonder if the OVMF UEFI BIOS they offer causes any issues. A quick search doesn’t show any clear guides on how to use alternate boot methods with OVMF but a bunch of suggestions it should work.

For that matter on a virtual machine it’s not clear using UEFI really offers any advantages over the old fashioned MBR-style BIOS. I kinda miss LILO. (IIRC, you could also boot Linux directly from an MBR BIOS with some tricks, but not sure about initial ramdisks.)

ssh attacks

I knew botnets testing ssh passwords was a thing but I didn’t realize it was this bad. Here’s one minute for my home server which I need to be able to ssh into.

Jan 11 01:14:00 tt sshd[294770]: Failed password for root from 98.97.59.56 port 27496 ssh2

Jan 11 01:14:09 tt sshd[294773]: Invalid user ftp from 212.70.149.150 port 62358
Jan 11 01:14:13 tt sshd[294773]: Failed password for invalid user ftp from 212.70.149.150 port 62358 ssh2
Jan 11 01:14:22 tt sshd[294789]: Failed password for root from 43.159.32.231 port 44228 ssh2
Jan 11 01:14:40 tt sshd[294795]: Failed password for root from 127.0.0.1 port 44192 ssh2
Jan 11 01:14:46 tt sshd[294816]: Failed password for root from 35.194.181.153 port 54910 ssh2
Jan 11 01:14:49 tt sshd[294818]: Failed password for root from 165.22.51.149 port 35608 ssh2
Jan 11 01:14:52 tt sshd[294838]: Failed password for root from 180.101.88.236 port 13566 ssh2
Jan 11 01:14:54 tt sshd[294838]: Failed password for root from 180.101.88.236 port 13566 ssh2
Jan 11 01:14:57 tt sshd[294838]: Failed password for root from 180.101.88.236 port 13566 ssh2

There are 97,354 of these attempts in five days, or a rate of once every 5 seconds.

The simple protection is to disable root login in sshd. I’d rather not deal with the requests. Some folks run ssh on an unusual port; that’ll at least cut down the traffic. fail2ban is also a popular solution but I’ve never liked how it works. Scanning logfiles? Really? And what if it blocks my legitimate logins somehow?

Here’s the top 20 users other than root being probed. Passwords really are a terrible form of authentication.

    796 admin

601 user
505 ubuntu
389 debian
238 test
147 oracle
92 ftpuser
88 postgres
72 deploy
67 git
66 mysql
59 hadoop
51 guest
47 student
47 es
47 centos
46 dev
44 test1
43 www
42 pi

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.

Kiwix libraries for offline Wikipedia

It’s still hard to set up offline Wikipedia on Android with Kiwix. Fortunately the app is getting updates again after the year+ mess. The new app works well and you can download ZIM libraries in the app and they work fine. But getting the full 100GB Wikipedia is difficult to impossible from their downloader.

Here’s what I did to download the ZIM file to my PC, then copy it to the phone. These steps may require the phone be in developer mode; that’s safe in Android and is not the same as rooting the phone.

  1. Choose a ZIM file. I picked the 101.6GiB wikipedia_en_all_maxi_2023-11.zim
  2. Download the ZIM file on your PC.
    I used this torrent which came from their library. (Note browsing and linking this site is awkward). Another option is a direct HTTP download from their site.
  3. Launch the Play Store Kiwix app on your phone and use the app to download something small, like the top 100 articles. The goal here is just to get a storage folder created.
  4. Mount the phone via USB on your PC.
  5. On the PC, go to the directory
    Pixel 8\Internal shared storage\Android\data\org.kiwix.kiwixmobile\files\Kiwix
    You should see the small ZIM file that you installed in step 3 there.
  6. Copy the big ZIM file you downloaded into the directory
  7. Launch the Kiwix app and choose Library. You should see your new file.

Reddit is full of people saying they did this and it did not work. I’m not sure what’s going on. Maybe developer mode helps?

If the above steps don’t work, it’s recommended you uninstall the Google Play Store version of Kiwix and sideload a download from Kiwix itself. This has extra capabilities the Play Store won’t allow, including file access.

Another option is to install the Kiwix PWA, a fancy web page that works like an offline application. For some confusing reason PWAs on Android (which are not reviewed) can access your entire filesystem even if individual apps (which are reviews) can’t. That’s Google’s fault. Kiwix has been developing their PWA a lot recently. I haven’t really tried it.

The underlying problem here is Android keeps ratcheting up platform security and has slowly eroded the principle that apps can access files. I would hope nothing would stop this direct USB transfer but I don’t know anymore. I have other apps that can still access the filesystem, like SolidExplorer. Maybe Google gives them an exception that Kiwix can’t get?

Choosing a ZIM file

Kiwix has made it very hard to find the ZIM file for Wikipedia. The product usability is really bad.

It seems the ZIM libraries come in the following flavors:

  • Mini: summary sections only with pictures
  • Maxi: full articles with pictures
  • Nopic: full articles without pictures
  • ???: no videos (almost all of them seem to be this but there’s exceptions.)

If you search for “Wikipedia” in the mobile app, you get a bunch of special interest things like “Ray Charles Wikipedia”. If you weed through those you can finally find actual Wikipedia. But the labels are (currently) wrong. For instance the screenshot at right shows 4 different versions of the top 100 articles. But one is mislabelled: that 14.1MB one does not contain videos. I think it’s actually wikipedia_en_100_mini_2023-12.zim which is only the summary section of each article, but has pictures.

In theory you can use the Google Play store app to download the full 100GB Wikipedia all in your phone. Nice! Assuming you can make that download work reliably on a phone, that is. But in practice I literally can’t find that ZIM file in the downloader, it’s like it’s hidden. The closest I could find was the 56GB all nopic.

BTW these files are huge for a phone! If you want something smaller try wikipedia_en_top_maxi_2023-10.zim. That’s 50,000 articles at 6GB. I do think it’s worth getting the full maxi with pictures; very useful in offline situations.

Kiwix also has a new Library webapp which lets you view the ZIM files in your browser. It seems like a nice idea! But again, the usability is terrible. What’s the difference between these 4 libraries in the screenshot below? Other than the size.

I feel bad picking on an open source project like Kiwix. But the product has had these usability problems for years now. They get funding from Wikipedia, maybe it’s not enough.

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.

Restic for backups

I finally have a better backup solution: Restic. This project has emerged as the open source favorite for backups. It’s easy to see why: it’s very capable and a very professional product. Don’t be put off by the scary 0. version number: there’ve been releases for seven years now. And it seems really solid.

For many years now I’ve relied on rsnapshot for backups. It’s nothing fancy but is straightforward. But it basically requires you have root access on both the source machine and the backup server. (rsnapshot stores actual copies of your files, complete with timestamps and owners). And it’s slow and creaky and, well, time for something new.

Restic is very fancy. The underlying repository datastore slices your files up into 1MB blobs and storing them in a sort of content-addressable store. Everything is encrypted and indexed by the SHA256 hash of the data. That makes verification, deduplication, etc straightforward and fast. The downside is the backup format is entirely opaque; you need the restic binary to work to restore files. (It is documented, but far too complicated to easily reimplement.) The upside is it is very efficient.

The product packaging is fantastic for open source. It ships as a single self contained Go binary. The docs are terrific including a quickstart that gives a vey good experience. It supports a wide variety of backup server types from local disk to sftp to cloud providers (or rclone if you want to do your own thing). There’s good tools for inspecting backups, verifying them, restoring them (including a FUSE mount). Also a first class tool for removing old snapshots. The tool gives a lot of confidence.

restic runs really well and fast. I can back up 50GB of my data to 38GB in the repo in about 6 minutes, about the speed the disk runs at (and this over NFS). An empty incremental takes just 10 seconds.

The one thing missing is some usability for system integration; you’re left writing your own shell scripts and cron jobs to use it. Fortunately there’s a CLI frontend called resticprofile which helps with that stuff, driven by a simple config file. It’s not quite as clean a product as restic itself but it has good docs and seems to work well. And what it does is not mysterious, it’s just invoking restic, so I’m not as concerned about the niceties.

Edit: another option for managing restic is backrest, a web GUI. Update Aug 2024: finally gave this a try, it is very nice.

It’s a real pleasure to use a nicely built open source tool like restic.

Update 2: offsite backups

I’m using Backblaze now for offsite backups. It seems to work OK and is fast and cheap ($6/TB/mo with no minimum. plus extra for bandwidth if you use much.) Was fairly straightforward to get working with Restic. Configuring the bucket is a bit tricky; I turned off encryption (restic is encrypted already) and file retention.

I tried SFTP briefly to a small server I have. It was very slow, like 6 minutes for 2GB (or less). To be fair my server is slow.

Update: system backup config

Here’s the fairly simple resticprofile config I’m using to back up my main Linux system. It backs up to local disk once an hour and keeps old dailies, weeklies, monthlies, and yearlies on a reasonable schedule. The only subtle thing here is I’m backing up in two separate jobs, once for my home filesystem and once for the system root.

version = "1"

[global]
  ionice = true
  nice = 5
  scheduler = "crond"
  restic-binary = "/usr/local/bin/restic"

[default]
  repository = "local:/mnt/backup/restic"
  password-file = "/usr/local/etc/restic/password"

# Everything but my home directory

[root]
  inherit = "default"
[root.backup]
  source = [ "/" ]
  exclude = [ "/home/nelson", "swap.img" ]
  one-file-system = true
  schedule = "*-*-* *:37:15"
  schedule-permission = "system"
  schedule-log = "/var/log/restic.log"
[root.retention]
  keep-hourly = 24
  keep-daily = 7
  keep-weekly = 4
  keep-monthly = 60
  after-backup = true

# My home directory

[home]
  inherit = "default"
[home.backup]
  source = [ "/home/nelson" ]
  one-file-system = true
  schedule = "*-*-* *:07:15"
  schedule-permission = "system"
  schedule-log = "/var/log/restic.log"
[home.retention]
  keep-hourly = 24
  keep-daily = 7
  keep-weekly = 4
  keep-monthly = 60
  after-backup = true

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

Making peace with journalctl

Journalctl is systemd’s much-maligned replacement for syslogs. Crusty old nerds like me are mad it’s not just a text file. But the binary format actually has a lot of advantages, you can efficiently do simple time and metadata queries. I also like the color pager it gives you. Now that I’ve learned a bit about the journalctl tool I like it more.

journalctl -b
Entries since last boot. Solves the big problem of journalctl spamming you with useless crap from months ago. journalctl -b -1 will show you the boot before this one.

journalctl -n 100
Last 100 entries

journalctl --since '3h ago' --until '2h ago'
Time slicing. The since and until format is defined in systemd.time(7).

journalctl -u chrony or journalctl -t chronyd
Entries matching a unit name or syslog identifier

journalctl -g chrony
Entries whose contents match a grep expression. Note this does not match the displayed text of the metadata, it’s not the same as grepping a syslog.

journalctl -p 4
Level warning or more serious. The levels are the same as old syslog.

journalctl -r
Reverse order.

journalctl -e
Jump the pager to the end (like pressing G).

journalctl -n 100 -f
Display the last 100 entries and keep scrolling new entries forever

journalctl --vacuum-time=7d
Erase all logs more than a week old. Useful for making disks smaller.

journalctl --dmesg
Emulate dmesg, only showing kernel messages (but in a different format).

usermod -aG systemd-journal nelson
Anyone in group systemd-journal can run journalctl without being root, at least on Debian. Note this includes the ability to modify the journal.

The big thing missing is negative filters. I want to show all log entries that are not from the spammy sshd and cron units. Can’t really do it.

You can still do journalctl | grep of course. There’s also a JSON output format you can manipulate with jq or the like.