Some Bits: Nelson's log

17 posts in December 2023

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.

Shrinking a VM disk image: loss and recovery

A small experiment. I have a 2TB physical disk (SSD) with about 80GB of real data on it. I want to shrink that 2TB to a virtual disk that’s 150GB; 80GB of data and 70GB of free space. The disc has two GPT partitions, almost all of the space allocated to the second partition. That partition is formatted with BTRFS.

I managed to do this but it was kinda scary all the way, particularly the part where I broke everything and lost all my disk partitions. I did recover it in the end but I do not recommend the experience. I was playing around on a test VM so it wasn’t a catastrophe, but if this were a precious system I would have been very unhappy.

To cut to the chase: resizing the filesystem and the partition were easy. But shrinking the virtual disk with qemu-img caused big problems. The underlying problem is that GPT has two copies of the paritition table: a primary at the start of the disk and a secondary at the end. Changing the disk size screws up the secondary and Linux gets angry and won’t recognize the partitions. You can repair the GPT partition table manually with gdisk but it’s scary. This may not be an issue with old fashioned MBR partitions.

Battle plan

The simple way to do start is gparted’s GUI; it will resize a btrfs filesystem and partition for you. But I’m stubborn and using command line tools. The plan is roughly:

  1. Clone the physical disc to a QCOW2 image
  2. Clone the QCOW2 image with qm import disk to whatever raw format Proxmox wants.
  3. Build a VM around that Proxmox clone.
  4. Boot the VM
  5. Use btrfs filesystem resize to resize the filesystem inside the live VM.
  6. Use parted on the disk to shrink the partition for the filesystem we resized.
  7. Reboot and test it’s basically working but the partition is now really smaller
  8. Shut down and use qm resize on Proxmox to make the disc smaller. This is the part that broke.
  9. Repair the damage with gdisk
  10. Reboot and you’re done!

The first few steps are documented in other blog posts and are about moving a physical disc to a VM. The rest of this post is about resizing a Proxmox VM disk in QEMU raw format.

btrfs filesystem resize

The goal here is to make btrfs think the partition is smaller than it used to be, moving all the data to the front of it so you can then lop off the rest of the partition. It’s pretty straightforward and can (must) be done on a mounted disk.

# time btrfs filesystem resize 150G /

Resize device id 1 (/dev/vda2) from 1.82TiB to 150.00GiB
real 0m21.361s
# btrfs filesystem show /
Total devices 1 FS bytes used 72.25GiB
devid 1 size 150.00GiB used 95.02GiB path /dev/vda2
# df -h /
/dev/vda2 150G 74G 75G 50% /

The filesystem resize was quick and easy! As far as everything is concerned the filesystem is now 150GB big, not 2TB. However the partition is still 2TB.

Parted

Now I want to repartition the disk so nothing is using space beyond 150GB. I’m using parted to edit the partition table on the live disk, the one that is running the OS I’m running parted from. That’s not a good idea, it’d be safer to boot from rescue media. But I’m feeling spicy and this is a test VM.

It’s very important to separate “GB” (1,000,000,000 bytes) from “GiB” (1,073,741,824 bytes). btrfs filesystem is explicit about talking in GiB. parted understands both but seems to prefer the base 10 smaller numbers. You can change that with unit GiB in parted.

unit GiB print
Number Start End Size File system Name Flags
1 0.00GiB 1.05GiB 1.05GiB fat32 boot, esp
2 1.05GiB 1863GiB 1862GiB btrfs

(parted) resizepart 2 155GiB
Warning: Partition /dev/vda2 is being used. Are you sure you want to continue?
Yes/No? y
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? y

(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 1863GiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 0.00GiB 1.05GiB 1.05GiB fat32 boot, esp
2 1.05GiB 155GiB 154GiB btrfs

Note I chickened out and made the new partition 154 GiB, a few GiB bigger than the filesystem. I don’t trust my math. The correct number for the end of the partition would be 1.05GiB + 150GiB. (But oh god does parted round down by a few bytes?)

I rebooted and verified everything worked. I now have a 2TB disk with only 155GiB of partitions on it.

Resizing the QEMU virtual disc

This is the part where I broke things. I wanted to make the actual VM disk smaller, to shrink it from 2TB to 150GiB (or a bit bigger)

Proxmox explicitly does not allow shrinking a desk with the GUI or qm command line tool. The docs just say “that’s dangerous and we won’t help you”.

However it’s still possible to do it with command line tools. I did this with qemu-img on a raw image. That linked page talks about LVM as well. Note that both qm and qemu-img seem to work in binary sizes. Ie: 1G is 1GiB, 1,073,741,824 bytes. I sure hope this is consistent everywhere since it’s not explicit.

First, I shut down the VM. I did some experiments on a scratch monkey while the VM was still up and bad things happened. The file size of the .raw changed on the Proxmox host, but even after rebooting the size looked like the old size inside the VM. It must only work to resize a disk if the VM is offline.

# ls -l disk.raw
-rw-r----- 1 root root 2000398934016 Dec 30 18:49 disk.raw

# qemu-img resize --shrink -f raw disk.raw 156G
Image resized.

# ls -l disk.raw
-rw-r----- 1 root root 167503724544 Dec 30 19:18 disk.raw

# qm rescan
# rescan volumes...
VM 100 (virtio0): size of disk 'local-btrfs:100/vm-100-disk-1.raw' updated from 1953514584K to 156G

Looks like it worked! Note the qm rescan is necessary.

But then disaster. Reboot failed. Getting to a rescue disk , blkid didn’t show any of my partitions. fdisk and parted on /dev/vda showed scary errors like “GPT PMBR size mismatch (3907029167 != 327155711) will be corrected by write.”

I was able to correct things somewhat by using qemu-img resize again to grow the disk back to 2TB, its original size (to the exact byte). Even then nothing was working. But now parted and fdisk reported “The backup GPT table is corrupt, but the primary appears OK so that will be used.” I used gdisk (a new-to-me program) to interactively repair things. It used the primary GPT table for the info and rewrote everything. And it worked! But this was all super scary. And I’m back to a 2TB disk.

I have a theory for what went wrong here. Apparently GPT writes two copies of the partition table; a primary at the front of the disk and a secondary at the back. When I shrunk the disk the second copy was removed, then when I made the disk bigger again it was “back” but now zeros instead of data. And so there was a minor complaint with the secondary and gdisk could work around it. Not a big deal to recover from but spooky.

But I really wanted the disk smaller. So I resized it again, booted to rescue, and used gdisk. And ran the v command. Look at all these errors!

Not only is it unhappy about the secondary partition table being wrong but also it is aware that the disk used to be bigger and stuff is inconsistent.

I used the suggested e command (or was it r?) as suggested. That basically says “trust the primary” and generate a new partition table. Then w to write the change. That all worked fine; both gdisk and parted no longer reported errors. Is it done?

Reader, the system rebooted with no problems. Ubuntu was saved!

Ideas for doing this more safely.

gdisk has options to back up GPT partition data to a file and restore it. I’d definitely use that before monkeying around with any of this.

I would use the gparted GUI tool for most of the work. It handles both the btrfs resize and the repartitioning. It’s not going to anticipate the GPT partition weirdness of a qemu-img shrunk disk, but maybe it has nice tools for recovering from the mess too.

Phone migration: what I think should happen

Lots of responses to my rant about the bad experience of getting a new Android phone. A real mix. Some folks saying “worked for me!”. Some folks saying “I had those same issues but they didn’t bother me”. Not so many people just saying “I feel your pain, it should be better” but then my post was ranty enough that I expected aggressive responses.

Here’s what I would like for a phone migration experience.

Requirements

Every app should transfer all settings and data. Every preference and config. All data, including cached data you could download over the Internet again. The migration process should be more comprehensive than restoring from a cloud backup; the data is already available locally. (I’ve seen hints that Android does better with a USB wired migration vs. wireless. The Pixel 8 never prompted me to plug in a cable so I didn’t try it.)

Every single app should be aware I migrated. Most apps probably shouldn’t care but some may need to respond to a migration event so the product needs to adapt to the new hardware somehow.

Low stakes apps like Spotify should keep me logged in. The migration was a secure process, my login tokens should transfer too.

High stakes apps like banking or a password store might choose to reauthenticate me after migration, for extra security. But the app on the new phone should already know who I am, already have my username pre-filled. Apps that require two factors for login on a new install should only require one of those factors on a migrated phone.

Some apps require you do something on the old phone to migrate, like de-register it. Those apps need to treat that requirement as a serious thing requiring explicit user action. Notify me during the migration if I need to do something on the old phone. “Hey, you need to do something special for this product”. As it stands now for some apps (Volvo, WhatsApp, Battle.net, ...) you only notice you have to do something on your old phone when you get around to launching it on the new phone. That may be several days later, after you’ve already wiped and sold your own phone. That’s not acceptable. (I literally spent a couple of hours launching every single app to make sure it worked. Don’t make me do that. I’m still scared to wipe and sell the old phone.)

Google needs to work with cell providers to migrate cell service better. This used to be great on iOS, not sure if it still is. All Android says is “lol contact your cell provider”. Maybe the Google Fi version is nicer?

Google should respect my ad privacy settings on migration. As it stands now Android uses a migration as an opportunity to trick you in to agreeing to being tracked.

I’m on the fence whether Android should copy over app permissions. It doesn’t seem to, at least for location, file access, and biometrics. OTOH a migration is a chance to fight the proliferation of promiscuous permissions. That e-commerce app really doesn’t need my precise location.

Commentary

A lot of people responded “it’s an inconvenient experience because of security”. Sure, security-vs-usability tradeoffs are often tricky. But make the tradeoff explicitly, on purpose! Not just this lazy mess. And for security, wouldn’t it be better if the product recognized that it’s not a new install, but rather a secure transfer from an old install? A migration is a different, lower risk. Most of the apps I used don’t do anything that nice, they just reset me back to zero. I suspect they do this because it’s easy and they trust that process is relatively secure rather than building a special migration experience. They didn’t put any product effort into the tradeoff during migration, they just made it inconvenient.

Many of my requirements are predicated on the assumption that the migration itself is a secure process. That no hacker can produce an unauthorized clone of my phone and use that to access my bank account. I am pretty sure Google designs for secure migration and trusts it. But I can understand why my bank might not trust Android. So fine, require I log in again if the stakes are high. But at least design that process nicely. The bare minimum is not making me type my username again.

Secure hardware enclaves complicate migration: it may not be possible to move some data. I don’t know Android well enough to know how prevalent that is. I don’t think it explains most of the problems I saw.

Both 1Password and Aegis did a good job on migration. These are some of the most sensitive apps I own; both migrated my data in a way that I trust is secure. They did require me to reauthenticate but that process was simple. Both already had my data and knew who I was. This proves that secure convenient migration is possible on Android. My guess is their product teams put a lot of effort into making migration work well, it’s a primary feature for both.

Several simpler apps also migrated well. (Yay Paprika!) And Google’s apps also mostly did a good job on migration. Not exactly a surprise, they control the whole platform. Also they have a very clear authentication and account model, most of their apps just trust the system’s Google login. I logged in once to Google during the setup process and then my Gmail, etc was already available. Wallet and GPay were exceptions, both had problems.

Special shout-out to the Wikipedia app which kept all my tabs during the transition. That was a nice surprise!

Migrating to a new Android phone sucks

I upgraded my Pixel 6 Pro to a Pixel 8. I just spent some five hours getting the new phone working the way the old one did. It was a terrible experience. Getting a new phone isn’t a delight, it’s an awful chore to be avoided. Every product manager and engineer involved in this mess should feel bad. FWIW it was bad two years ago when I did this last time, too. My impression is the iOS migration experience is much better. (Update: mixed opinions about iOS on the Fediverse.)

Update: see this followup.

(Content warning: this note is a bit ranty. I felt it was important to capture the emotional experience.)

Broadly speaking, the problems fall into several categories:

  1. Data not copied over to the new phone
  2. Random app settings not being configured
  3. Having to log in to every app
  4. Security critical stuff
  5. Getting the cellular contract to work
  6. Google being sleazy with surveillance

I think the underlying problem is the Android platform must not specify how migration is supposed to work well enough that every app gets it right. No one owns the whole migration product: it’s partly Google/Android’s responsibility, partly the phone manufacturer’s (Google in my case), partly the carrier, and partly the apps’.

Also I can imagine each app / product owner not thinking it’s a big deal. “Migration only happens every two years, no need to worry about it”. I bet these products lose 5–10% of their customers every two years. Also the problem is much worse for the individual because they have to manage 100+ app migrations all on the same day.

It’s not like it’s not possible for migrating to a new phone to work. Some things even do work in Android. The little mom & pop Paprika app migrated perfectly. All my recipes on the new phone, still logged in. So did Libby, the public library book borrowing platform. But many other well funded apps sucked. High stakes things like my banks or Uber, but also low stakes things like my Spotify account. My suspicion is the product people for most of these apps just don’t care enough to make it work.

Details

Do I have detailed notes? You bet I do!

Data not copied over to the new phone

Android has a fancy migration tool for new phones. It’s pretty slick! Wireless, auto-discovery, relatively quick considering what it’s doing. And it does successfully copy a lot of data over. But not everything. For instance all of my music files copied over. But the 3GB of map databases Organic Maps had? Have to download those again. Also the 80GB of Wikipedia database from Kiwix. I suspect there’s a deliberate decision here not to copy this data since it can be downloaded again. It may be tied to the set of data that’s backed up. But re-downloading 80GB over the Internet is a big burden and the data is right there for the copying.

Google Wallet kept my credit card, the most sensitive item it had. But it lost my Clipper transit card. Also lost my Covid vaccination record (again). Maybe no one on the Google Wallet team cares enough to make sure the user’s cards in their wallet transfer over. Just empty the wallet into a fire and start over.

Random app settings not being configured

A whole lot of apps had to be reconfigured. A few apps copied their configs over entirely, worked great. Most didn’t even try, I started new. A few special apps copied some settings but not all. A whole lot of apps treated me to a New User experience, some condescending 8 page onboarding slideshow like I’d never used the product before. (Including, bafflingly, a few that had copied my configs.)

A related detail: all my system settings for app permissions had to be re-enabled. I had to manually tell the phone, again, to allow the maps app to know my location and the file manager app to access my files. I think my notifications preferences were kept though.

The notes from the Niagara Launcher app are possibly instructive here. “We’re currently using Google’s Backup implementation, which is not 100% reliable...” In my case I had to fully reconfigure Niagara. There’s a feature request for Niagara to implement its own settings export / migration tool. Some of the apps I use have those but I didn’t use any of them because the process of juggling the settings file was too tricky. It should just sync to the Google Cloud Backup Drive Panopticon, why does this not work for every app consistently?

Having to log in to every app

A huge PITA is that most apps are basically just wrappers around a website. And almost all of them demanded I log in again. I suppose they think this is “for security reasons” but for 90% of the apps there’s very little risk. It doesn’t help that the login process is a PITA. I use 1Password for logins and for about half the apps it works very well, I just tap a button in the keyboard and it fills. The other half? I have to cut and paste across two apps. Or the new trend, the app doesn’t even let you use a password but insists on sending an SMS message with a login code. Which cuts 1Password out of the loop entirely.

Security critical stuff

A few apps have special security needs, I expected them to be awkward to migrate. Except: they aren’t! Both 1Password and Aegis (my 2FA store) worked great. I think I had to type a password into each one once on the new phone. All data, login tokens, etc transferred. Because they care to get it right.

By contrast the various bank apps and other things with material consequences to security all sucked. In all cases it was basically like I was installing a new app for the first time on a new device, no aspect of the transfer worked at all. Only because these are security conscious products the new app setup process is always onerous.

And then there are the special apps that insist I do something on my old phone to deregister it before it will let the new phone work. The geniuses at Volvo managed to build a car where if you lose your phone or uninstall the app you have to factory reset the entire car software in order to connect a different phone to it. Fortunately I have the old phone and could unpair it but I still haven’t paired the new phone because I have to have both physical car keys with me to pair a new phone. The Android migration tool did nothing to help me here.

I was going to check what happened to my Passkeys but hahaha I have no Passkeys because that technology rollout is going very poorly.

Getting the cellular contract to work

Another special case I have a little sympathy for: migrating cell service is tricky. And very security important, given how every app treats SMS to your phone number as a primary means of identification. I give Verizon credit here, the transfer process was actually pretty good. eSIMs should make this simpler but in practice make it more complicated since there’s no physical object to move your identity on. But it still worked mostly fine, although Verizon’s website and docs are wildly inconsistent on what you need to do to migrate. (The obvious thing worked for me without talking to anyone.)

But Android did nothing at all to help make my phone be a phone. Why not recognize I’m moving a phone with a Verizon contract and help migrate the eSIM service over at the same time?

Google being sleazy with surveillance

A special bonus here. Somehow Google forgot my ad privacy preferences. Google rolled out a whole new ad privacy setting this fall. I immediately opted out of all surveillance on my phone and my Google Account. But despite migrating a Google Account opted out on a phone opted out, the new phone demanded I set my ad preferences up again. Defaulted to full tracking. Twice: once for Chrome and once for the phone device itself.

Of course Google knows exactly what they’re doing, it’s not a bug. They want desperately to track users but they need to maintain the fig leaf that we somehow consented to the tracking. So the phone transfer doesn’t transfer the privacy settings and resets me to full tracking. But this game they’re playing undermines their goal. They clearly ignored my informed preferences and tried to trick me into undoing them. That’s not informed consent, that’s fraud. I know to pay close attention for this garbage but most users won’t follow it.

Conclusion

Phew, feel better getting that rant out. But seriously, the experience of migrating one Android phone to another is really bad. It’s a mess of a difficult problem, complicated tech that apparently doesn’t work right, and a product conundrum that no one cares enough about to fix.

xxhash notes

Following up on a post 7 years ago, there now seems to be a consensus for a hash / checksum algorithm that’s not cryptographic. xxhash. Some variants are literally faster than memcpy, which is quite a trick. (I assume it’s the SIMD instructions).

xxhash has a bunch of implementations, I’m using the Ubuntu version. It comes in four flavors: 32, 64, 128 bit, and an alternative 64 bit (H3) that’s the fastest. Oddly the 128 version is the fastest of the first three, then the 64 bit.

This reimplementation blog post has some details on the algorithm. The speed comes from a parallel design meant for SIMD calculation. The actual checksumming boils down to rotate(state + (data * prime2)) * prime1. I’m a little surprised it’s a multiply and not a shift and xor or something but I know nothing about modern CPU speed.

I did a very simplistic benchmark: time dd if=/dev/zero bs=1024k count=1024 | xxhsum -H3 and took the best time of several runs.

  • no hash (send to /dev/null): 30ms
  • H0: 245ms
  • H1: 222ms
  • H2: 224ms
  • H3: 224ms
  • md5sum: 1250ms

Safe to say xxhash in any of its forms is so fast that I/O speeds and overhead dominate the CPU for the calculation. No wonder people embed this thing in filesystems, etc. It has very little cost.

My own archive of tweets

I put my own Twitter archive online, hosted here with individual tweet URLs like here. The “server” is all static HTML but the list of tweets is an infinite scroll thing. Oct 2006 to Nov 2022.

I made this with Julia Evans setup, itself based on Darius Kazemi’s tool. Darius’ program generates its own HTML view but it’s got an idiosyncratic presentation. Julia’s code takes the tweet data (from searchDocuments.js) and the media files and constructs a new HTML archive borrowed broadly from Nitter’s UI. The Vue-based infinite scrolling wouldn’t be my first choice for an archive but it works fine and only took a half hour to set up. The main thing I miss is thread nesting.

I mostly just followed Julia’s instructions, getting something basically working is very easy. The scripts aren’t a polished product but if you are comfortable hacking a little code it’s not hard to get working. I’m glad she shared them! Some details:

Here are the specific edits to the code to customize my archive:

  • app.js: Replace two instances of b0rk with nelson
  • index.html: Replace four instances of “julia” or her full name with mine. Replace two instances of “b0rk” with “nelson”.
  • build.py: 5 instances of “b0rk” for “nelson”. 4 instances of “julia” for “Nelson”. (this page includes HTML similar to index.html).
  • profile.jpg: replaced with my own image

Deployed by rsyncing the entire github package, Julia’s scripts write stuff in that directory. Then on the web server I deleted things that weren’t necessary for the static HTML: .git, scripts,

The other thing I did was write a script to filter my tweets by date. I decided to cut off the archive at Nov 3 2022, the stuff I posted afterwards is all not something I care to preserve, just bearing witness to Elon Musk’s destruction of the company and product.

#!/usr/bin/python

import json, pytz
from datetime import datetime

cutoff_dt = datetime(2022, 11, 4, tzinfo=pytz.UTC)

def cutoff(item):
	created_at = item["created_at"]
	dt = datetime.strptime(created_at, "%a %b %d %H:%M:%S %z %Y")
	# print(dt, dt >= cutoff_dt, cutoff_dt)
	if dt >= cutoff_dt:
		return True
	else:
		return False

jsonp_header = 'const searchDocuments = '
data = open("searchDocuments.orig").read()
data = data[len(jsonp_header):]

tweets = json.loads(data)

filtered = tuple(t for t in tweets if not cutoff(t))

print(f'{len(tweets)} tweets in archive, {len(filtered)} passed filter')
with open('searchDocuments.js', 'w') as fp:
	fp.write(jsonp_header)
	json.dump(filtered, fp, separators=(',', ':'))

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.

LXC by hand

Some rough notes on setting up LXC on a generic Ubuntu system with the command line tools. No Proxmox. I mostly followed this guide and made it difficult for myself by setting up an unprivileged container. This is easier if you’re root.

  1. sudo apt install lxc
  2. Follow the instructions in “Basic unprivileged usage” that have you creating a ~/.config/lxc/default.conf and as root adding permissions for networking to /etc/lxc/lxc-usernet.
  3. Run lxc-update-config -c ~/.config/lxc/default.conf
    This is not mentioned in the Ubuntu docs but seems necessary, I found it in a comment here.
  4. Create a container: lxc-create -t download -n u1 -h
  5. Configure it interactively (I couldn’t figure out command line switches). The list of containers is here. I chose alpine, 3.18, arm64.
  6. Start it: lxc-start -n u1
  7. Connect to it: lxc-attach -n u1

On the container:

  1. Verify networking works: ping 8.8.8.8 (note that “ping” can be fraught but it worked for me.) ip a shows me a 10.* address, not my usual LAN subnet. I guess some routing is involved?
  2. Verify you have process isolation: ps -axu. It’s a list of a few root processes just for the Alpine container, nothing for the host.

On the host:

  1. Verify user ID mapping: ps -axu | grep /sbin/init. I have some processes with a new user 100000.
  2. Learn some things about the container:
    lxc-info -n u1
  3. Check the container’s files in $HOME/local/share/lxc

I’m having a hard time getting any system stats about the containers. lxc-top reports nonsense, free inside the container shows the host system stats (yes, lxcfs is installed in the host), lxc-info does not show memory usage despite all the docs saying it should.

One thing I notice is all the help pages I find online in my searches are ~2014 era. I suspect most people have moved on from LXC to LXD or Docker or whatever. I’m only tinkering with LXC because that’s what Proxmox uses. But then they’ve built their own pct tool for managing things.

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.

BOSGAME B100 thoughts

I bought a cheap new mini-PC for Linux, a BOSGAME B100. I don’t have a lot to say about it except it has made a very good impression, particularly for the price.

Update August 2024: the cheap SSD in this thing failed after 9 months. Gave errors on reads sometimes. I still like this product category and it’s easy enough to replace the SSD, but ugh.

There’s a bunch of these generic inexpensive mini PCs on the market now based on Intel N100 CPUs (or before, N95). Beelink is a popular brand; I picked the BOSGAME because it would ship same day. I bought it from Amazon for $160 (with a coupon).

It’s wild how cheap these are for the capability. The CPU has 4 cores that can run up to 3.4GHz. 16 GB of RAM, 512 GB SSD that reads an honest 500 MByte/sec, a 2.5GB ethernet controller from Intel, 10 Gbps USB 3.2 ports. Supposedly 802.11ac and Bluetooth but I haven’t checked if they work in Linux. None of these parts are top of the line. For instance, the RAM is DDR4-3200 but it’s a single module (not a dual channel pair) and it’s CL 22. You can get SSDs that are 50% faster. But still, it’s pretty capable hardware. And that price!

It’s actively cooled with fans. I can’t hear the fan when it’s idle, I can hear it but it’s not very loud running at full load. One drawback of its design is it has the exhaust fan in the top, which means you can’t put anything on top of it. You could stack the Intel NUCs. (For an alternative see these fanless designs on sale here. But that’s got a big ol’ heat sink on top, still can’t stack it.)

Stress-ng gets it to 61C, the CPUs stays at 10.6W and 2900MHz. Plex actually works it harder when it scanned my video library for the first time. I saw the CPU peak around 76C, 14W, and 3300Mhz or more on all 4 cores. It’s using the GPU too, at least sometimes. The fan is a little noisy but the system is stable. Can’t find fan speed with lm-sensors.

The server seems to draw about 7W when running but mostly idle; the CPU package is using 2W of that. stress-ng on all CPUs gets the system to 19W, CPU package at 11W. Mind you that includes a spinning laptop drive which is 3W all in itself. It’s just remarkable how low power it is.

Signal Foundation financials

I keep seeing chatter about the Signal Foundation and their financials, so I dug deeper into their IRS 990 filings. No big story here, just my notes on what I learned. I love the secure messaging product and the non-profit mission. But their financial status sure seems headed for trouble. I am not an expert on non-profit financials, it’s possible I missed something and if so I’ll try to update this post.

Update: somehow I missed this post two weeks ago from Signal discussing their finances and asking for donations from individuals. More or less agrees with what I describe below. I’m looking at older financial reports, new donations won’t have shown up in the data I looked at yet.

Bottom line: the company is spending $20M–$30M a year. They’re making maybe $2M a year in real revenue. The only meaningful inflow was in 2018, the $105M loan (now mostly gift) from Brian Acton. They aren’t getting significant income from the product nor major contributions from other donors. They’re down to $37M in assets in 2022. Without some major change or new donation it looks like they’ll be out of money in a year or two. I think Wikipedia’s summary is mostly accurate:

On February 21, 2018, Moxie Marlinspike and WhatsApp co-founder Brian Acton announced the formation of the Signal Foundation, a 501(c)(3) nonprofit organization.[4][8] The foundation was started with an initial $50 million loan from Acton, who had left WhatsApp’s parent company, Facebook, in September 2017.[8] ... By the end of 2018, the loan had increased to $105,000,400, which is due to be repaid on February 28, 2068. The loan is unsecured and at 0% interest.

If you look at ProPublica’s summary of the 990 filings there’s some graphs of financial trends but they give a slightly misleading picture.

That revenue graph is dominated by details of the $105M loan in 2018. Most of the revenue in the graph above is Acton forgiving that loan, knocking $10M–$30M off a year. (The loan is down to $32M in 2022). If you look at Part VIII of the 2022 990, for instance, $23.5M of $26M is contributions. There’s no list of contributors but eyeballing the numbers, the big contributions every year match the debt forgiveness. It looks like their primary contributor is Acton writing off the loan.

Other than the gift, the most meaningful revenue Signal books is about $2M in 2021 and 2022 for royalties. There’s also ~$400K a year from investment income. Overall Signal seems to be taking in a couple of million a year from the product. And not receiving any major contributions other than Acton’s 2018 gift.

Meanwhile Signal’s expenses were $30.5M in 2022. Part IX of the 990s has the details. Roughly $12.5M is paying employees and executives, another $12.5M is computer hosting costs (Twilio, Microsoft, Amazon, Google). The 2021 picture is similar.

So that’s the picture; spending $30M a year, taking in $2M, and living off the $105M gift in 2018. That’s going to run out soon.

Nothing in this picture is weird or nefarious, it makes perfect sense for a non-profit. Signal is running a valuable service for people to use for free. But they aren’t getting major donations, relying entirely on that gift from their CEO in 2018. That’s cool too, I love seeing rich people use their money and time to build something of benefit to the world! But either he’s going to have to stump up again or something’s got to change.

(BTW, the Signal Foundation is the non-profit I’m looking at here. They own an ordinary company subsidiary, Signal Messenger LLC. That LLC seems mostly small and passive, not raising investment of its own. I don’t think this is like OpenAI and Microsoft.)

Amateur security hour at Carta

Just got this email from Carta. Or a financial phishing attempt. Or both?

At least they provided a copy and paste URL you can verify, although it going to a resource named “redirect” is not inspiring. The real treat here though is the big black button is not a link to carta at all; it’s a link to mandrillapp.com, some Mailchimp surveillance thing.

Linux and bad memory

This post has more than the usual flailing around. Don’t follow this advice.

My Intel NUC server is failing, twice now it’s corrupted database files with single bit errors. I confirmed with memtest86+ that the problem is bad RAM. I’ve got new hardware on order but meanwhile I want to make things work again.

First I used memtest86+ in summary mode (pressing F1 and F4) to get the above display. It’s telling me that RAM is bad between 868MB and 996MB, also with the hex addresses. Probably not all 130+ MB there is bad but who knows. (In detail I can see that the 5th bit is bad, mostly in a single 4k page. Happily this coincides exactly with the data corruption I was seeing in my database files.)

Then I convinced Linux not to use this RAM by adding the memmap=140M!860M to the Linux command line (by editing /etc/default/grub.) That avoids the whole region memtest86+ identified as bad. This Stack Exchange discussion was very helpful in figuring it out, and this web page has a great detailed explanation of how memmap works. The real purpose of this option is to tell Linux not to touch the memory because some other fancy performance system is using those addresses specially. I rebooted and confirmed the reservation was happening thanks to this line in dmesg:

[ 0.000000] reserve setup_data: [mem 0x0000000035c00000-0x000000003e7fffff] persistent (type 12)

Some fuckups I encountered along the way:

  • Linux has a CONFIG_MEMTEST where it can run a simple RAM check and automatically avoid RAM that tests bad. Apparently memtest=17 is a good setting, according to the cargo cult. I never got the system to boot with this; it’d just go to a blank screen and nothing would happen. I waited 20+ minutes, longer than the 4 minutes one guy who had 128GB of RAM said it took. Perhaps the system overheated and froze up.
  • The old way to do deal with flaky memory was using the BADRAM setting with a confusing mask. This apparently was never in a standard Linux kernel but the patch is in Ubuntu’s kernel. But it doesn’t work in UEFI Secure Boot so forget it.
  • A bug in ubuntu installer from 2016 left /etc/default/grub.d/50-curtin-settings.cfg lying around with a variable that clobbers my setting in /etc/default/grub with the empty string. Here it is eight years later and I just now got hit by the legacy of this bug. (They sorta fixed it, but didn’t do anything to repair systems that had the bug). So I was making changes to the GRUB config, always a scary and confusing thing, and they weren’t taking.
  • Sometimes on booting my poor machine would display “alloc magic is broken at 0x.....” early in the GRUB boot process, I think loading the init ramdisk. Searching Google for this error gives even less than the usual semi-useless info. But one common explanation is.. bad RAM! I noticed the address in the error was close to where my error is, so I think flaky RAM caused it. No idea why it works sometimes and not others, but it seems to work better after I let the system cool down a bit.

Truthfully, every time I’ve tried to use software to cope with flaky hardware it’s ended badly like this. Better just to throw money at the problem and get new hardware. I have an embarassingly cheap N100 system on order, hoping it’s not total garbage.