Some Bits: Nelson's log

24 posts in July 2024

Some NAS hardware estimates

I’m trying to get an idea of what building a 10TB NAS would cost if you’re on a budget. Options range from plugging in a single USB drive into an existing N100 miniPC running TrueNAS up to a dedicated Synology device.

I’m not an expert on this stuff: comments welcome!

I’m targeting a working set of roughly 10 TB of data. I’m thinking spinning hard drives (HDDs) make more sense. I like SSDs but the speed is mostly irrelevant in a NAS on gigabit ethernet. Maybe SSDs are more durable, but they are 2-3x more expensive. For RAID options I’m considering setups where one disk can fail and we still can operate.

Summary

We can get 10TB usable storage for anywhere from $200 to $1500 depending on how we do it.

Disks: 10TB usable can be done for $210 with a single disk (no recovery). Or RAID recovery with either 4x4TB or 2x10TB. Both RAID options are about $400 for spinning disks. $1300 to go with SSDs.

USB enclosure: about $200 for a four bay enclosure. Not needed if we just do one or two drives on the N100.

Separate PC appliance instead of the N100: about $250-$600, lets us avoid USB, also maybe a simpler commercial solution.

Update: I ordered two 8TB WD Red Plus drives and a Yottamaster PS200U3 two disk enclosure. Basically the cheapest plausible mirrored setup. Total price $400 plus tax (plus the computer to plug them in to). The 10TB WD Red Plus disks are sort of weird. 12TB are OK but noisier and higher power, so starting smaller. Early indications are the Yottamaster is not reliable, having a lot of trouble with USB errors in TrueNAS Scale.

N100 with TrueNAS and spinning disks

Variants of what I’ve set up already, a homebrew inexpensive system. The experts will tell you USB is not suitable for real NAS systems. But I think it could be OK.

10TB Cheapest: a single 10TB 3.5″ HDD on USB to the N100. 10TB is $210.

10TB RAID1 (mirror): two 10TB HDDs on the N100. $420.

10TB RAIDZ1: four 4TB HDDs ($400) in a USB enclosure ($200) connected to N100. $600

N100 with TrueNAS and SSDs

An SSD option. The disks are 3x the cost of HDDs.

10TB RAIDZ1: four 4TB SATA 2.5″ SSDs ($1300) in a USB enclosure ($200) connected to N100. $1500

Synology appliance (no N100)

A third party commercial alternative to building our own NAS on the N100. Not as capable as TrueNAS but easier to understand and support. No USB involved.

10TB RAID1: two 10TB drives ($420) in a DS223 ($250). $670

10TB RAID5: four 4TB drives ($440) in a DS423 ($400). $840

Build our own appliance

To avoid USB we build a little mini-PC with SATA disks in it. This is a rough guess only.

10TB RAID5. four 4TB drives ($400) and a cheap custom mini PC ($500?) $900ish

Extra costs: Local versioned backup drive

I think this is easy, just a local disk to copy stuff to.

16TB: 3.5″ external HDD on USB to the N100. $280

Extra costs: electricity

50 watts works out to 438kWh a year or about $200/year.

SanDisk Extreme Pro: data loss, smartctl

SMART

I have a recently purchased 4TB SanDisk Extreme Pro 55AF, an SSD. (Note SanDisk is a Western Digital brand.) smartctl doesn’t recognize it. I found a workaround for it which is to pass -d sntasmedia to smartctl. Doing that gives plausible output but some stuff looks a bit off (like power on hours). See full SMART output below.

Getting OpenMediaVault to pass this flag is not possible or at least not easy. There’s a remarkably detailed response here which says they want smartmontools to update its database instead. There’s also a suggested workaround which is to add an entry to /etc/smart_drivedb.h but the format for that seems daunting, I didn’t pursue it (yet).

Bad drive?

Unfortunately while researching this SMART problem I learned SanDisk Extreme Pro has been implicated in some serious data loss problems. See here, here, or here for reports. SanDisk has said it’s a firmware issue and put out an update, their tool here says we don’t need an update for this drive (if I have the right serial number). OTOH Tom’s Hardware is saying it’s a hardware flaw. That’s very troubling and knowing all this now I’ll think twice before buying any SanDisk or WD external USBs. Not sure what to do with this disk.

I have seen one problem with this drive, btw. When using hdparm -t to test throughput it reads for 3 seconds. It tests fine, like 800 MB/s. But if I test a second time it tests super badly, like 60 kilobytes/sec, and there’s an error in dmesg saying it had to reset the drive interface. Then the drive seems to work fine again (until I test throughput again.)

Jul 23 17:50:32 nchsomv (udev-worker)[7715]: sdb: Spawned process 'serial_id /dev/sdb' [7754] is taking longer than 59s to complete
Jul 23 17:50:32 nchsomv systemd-udevd[295]: sdb: Worker [7715] processing SEQNUM=2565 is taking a long time
Jul 23 17:50:32 nchsomv kernel: sd 3:0:0:0: [sdb] tag#11 uas_eh_abort_handler 0 uas-tag 2 inflight: IN
Jul 23 17:50:32 nchsomv kernel: sd 3:0:0:0: [sdb] tag#11 CDB: ATA command pass through(16) 85 08 0e 00 00 00 01 00 00 00 00 00 00 00 ec 00
Jul 23 17:50:33 nchsomv kernel: scsi host3: uas_eh_device_reset_handler start
Jul 23 17:50:33 nchsomv kernel: usb 2-1: reset high-speed USB device number 2 using xhci_hcd
Jul 23 17:50:33 nchsomv kernel: scsi host3: uas_eh_device_reset_handler success
Jul 23 17:50:33 nchsomv kernel: program smartctl is using a deprecated SCSI ioctl, please convert it to SG_IO

I’ve only seen this error with a synthetic test, and that via a KVM pass-through USB device. So I just kind of shrugged it off. FWIW we’ve successfully written 1.7TB of data to the disk and read 3.2TB off of it, so it’s not failing all the time. Sure don’t care for this uncertainty though.

Update: I’ve also seen this error now just reading files from the mounted disk (tar cf - . | pv > /dev/null). It’s possible this was related to the disk waking up from a sleep mode. The earlier hdparm failures were very unlikely to be sleep related. Then I was able to read 2.5TB or more off the disk, both streaming (at 400MB a second) and two parallel random access threads. Without a single error.

SMART output

# smartctl -a -d sntasmedia /dev/sdb
smartctl 7.3 2022-02-28 r5338 [x86_64-linux-6.1.0-23-amd64] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Number:                       WD_BLACK SN850XE 4000GB
Serial Number:                      240632803712
Firmware Version:                   624131EX
PCI Vendor/Subsystem ID:            0x15b7
IEEE OUI Identifier:                0x001b44
Total NVM Capacity:                 4,000,787,030,016 [4.00 TB]
Unallocated NVM Capacity:           0
Controller ID:                      8224
NVMe Version:                       1.4
Number of Namespaces:               1
Namespace 1 Size/Capacity:          4,000,787,030,016 [4.00 TB]
Namespace 1 Formatted LBA Size:     512
Namespace 1 IEEE EUI-64:            001b44 8b47193cd2
Local Time is:                      Mon Jul 29 21:55:46 2024 UTC
Firmware Updates (0x14):            2 Slots, no Reset required
Optional Admin Commands (0x0017):   Security Format Frmw_DL Self_Test
Optional NVM Commands (0x00df):     Comp Wr_Unc DS_Mngmt Wr_Zero Sav/Sel_Feat Timestmp Verify
Log Page Attributes (0x1e):         Cmd_Eff_Lg Ext_Get_Lg Telmtry_Lg Pers_Ev_Lg
Maximum Data Transfer Size:         128 Pages
Warning  Comp. Temp. Threshold:     91 Celsius
Critical Comp. Temp. Threshold:     94 Celsius
Namespace 1 Features (0x02):        NA_Fields

Supported Power States
St Op     Max   Active     Idle   RL RT WL WT  Ent_Lat  Ex_Lat
 0 +     9.00W    9.00W       -    0  0  0  0        0       0
 1 +     6.00W    6.00W       -    0  0  0  0        0       0
 2 +     4.50W    4.50W       -    0  0  0  0        0       0
 3 -   0.0250W       -        -    3  3  3  3     3100   11900
 4 -   0.0050W       -        -    4  4  4  4     3900   45700

Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
 0 +     512       0         2
 1 -    4096       0         1

=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

SMART/Health Information (NVMe Log 0x02)
Critical Warning:                   0x00
Temperature:                        34 Celsius
Available Spare:                    100%
Available Spare Threshold:          10%
Percentage Used:                    0%
Data Units Read:                    6,286,318 [3.21 TB]
Data Units Written:                 3,285,119 [1.68 TB]
Host Read Commands:                 62,684,905
Host Write Commands:                33,660,622
Controller Busy Time:               94
Power Cycles:                       803
Power On Hours:                     33
Unsafe Shutdowns:                   8
Media and Data Integrity Errors:    0
Error Information Log Entries:      0
Warning  Comp. Temperature Time:    0
Critical Comp. Temperature Time:    0

Warning: NVMe Get Log truncated to 0x200 bytes, 0x200 bytes zero filled
Error Information (NVMe Log 0x01, 16 of 256 entries)
No Errors Logged

Android notifications are still terrible

I’m still missing Android notifications, Gmail this time. I asked the Claude AI for help. Check out this list of 20 options. Perhaps Android’s product has gotten too complicated? The list isn’t entirely correct and it misses a few (some are hidden in the Gmail app itself, for instance) but it gives a gist.

What are all the settings on Android Gmail that might mean I don’t see a notification for a new email? I want all of them, a comprehensive list.

Here’s a comprehensive list of Android Gmail settings that might prevent you from seeing notifications for new emails. Sorry for bad formatting.

  1. Notifications disabled in Gmail app:
  • Settings > [Your account] > Notifications > Notify for new messages
  1. Notification categories turned off:
  • Settings > [Your account] > Notifications > Manage notifications
  1. Sync turned off for your account:
  • Settings > [Your account] > Sync Gmail
  1. Battery optimization interfering:
  • Device Settings > Apps > Gmail > Battery > Battery optimization
  1. Do Not Disturb mode active:
  • Device Settings > Sound > Do Not Disturb
  1. App-specific notification settings in Android:
  • Device Settings > Apps > Gmail > Notifications
  1. Notification importance set to low:
  • Device Settings > Apps > Gmail > Notifications > Importance
  1. Notification channels disabled:
  • Device Settings > Apps > Gmail > Notifications > [Specific channels]
  1. Gmail app data restrictions:
  • Device Settings > Apps > Gmail > Mobile data & Wi-Fi > Background data
  1. Gmail app battery restrictions:
    • Device Settings > Apps > Gmail > Battery > Restricted
  2. Inbox categories filtering:
    • Gmail app > Menu > Settings > [Your account] > Inbox categories
  3. Priority Inbox settings:
    • Gmail app > Menu > Settings > [Your account] > Inbox type > Priority Inbox
  4. Filters or labels automatically archiving emails:
    • Check filters in desktop Gmail settings
  5. Outdated Gmail app version:
    • Google Play Store > My apps & games > Gmail > Update
  6. Android system notification settings:
    • Device Settings > Notifications > App settings > Gmail
  7. Power-saving mode active:
    • Device Settings > Battery > Power saving mode
  8. Account sync issues:
    • Device Settings > Accounts > Google > [Your account] > Sync account
  9. Airplane mode enabled:
    • Quick settings or Device Settings > Connections > Airplane mode
  10. Poor internet connection:
    • Check Wi-Fi or mobile data connectivity
  11. Gmail storage full:
    • Check available storage in Gmail account

This list covers most settings that could affect Gmail notifications on Android. The exact names and locations of these settings may vary slightly depending on your Android version and device manufacturer.

Would you like me to elaborate on any specific setting or provide more information?

Windows screenshot tools in 2024

It’s 2024 and Windows is still bad at taking screenshots. Actually the built-in Snipping Tool is sort of OK but third party solutions are better. Also my Apple keyboard doesn’t have a Print Screen button so all the defaults are awkward for me.

For years I’ve used Lightshot but the last release was 2009. Then I used ShareX but never liked it’s complicated UI.

Greenshot is my new bae. It’s open source and has a good UI with some attention to usability and simplicity. There’s a simple built-in editor. I could suggest some minor UI improvements but basically it’s fine. The one feature it’s missing is WebP support but I can easily convert manually with File Converter.

Relationship with Greenshot ended. Turns out it has a serious vulnerability over a year old that is actively being exploited. The release hasn’t been updated in 7 years. The developer keeps making noises about wanting to put out a new release but having trouble with signing keys, etc. IMHO it’s irresponsible for them to keep offering the software if they can’t fix it. I regret recommending it.

Flameshot is also nice with a capture UI that looks like the old Lightshot UI. But there is no way to change the hotkey from PrintScreen and the three year bug report discussion left a bad taste in my mouth. In general Flameshot seems to not have quite the usability polish of Greenshot, and since I can’t even launch it with my keyboard I won’t use it.

Flameshot’s last release was 2022. There’s been a lot of submitted improvements since then but no release on Windows.

Debian 12 slow login in Proxmox

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

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

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

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

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

Sometimes this computer stuff sucks.

Towards a Proxmox NAS

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

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

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

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

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

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

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

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

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

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

I wonder if this would be a good NixOS project?

TrueNAS Scale first impressions

After having mixed reactions to OpenMediaVault I thought I’d give TrueNAS Scale a try as a small Network Attached Storage system to run under Proxmox. This is a first time user and a very small test, nothing serious, but I learned something. I set up a single user accessing a single SSD via SMB and NFS.

TrueNAS is a bit confusing as a product. It’s a commercialized evolution of FreeNAS by iX Systems. It is still free and open source. TrueNAS Core was the original product and runs on FreeBSD. It’s being deprecated in favor of TrueNAS Scale running on Linux. So I’m only looking at Scale. Scale used to use Kubernetes to manage services but is migrating towards Docker instead. That’s created some drama with TrueCharts, a third party company that published a lot of popular TrueNAS Scale applications for installation. That’s over now but presumably the Docker ecosystem will substitute.

Compared to OMV, TrueNAS makes a very good first impression as a serious, professional product. It also feels like overkill for a home setup but maybe that’s OK. The docs are quite good, succinct and thorough. I’m having a bit of trouble because the TrueNAS Core docs seem more complete but are just a little out of sync with how Scale works. Scale has its own docs but they seem a little less organized. Still the docs are great. And community support is good, lots of nice answers on Reddit and TrueNAS’ own forum.

The initial setup experience seems faster than it was in OMV, despite TrueNAS having more complex features. Maybe that’s just because I’ve learned more about NAS setups in general, or maybe it’s because TrueNAS is nicely designed.

Fancy features

There’s some interesting advanced features for share types. Like early on you can designate a filesystem as case-insensitive if you’re only using it for SMB. There’s presets for multiprotocol SMB/NFS shares, for write-once-read-many SMB setups, etc. I don’t know if I need (or trust) these but it could be quite useful if they work well.

TrueNAS has elaborate support for creating virtual machines with KVM. It also has containers, and Docker, and Core made good use of BSD jails. I don’t need any of that stuff, that’s what Proxmox is for.

TrueNAS gives you access to ZFS snapshots. And it has cloud backup support. The latter looks more like a “replicate to cloud” feature but in combination with snapshots that could get you versioning. I didn’t explore this but it looks promising.

TrueNAS also has an app store and a bunch of installable apps. Some seem useful to have tightly bound in your NAS: SyncThing or Nextcloud are great. Others I’d rather run in separate Proxmox guests, like Plex or a Minecraft server. Also with the TrueCharts drama the world of community contributed apps is a bit in flux, but I bet that’ll work out. Moving to Docker is a good choice.

Complexity vs. low-spec systems

TrueNAS really wants to be a system for enterprise bullet proof storage. It’s very good at that, if you want to spend $2000+ on a storage array I’m sure it’s your software. But I’m sitting here with a $200 mini PC and a $100 USB drive. Is TrueNAS for me? Sorta, it will work, but it will nag you.

TrueNAS is all-in on ZFS. And it really, really doesn’t want you to lose your data. It really wants at least 2 storage disks and would be very happy to use 8 or more. It is possible to set up TrueNAS using a single disk (technically “striped mode”, but with just 1 disk). But the software complains and warns you at every opportunity that what you’re doing is not safe. Which, fair enough, but for my little home use case really it’s what I want.

On the flip side if you want to have 2 disks and mirror them or have 8 disks and some fancy RAIDz2 setup with a separate log device, TrueNAS totally is the product for you. Which, honestly, is probably a good idea for a real storage array.

There’s a similar nag if you try to use TrueNAS to share a USB drive. It complains “‘SSD’ is consuming USB devices ‘sdb’ which is not recommended.” Again, there’s good reasons for that but it ignores the reality of how good USB has gotten and the value in using consumer hardware for small projects. AFAICT it just complains once and you can ignore it.

I don’t know. Overall TrueNAS still feels like overkill to me. OTOH it’s not that hard to set up and you can run it for a small storage array. So maybe it’s worth it, just ignore the extra complexity you’re not using?

Inside BOSGAME B100 (adding a drive)

My Mini-PC has support for adding a SATA drive so I took a look at what’s involved. Kinda fiddly. Not as nice as the Beelink in this video where the drive cage has a SATA connector already wired to the motherboard. In the BOSGAME instead there’s a tiny 12 pin connector and the computer came with a cable to plug into that with a SATA connector on the other end. There’s a similar looking cable on Amazon so maybe this connector isn’t entirely proprietary but it is unusual. Also fragile.

USB speeds and bad cables

I had a problem where copying from one USB disk to another was slow, averaging 10.5MBytes/s. The source disk seemed fast enough but while the destination should do 100 MBytes/s it was one tenth that. The problem is it was connected with a USB 2.0 cable at 480 Mbit/s. With better cables it goes fast like expected. Still I should be getting 60MBytes/s out of it, or at least over 30.

I discovered every single USB C-to-A cable I have is USB 2.0 and limited to 480 Mbits/s. I diagnosed this with lsusb -t to see the interface speeds (480, 5000, or 10000) and hdparm -t to test throughput (100 MBytes/s or more when working well.)

Good USB 3 C-to-A cables do exist and can do at least 5000Mbits/s but they cost more. I’m going to have to buy some. There’s no easy way to tell a slow USB 2 cable apart from a fast USB 3 cable, but usually the USB 3 Type A cables have blue connectors or are marked SS or SS+ for “SuperSpeed”.

Update: good cables to buy

I bought a bunch of cables on Amazon and tested them. All of these advertise 10Gbps and tested fine at 10Gb/s. They all have blue connectors but only the Monoprice cable has “10 SS” printed on the connector. I did not test the power on max charging.

  • Monoprice USB 3.1 Gen 2 cables. These are my favorite because they are well labeled. Shortest length is 3 feet.
  • LDLrui, a generic USB 3.2 Gen 2 cable. These seem to work fine and come in 1 foot length.
  • Monoprice USB 3.1 Gen 2 adapter. The only adapter I’ve seen that works at SuperSpeed in both orientations, no “flip for super speed”. No idea if that means it can’t do high power charging. Note this adapter is big, much longer than the flip-style.

I also tried this Ugreen “up to 10Gbps” adapter. It’s one of those “flip to act differently” designs that I think are confusing. Also while I could connect at 5Gbps once, mostly it was connecting at 480Gbps no matter which of 4 orientations I tried. I’m returning them.

Lots of detail

Below is a deep dive on my troubleshooting and some theoretical disk speeds for consumer hardware. But first...

Good USB C-to-A cables

The cable matters! For some reason there’s a bunch of bad cheap C-to-A cables and adapters out there. The good ones cost more, should be marked “super speed”, and probably have blue connectors.

SuperSpeed C-to-A cables exist from name brands like Anker or Monoprice. They cost more. I’ve ordered these and these.

SuperSpeed C-to-A adapters are harder to find and are usually female on the USB-A end. But that’s not what I need, I need a male A plug to stick into the A receptacle on the mini-PC. There’s lots of generic adapters in this configuration but precious few name-brand ones. I ordered these from UGREEN and this Monoprice. (There’s also lots of USB 2.0 C-to-male-A adapters but that’s what I’m trying to replace!)

I am curious about this specific C-to-A jack adapter from XAOSUN. It has a strange design, the docs say “The Type-C female port allows you to switch between USB 3.1 speed and USB 2.0 speed with a simple flip of the Type C plug.” Why would you do that?! One reviewer says “Be aware that devices like this support high-speed charging and high-data transport from USB-C to USB-A 3.0 and above are not symmetrical on the USB-C end. One side of the USB-C supports single-lane USB 3.1 Gen 2 data and low-power charging. The other side of the USB-C supports USB 2.0 data transfer and up to 100W 20V 5A charging.” So maybe that’s it? I did notice the name brand C-to-A adapters talked about maxing out at 3A. Maybe they’re trying to fake non-standard 100W charging on a USB-A port which requires weird wiring incompatible with 10Gbit/s data? Anyway “works differently when flipped” sounds like a confusing mess so I’d rather get something that just does high speed data. All my fast charging devices now are USB-C and USB-PD anyway.

Update: almost all C-to-A small adapters have this flip-for-superspeed design. This discussion says the whole concept of C-to-A adapters is problematic.

Disk medium, SATA, and PCIe speeds

Modern spinning disk media can transfer at least 100MByte/s, more like 150 or even more if you have a high performance disk. SSDs are much faster, like 3000MByte/s or more.

Older disks are interfaced via SATA. SATA 3.0, from 2008, is 6 Gbit/s = 750MByte/s. That’s faster than any spinning disk but slower than modern SSDs. New SSDs interface via M.2 / NVME which runs at PCI bus speeds. That’s very fast, even the oldest PCIe 3.0 with 4 lanes is almost 4000MBytes/s. I’m not clear on whether these SATA and PCIe speeds are shared between devices or not. In practice any PCIe interface is fast enough for any SSD and SATA is fast enough for spinning disks but not SSDs.

Bottom line, here’s a low estimate of speeds of typical disks on modern hardware:

  • Spinning disk via SATA: 100MByte/s
  • SSD via SATA: 500MByte/s
  • SSD via M.2: 3000MByte/s

USB 2 and USB 3 speeds

A proper PC connects to the drives directly via SATA or M.2. But mini-PCs often use USB instead and you have a drive enclosure with SATA or M.2 input and USB output. Modern USB enclosures support at least 5Gbit/s (625MByte/s) which is just about as fast as any SATA drive (HDD or SSD) but will limit an M.2 SSD.

USB comes in multiple flavors, this is a good reference. USB 2.0 is “high speed”, ie: slow. It means 480 Mbit/s (60 MByte/s). USB 3.0 dates to 2008 and is 5Gbit/s (625MByte/s). USB 3.1 is 10Gbit/s and USB 3.2 2x2 is 20Gbit/s. Sometimes you see USB 3 stuff advertised as “SuperSpeed” or “SuperSpeed+” but these days it’s more common to just publish the number. Everything in the last 10 years or so should be supporting at least 5Gbit/s on USB 3, 10Gbit/s is common. 20 is rare.

Note these speeds are shared between all devices on the same USB bus. So if you have two drives plugged in to a 480Mbit/s USB bus the max throughput copying from one to the other is going to be 480 / 2 = 240Mbit/s or 30MByte/s (I think?).

Cables also matter. I think USB-A maxes out at 10Gbps, it can’t do the x2 part required for 20Gbps. Older USB-A cables may be limited to 5Gbps. And old, cheap, or bad cables are limited to 480Mbps USB 2. Look for a blue block inside the connector, that’s the branding for at least 5Gbps. Or the words “SuperSpeed” or “SS”.

USB-C is better. I think most USB-C cables are SuperSpeed but there are probably some cheap “charging cables” out there that aren’t.

Unfortunately, mini-PCs mostly still have USB-A ports on them. So you need a C-to-A adapter or cable. That’s where I got in trouble, turns out a lot of those are not SuperSpeed but limited to USB 2 speeds.

I think mixing USB 2 and USB 3 devices on the same bus is OK and that the USB 3 devices can operate at their faster speeds. Not positive though. (Reference.)

Bottom line theoretical speeds from USB:

  • USB 2.0: 60MByte/s, half that if transferring between two drives
  • USB 3.0 5GBps: 625MByte/s
  • USB 3.1 10GBps: 1250MByte/s
  • USB 3.2 2x2 20GBps: 2500MByte/s

In practice USB 3.1 10Gbps is faster than any SATA interface and even 5Gbps is close to SATA speeds. But USB 2.0 is slow, slower even than spinning disks. It is a bottleneck to be avoided.

Cable testing

I decided to try a bunch of cables with a Samsung SSD 860 EVO 1TB SSD in a UGREEN SATA enclosure. It has a USB-C port. The USB interface is 10Gbit/s, the SATA is 6Gbit/s, and this old SSD drive can do about 500MByte/s. The disk is the bottleneck then, but should be capable of 500MByte/s.

With a USB C-to-C connection to the USB-C port on the BOSgame, lsusb -t shows 10000M speed and hdparm -t measures 500MBytes/s. Great! (I also tested a spinning rust 1TB disk at about 90MBytes/s with this same C-to-C cable. Yay!)

With a blue USB C-to-A cable sold with a hard drive as SuperSpeed, lsusb -t shows 5000M speed and hdparm -t measures 410MBytes/s. Still quite good but it’s interesting the C-to-A connection speed is half the C-to-C and that is reflected in actual throughput. In theory 5000Mbit/s should still deliver 500Mbyte/s transfers but in practice, it gets knocked down to 410MBytes/s.

With various other C-to-A cables: cheap ones, fancy Anker ones that are actually USB 2, the good C-to-C cable plugged into a cheap C-to-A adapter, every other cable I tried it connected at 480Mbps. And the drive measured out about 16MBytes/s. Turns out these are all USB 2.0 cables, WTF? They are garbage but I guess they are common because they are cheaper.

I don’t understand why I’m getting 16MBytes/s with USB 2.0 connections and not the theoretical 60MBytes/s. Maybe the Mini-PC’s USB 2.0 implementation is not very good?

Mini PC speeds

I have a BOSGAME B100 I bought in December 2023. The Amazon marketing page picture says the USB-A ports in back are USB3.2 Gen 1*2 and the USB-A ports in front are “USB3.2 Gen 2*2”. (Note this says “*2” which I think means two ports, not the USB x2 double speed ports.) There is also a USB-C port on front. The Bosgame site spec page also says four USB 3.2 ports but it suggests the front ones are the slower 5Gbit/s and the back are 10Gbit/s. Testing confirms this is true: the back ports are 10Gbit/s, the front ports are 5Gbit. But all these ports should be USB 3 and capable of at least 5Gbit/s = 625MByte/s, faster than any 2.5″ SATA disk. (There is also room for an internal SATA drive.)

I also bought a Beelink S12 Pro Mini PC. According to the Beelink sale page it has 4 USB3.2 Gen2(10Gbps) ports. Good! It also has room for an internal SATA drive.

The good disk

The USB disk I was copying from is an old WD Passport I bought in 2012 and use mostly as a backup drive. It is an honest USB 3.0 drive. lsusb -t shows 5000Mbit/s and hdparm -t tests out at about 100MB/s. I get this using either a USB-A port in the front or the back or the BOSGAME. It’s using a short cable with USB-A on one side (colored blue) and Micro USB 3.0 Micro-B connector on the drive side.

The bad disk

Actually no disks are bad. If I connect them with C-to-C cables, they all test at 100MBytes/s. The badness comes from the crappy C-to-A cables, not the disk.

But the destination disk that was slow for my copy is a WD Blue 2.5″ SATA spinning disk in a cheap Orico enclosure. The disk can do up to 150MB/s and the enclosure claims 10Gbps USB 3.2 Gen2 so should not be a bottleneck. smartctl doesn’t show any obvious errors, the drive has 32,000 hours on it but no errors. It should be capable of 150MByte/s. In practice I get 100MByte/s with a good cable.

The test disk

Described above in cable testing: a 860 EVO in a SATA enclosure. Gets 500MBytes/s with a proper cable.

The best disk

I have an SSD in a UGREEN M.2 enclosure that says it does 10Gbits/s via USB-C. (The SSD itself is a 970 Evo that can do 3000MByte/s, or faster than the USB.) So I should get an honest 1250MByte/s with this device. Just for fun I tried it with a C-to-C cable. It connects at 10,000 Mbit/s. hdparm -t shows just about 1000 MBytes/s, or close to the USB speed. The SSD is capable of 3x that speed but that’s too fast for USB 3. In theory I might get double the speed if I could manage a USB 3.2 2x2 connection at 20Gbit/s.

Observed bad copy behavior

Notes from the slow copy using a bad C-to-A cable. I’m using rsync -a --partial --append --progress to copy a 700GB file from one USB disk to another. It’s slow, it copied at 10.5MBytes/second. the rsync outpput:

699,404,892,160 100% 10.51MB/s 17:37:25 (xfr#1, to-chk=0/2)

That’s terrible. Even worst case (both drives on USB 2.0) I should expect nearly three times this speed.

Watching the rsync progress it fluctuates between 20MB/s to as slow as 2MB/s. iotop doesn’t show me anything interesting, this copy is the only major I/O.

Linux diagnostics: USB

The thing that got me started looking at all this in detail was this output from lsusb -t

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    |__ Port 3: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
    |__ Port 4: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
    |__ Port 6: Dev 5, If 0, Class=Mass Storage, Driver=uas, 480M
    |__ Port 7: Dev 4, If 0, Class=Mass Storage, Driver=uas, 480M
    |__ Port 8: Dev 2, If 0, Class=Wireless, Driver=btusb, 12M
    |__ Port 8: Dev 2, If 1, Class=Wireless, Driver=btusb, 12M

That’s telling me two disks (dev 4 and dev 5) are running at 5000Mbit/s. Good! But two are running at 480Mbit/s. Bad! Even so, I should still get at least 30MByte/s (or more), but something’s not right.

Device 5 is the slow Orico disk I’m writing to. dmesg tells me “usb 3-6: new high-speed USB device number 5 using xhci_hcd”. But lsusb says it’s running at 480Mbit, because of the bad cable.

Device 4 is the 2.5″ SATA SSD in a Ugreen enclosure. Also connected at 480Mbit/s because of the cable.

Note the slow disks are connected with the UAS driver. That should be good, that’s more capable than the older usb-storage driver. These enclosures are newer and support the newer UAS protocol.

Linux diagnostics: hdparm throughput

Not much to say here, just hdparm -t /dev/sdd is a quick test of max throughput on a disk. Something like fio is better for real disk I/O benchmarking but hdparm is useful for seeing if it’s basically working right.

OpenMediaVault first use thoughts

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

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

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

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

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

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

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

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

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

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

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

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

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

OpenMediaVault setup notes

Setting up a little NAS with OpenMediaVault. First time user, my notes on what I did. This guide helped.

VM configuration

  • Make a Proxmox VM with 4GB RAM, 8GB of disk, and 2 CPUs. Legacy DOS BIOS.
  • Add a USB passthrough by device ID for an external disk that’s plugged into the machine
  • Enable qemu-guest-agent (note qemu-ga won’t start and gives a confusing error in the VM without this.)

OMV Installer

Basic Debian installer, mostly just take defaults.

OMV Configuration

Configuration mostly done via OMV’s web UI. Note at first it’s only available via http:, not https:. Default login is admin / openmediavault

  • Apply system updates
  • Change time zone to UTC
  • Change the admin login password
  • ssh: add myself to ~root/.ssh/authorized_keys
  • ssh: Install Tailscale
  • Reboot OMV from the web console

That’s a basic setup. After reboot....

And configuring the storage disk, mostly steps in the Web GUI

  • Storage > Disks: Wipe the disk in the Web UI: I aborted this when it started doing dd if=/dev/zero. But it did something with GPT to the partition table first, so probably a good idea.
  • Storage > Smart: Set up SMART for the external hard drive on USB
  • SSH: apt install hdparm so I can test disk speed (39 MB/s for a slow external drive.)
  • Storage > File Systems: Created an ext4 filesystem on the USB disk. This took a very long time!
  • Storage > File Systems: Mounted the filesystem. It ended up under /srv
  • Storage > Shared Folders: create a shared folder named “test”. Admin and Users are read/write, Others are no access
  • Users: Create a user “nelson” with a password
  • Services > SMB/CIFS > Settings: Enable service, set Workgroup
  • Services > SMB/CIFS > Shares: add the test shared folder I created

And using the disk from a client:

  • On Windows, open \\192.168.3.37\ and type in credentials (after a long pause)
  • On Linux, see the share with smbclient -L //192.168.3.37/
  • On Linux, mount the share
    apt install cifs-utils
    sudo mount -t cifs //server_ip/share_name /mnt/smb_share -o username=your_username,password=your_password
  • The name \\omv\ also works using the hostname omv. Also omv.local resolves as a hostname, Avahi is running.

Beelink N100 boot when power restored

I got a Beelink N100 for a little server. By default if the power is cut, it doesn’t boot again when it comes back on. Annoying for a server!

To enable it, go to the BIOS settings. Under Chipset > PCH-IO Configuration -> State after G3, set that to “S0 state”. There’s screenshots for all this in this Reddit post.

Sure is obscure huh? Why AMI doesn’t have a simple to understand top level setting for this, I don’t know. FWIW PCH is the Platform Controller Hub, the chip (or part of CPU) that controls various parts of a PC system.

PCH defines various power states like “full on” and “soft off”. G3 is “Mechanical OFF”, the name for there being no electricity at all. By default my Beelink goes to S5, which is “Soft Off”. So I’m telling it to go to S0 “Full On” instead after a G3 event.

WSL2, DNS tunneling, and .local names

Just copying the text of a post I made to Reddit. Long story short: if you want .local domain names to work in WSL2, you may have to turn off DNS tunneling.

Query

I’ve got several Linux boxes on my LAN running avahi-daemon. I can connect to machine.local fine on most of my LAN, including my Windows desktop in a web browser or DOS shell. However, my WSL2 system cannot connect to machine.local, it seems unable to resolve mDNS at all.

I tried finding an answer and found several years’ worth of advice, some conflicting. The root cause seems to be WSL2’s complicated networking setup interfering with multicast. Unfortunately I don’t really understand WSL2’s network setup. Is there some easy way to get mDNS resolving working?

Comment I wrote with solution

Setting dnsTunneling to false makes .local names work. I had to restart the WSL2 system as well.

DNS tunneling is described here and the configuration file is described here. There’s also this bug report on GitHub.

Before the change my WSL2 had 10.255.255.254 as the nameserver in the resolv.conf, now it has 172.31.0.1. DNS tunneling is relatively new (from Windows 11 22H2) and “is aimed to improve compatibility with VPNs, and other complex networking set ups”. So maybe turning it off causes other problems. But basic DNS and Tailscale’s Magic DNS are both still working for me and now .local names work too, so I’m happy.

Setting up a new Proxmox server

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

Hardware tasks.

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

Basic Proxmox setup

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

Root shell customizations

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

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

GUI customizations

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

Android Doze mode vs. notifications

Still trying to understand why my fancy Google Pixel doesn’t show me notifications in a timely fashion. I got some new insight into a possible cause from some Reddit comments: Android Doze mode.

Long story short, Doze is a power saving system w here the phone only wakes up every 15-28 minutes to process things in what they call “a maintenance window”. Normal notifications get delayed too, although there is an option for high priority notifications from apps. There’s no way to configure it with the usual Android settings. There are ADB hacks you can apply (and have to re-apply every reboot): see here or here for detailed discussions and solutions. The key thing is the command dumpsys deviceidle disable.

But Doze has been around a very long time, since Android 6. I only started noticing a problem around a year ago, maybe around Android 13 or 14. Did something change?

I’ve got no problem with low power modes! But they can’t interfere with basic use of the device. It’s particularly vexing for me since my phone spends most of its time sitting on a Pixel Stand at 100% battery, power saving is not my problem. (Which suggests one possible change: Pixels have gotten recent changes in battery charge optimization that means the phone may not realize it has a source of charging power when it’s near 100%.)

Another possible explanation for a change is that high priority messaging thing. It’s hard to imagine but maybe Gmail, Signal, and Messages aren’t getting high priority messages anymore and so don’t wake up? That’d be dumb. But maybe it’s a bug / bad system interaction?

Update: Gmail is definitely not getting reliable updates. Twice today I only got updates when I woke the phone up maually. I have no way of knowing what priority Gmail sends its notifications at but it’d sure be dumb if it weren’t high. Gmail has a zillion options for configuring its notification behavior. Most of them were turned on but “Notify for every message” was off. I’ve turned it on, now to wait a few days to see if it makes a difference. (No immediate improvement, just had more mail not show up as notifications. Even after I woke the phone, still took 30 seconds or more.)

Mostly I’m just tired and cranky about this bug. It’s affecting a huge number of Android users all over the world. It has to be obvious to any Google engineer who uses an Android phone regularly. Do they just think it’s OK? Can’t reproduce it? Don’t care?

This is the point where I’d be the hero who does a lot of testing and figures out the problem himself, finds a fix. But fuck that, I’ve got better things to do and don’t really know enough to tackle this one myself. It’s particularly frustrating because it’s hard to reliably reproduce the problem, mostly I notice when I haven’t seen an email I know I got about once a day. Anyway if I do get the interest to tinker again, things to try:

  • the ADB hacks
  • turn off Google’s battery saving charging, see if it works better on the charging stand.

Update: ntfy.sh

Got some interesting perspective reading ntfy.sh’s docs.

Instant delivery allows you to receive messages on your phone instantly, even when your phone is in doze mode, i.e. when the screen turns off, and you leave it on the desk for a while. This is achieved with a foreground service, which you’ll see as a permanent notification that looks like this: ....

Limitations without instant delivery: Without instant delivery, messages may arrive with a significant delay (sometimes many minutes, or even hours later). If you’ve ever picked up your phone and suddenly had 10 messages that were sent long before you know what I’m talking about.

The reason for this is Firebase Cloud Messaging (FCM). FCM is the only Google approved way to send push messages to Android devices, and it’s what pretty much all apps use to deliver push notifications. Firebase is overall pretty bad at delivering messages in time, but on Android, most apps are stuck with it.

The ntfy Android app uses Firebase only for the main host ntfy.sh, and only in the Google Play flavor of the app. It won’t use Firebase for any self-hosted servers, and not at all in the the F-Droid flavor.

Proxmox / KVM cpu types

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

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

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

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

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

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

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

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

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

Linux network interfaces can have more than one IP address

Had to re-learn this. Normally a network interface in Linux has a single IP address. But there’s nothing stopping you from adding several.

Adding a second address is as simple as running something like ip addr add 192.168.3.254/24 dev eth0.

Here’s a config I just set up in Alpine in /etc/network/interfaces. Not sure what the netplan equivalent looks like.

auto eth0
iface eth0 inet static
        address 192.168.9.5/24
        gateway 192.168.9.1
        hostname $(hostname)

auto eth0:0
iface eth0:0 inet static
        address 192.168.3.254/24

More details in this Reddit post where I originally tried to make it much more complicated.

A good Claude programming example

I’ve been having such a good time using Claude 3.5 Sonnet to help me program and learn APIs I’m not good at. See this transcript for an example, where Claude walks me through setting up a basic Python command line project, then adds pytest to it, then adds click, then makes it work in VS.Code

I taught myself how to do all these tasks three months ago. But it was a tedious process of finding the right updated docs, then experimenting a lot, and in the end not quite getting it right. A typical pre-AI programming experience. It did only take me an hour or two, and thirty minutes the second time, but still it was tedious.

Claude just magically gives me the answers. Here’s the catch: I’m not certain they’re right. I didn’t review this transcript closely or run the code. I did read it all though, and it is plausible. I am confident I could start with what Claude did for me, maybe fix a few little problems, and have a working thing. But it’s very important an expert programmer still be in the loop, you can’t just trust the code it emits. I’m fine with that, it saved me a lot of time.

What’s remarkable is it gets so many core concepts I learned three months ago right:

  • the file structure with src/hello_world_cli/__init__.py and tests/
  • the contents of pyproject.toml
  • using optional dependencies for pytest, etc
  • the structure of a decent README.md
  • click’s decorators for CLI programs, including an example of a switch
  • the use of CliRunner to test click commands in pytest
  • the need for a __name__ block to make it run under VS.Code debugger
  • it even incremented the tool version number after making changes!

It even taught me some new tricks:

  • using tool.pytest.ini_options to set up paths
  • using hatchling instead of setuptools
  • creating a launch.json file for .vscode

I know that all that’s happening behind the scenes is a very big neural network is predicting token outputs. But what it looks like to me is Claude knows a lot about programming including the use of several complex open source tools. And I can mostly chat with Claude pretending it is intelligent and understands what I’m asking and it will give me useful answers.

The limitation is I asked it precise questions about a relatively basic thing with a whole lot of good code examples and docs on the Internet. It wouldn’t do nearly as well with some more obscure libraries for which there are no good examples. It will have a harder time with more complex code. And it certainly won’t invent new things, Claude is not going to create a new algorithm for distributed consensus or something.

But for basic stuff it sure is a lot better than doing Internet searches and reading through docs and example code myself. It makes programming way more fun for me by eliminating a lot of tedium.

Booting Windows 11 23H2 to Steam Big Picture

I want my new TV gaming PC to boot all the way in to Steam Big Picture with no keyboard required. This is remarkably difficult and all the docs you find are outdated because Win 11 23H2 changed some things. Microsoft really doesn’t want you do this. Partly for good reason (it removes local system security) and partly because they are trying to force you into their monopoly experience.

This worked for me:

1. Log in locally, not with Microsoft account

Settings > Accounts > Your info has a “Sign in with a local account instead”. Turn that on.

Documented here, at least until Microsoft hides the docs again. When I did this I got warned I needed to back up my Bitlocker encryption key first, I guess because ordinarily that’s stored in your Microsoft key. I just removed Bitlocker entirely instead.

2. Re-enable the “no password” UI option

Go in RegEdit to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PasswordLess\Device and set the value DevicePasswordLessBuildVersion to 0. (Mine was 2).

This is a new thing in 23H2, documented here. If you don’t, the next step won’t work.

3. Enable passwordless login

Run the program netplwiz. Uncheck the checkbox at the top for “Users must enter a user name and password to use this computer”.

Documented here. This doesn’t work in 23H2 if you don’t do step 2 to re-enable it. Why the stupid program name? It started life as the “Add Network Places Wizard”, terminology from Windows 95.

4. Get Steam to start at boot in Big Picture mode

Go to Steam Settings > Interface. Enable “Run Steam when my computer starts” and “Start Steam in Big Picture Mode”.

Documented here. The web has all sorts of complicated docs with registry edits, batch files, replacing the Windows shell, etc... None of that is necessary.

NFS still a tar pit in 2024

I was dorking around with a new NFS server and ran mount testserver:/test /tmp/test on my main computer. Then I turned off the testserver VM and forgot about it. Classic mistake, one I’ve been making occasionally for over 30 years.

The NFS disk in /tmp/test was still mounted on my client machine. And because I supplied no options to the mount command, it was a hard mount by default. Which means anything that accesses /tmp/test will get stuck in device wait, very hard to interrupt. I first noticed this because my restic backups were failing. It tried to back up /tmp/test and got stuck and the backup failed. (Why am I backing up /tmp? Lol.)

The usual fix is to supply some options to the NFS mount so it’s interruptible or has a timeout. Some options to know of: soft, timeo, retrans, intr. My fstab mounts things with this cargo cult set of options: x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=10s. No idea where I got that, not sure it even actually works. Reading docs now I think that 10s timeout is for the initial mount only. ANd why does systemd need to be involved with its own bizarro thing? Who knows.

I also don’t understand why NFS doesn’t have some basic keepalive / server liveness test in its client. Maybe because NFS was originally connectionless and sort of loosey-goosey? I thought NFSv4 made all that much better. Maybe there’s some way to configure it. But the default options on Linux in 2024 are a tar trap.

I tried a bunch of things to unwedge my client. umount -f, which fails. lsof to see what processes had it open preventing the umount, which hangs forever. I finally gave up and just rebooted the NFS client. Awesome.

The underlying problem is network resources are not local resources. Software likes to assume that commands to a hard drive will either succeed or fail, not just hang indefinitely. But with a network filesystem they absolutely can hang. Even with a local one: modern hard drives are complex devices.

First impression of NixOS

I thought I’d give NixOS a spin after chatting with Jeff N. I had a great experience, I went from zero knowledge to a working web server in under two hours. And that includes lots of time writing this blog post, reading Mastodon, etc. And it was fun too!

I got this done mostly by asking Claude to tell me what to do: who has patience to read docs? It’s fun to learn something new this way. Also using this Wiki page and this baby steps tutorial. Julia’s notes are good too.

Update: I did this all as a Proxmox VM. There’s also notes on installing NixOS in a Proxmox LXC container.

Some basic concepts

I’m still trying to work my head around what Nix does. My impression is it’s similar to a Dockerfile or a puppet/ansible script, it’s a config file that creates a working Linux environment for stuff to run in. The difference is Nix has fancy design so everything’s managed, rollbacks are possible, etc.

NixOS is not Nix. Nix is the package manager, NixOS is an operating system built using the Nix package manager. Nix is like apt, NixOS is like Ubuntu.

The master configuration for NixOS and all the things running in it (like a web server) is in /etc/nixos/configuration.nix and has its own syntax. Almost the whole system is configured here. Nix folks have written little shims to take configuration directives from this file and write them into whatever weirdo format the ancient Unix utility might expect. (I hear the sendmail.cf generator is sentient but no one can understand what it’s saying.) You edit configuration.nix, check it into git, etc. You use nixos-rebuild switch to tell the system to implement the changes.

I’m looking at NixOS for a whole system image but there’s also a way to use Nix for your personal user environment that’s broadly similar.

There’s an effort to make bit-for-bit reproducible builds for NixOS which has nice affordances for security. But that’s not the only reason to use NixOS, more a happy side effect.

Install experience

First attempt for an install was with the minimal NixOS ISO (still 1GB!). But they aren’t kidding about minimal, this thing has you running fdisk yourself and leaves you with an unconfigured system. The graphical installer (3.5GBish) partitions a disk and gives you a basic working system when it’s done, so that’s easier.

After the default install the system reboots. 2.7GB is consumed on the hard drive and there’s 89 packages (not counting documentation packages). There’s about 10 processes running other than the kernel and all its threads. They all run out of /nix/store. They include

  • systemd running journald, udevd, oomd, timesyncd, logind
  • dbus-daemon
  • nsncd: a shim for name service (this one?)
  • Networkmanager

That’s a remarkably small system.

/bin and /usr/bin are nearly empty. There’s about 10 directories in my $PATH but much of what I’d expect to find is in /run/current-system/sw/. All the binaries there are symlinks into /nix/store. They’ve been dynamically linked with libraries like libc referencing paths in /nix/store.

NixOS installs a fairly complete Linux environment, at least it has less, bash, rsync, ssh. No sshd, python, or vim though. So why 2.7GB? As near as I can tell there’s a lot of stuff in /nix/store that’s not in my current environment, like a whole install of python3.11. Those binaries seem to work if I run them directly but I’m guessing I’m supposed to configure the NixOS system to officially use them if I want them.

The /nix/store can apparently get very large but there’s ways to manage it. I’m not sure if there’s an easy way to say “prune everything off the disk I don’t actually use” to get the install size down to 100MB or so.

Installing some packages in NixOS

First up, add an ssh server so I can log in easily. That’s as simple as editing configuration.nix to uncomment the line services.openssh.enable = true and then running nixos-rebuild switch to make it happen. The switch takes about 6 seconds. Various docs reference having to configure the firewall or enable password login, I didn’t have to do either with the NixOS GUI install’s defaults. (There’s some magic that allows ssh through the firewall if you enable it.)

I tried a rollback to remove ssh again. Easy as running nixos-rebuild switch --rollback. Apparently nix is keeping a history of what it’s done that it can undo. The rollback kills the sshd so I can’t log in anymore. My active sshd was still running, so I guess it doesn’t kill everything. (That implies many things about just how much state Nix will alter. Files, not memory, is my guess.)

Adding other shell utilities just requires listing them in environment.systemPackages. (Or maybe in a user environment, don’t understand that yet.) Whitespace delimited list. I did “joe git zip unzip” for now. And another rebuild switch and now I have those binaries available.

Final project was a hello world web server. I had Claude do this part for me.

  # Enable Caddy web server
  services.caddy = {
    enable = true;
    configFile = pkgs.writeText "Caddyfile" ''
      :80 {
        root * /var/www
        file_server
      }
    '';
  };

  # Create a simple HTML file
  system.activationScripts.createWebRoot = ''
    mkdir -p /var/www
    echo "<html><body><h1>Hello World from NixOS!</h1></body></html>" > /var/www/index.html
  '';

  # Allow HTTP traffic
  networking.firewall.allowedTCPPorts = [ 80 ];

That all just worked, thanks Claude! The firewall change was necessary: without it Caddy was running but unreachable outside this machine. iptables -L confirms that there is a firewall running (the default for NixOS), the chain nixos-fw seems most relevant. It’s letting in only ssh and http and ICMP ping.

Things to learn about

  • Updating packages from network
  • Scripting creating a new NixOS system from the environment file
  • Per-user Nix config vs system-wide
  • Nix state tracking, how rollbacks work
  • Logging
  • Recommendations for running actual production services in NixOS
  • Pruning disk usage
  • The ecosystem of Nix packages
  • nix-shell
  • WTF a flake is

Thoughts

This experiment was a good experience. Over the years I’ve tried a bunch of ways to automate setting up Linux system environments and gotten very frustrated every time. NixOS I had up and running in an hour and I feel like I could use this for real.

What would I use it for? Not sure, need to think more. I’ve been considering rolling my own NAS, a setup with NFS and Samba and syncthing and restic. I was just going to hand configure it but maybe NixOS would be a nice way to do that in a more managed way. As a VM in Proxmox I guess? Or maybe just an LXC container. Or just as a Nix thing in a general purpose VM, not sure if Nix gives me the separation I’d otherwise use Proxmox for.

I’ve run into some usability warts. nix search does not work as the config file suggests, you have to do some complicated set of flags for “experimental features” (this is apparently fixable but is a bad experience for a newbie!) The configuration that the NixOS installer created throws various warnings when you build with it. But stuff mostly seems to work.

The NixOS docs seem pretty good. I haven’t read them much but Claude has and that works great for queries. When I’ve looked stuff up myself there’s clear explanations for what I’m trying to learn.

I love learning new stuff like this. Claude was a big help.

Another failed Ubuntu 23.04 upgrade

Failed again to upgrade my recalcitrant Ubuntu 23.04 system. I give up and I’m mad at Ubuntu’s EOL policies.

The fun thing is how much some new tools make this kind of thing easier and safer. I had a lot of confidence experimenting thanks to Proxmox and the ability to easy rollback the whole system or restore a backup. I also got a lot further than I thought I would using Claude. These AIs still have a problem that sometimes it confidentally recommends bullshit. But as long as you understand that and evaluate suggestions yourself it’s a lot faster using an AI to find things than searching ordinary docs and forum posts. I tried more things more quickly than I would have without the AI help.

Hacking around GRUB

The problem last time is my system was installed with GRUB referencing a disk in /dev/disk/by-id that no longer exists. When I virtualized the server those IDs got lost. Claude did a great job suggesting various fixes. Some were wrong (like a hallucinated GRUB_DEVICE config) and some were plausible but don’t work (purge and reinstall GRUB). The good suggestion was to use debconf-set-selections to force a reconfig.

echo "grub-efi grub-efi/install_devices select" | sudo debconf-set-selections
dpkg-reconfigure grub-efi-amd64

This forced GRUB to reconfigure the path. It picked /dev/vba1. Not ideal (a UUID path would be better) but should work. And it did! I could reinstall GRUB on my 23.04 system, reboot, the BIOS all seemed happy. Success!

Maybe. After far too much drama upgrading to 23.10 the system then didn’t reboot. It all looked like it worked but the BIOS was no longer happy with what it found for a boot partition. I chickened out at that point and rolled back, gave up.

Ubuntu’s hostile EOL policy

Even though I think I fixed GRUB, I once failed in my attempt to upgrade Ubuntu.

Ubuntu has a clear but obnoxious policy that outside LTS releases, their interim go end of life quickly. 23.04 went EOL on January 25, 2024. The entire lifespan of this release was 8 months and if you don’t upgrade quickly enough, too bad. I’m a little confused why it won’t still let me update to 23.10: it goes EOL in three days. But when I tried I was told “Your Ubuntu release is not supported anymore”. There’s no option to upgrade directly to 24.04 LTS either.

I don’t mind that they EOL releases and don’t offer regular patches. But they really should offer some sort of upgrade path. They kind of do, I’ve upgraded an EOL system once before by hacking the sources.list to point at http://old-releases.ubuntu.com/. But there’s absolutely no tool help for doing that and you are on your own.

This time around I tried just swapping URLs and doing apt full-upgrade. It sure looked like it worked but then the reboot failed, maybe because of a bad update process or maybe because of my weird GRUB situation. Either way, I gave up.

At this point I’m going to give up and use Ubuntu LTS releases only. Which means one release every two years. I guess I’ll use something with rolling releases (Arch or Debian testing) if I need a more updated OS.

And now I’m doubly committed to rebuilding my main home Linux server. I kind of punted on that six months ago when I virtualized it into Proxmox as a whole system. I don’t relish rebuilding it all as lots of little containers but it’s probably a good idea. (Oh joy, now I can update 20 little Ubuntu systems instead of one big one!)

The yearly Ubiquiti UnifiOS disaster

About once a year my Ubiquiti routers give me trouble. I’ve long since stopped asking anything complicated of them like reliable failover or a VPN. I just want it routing packets. This week’s problem is my Unifi Dream Machine, my router/access point in San Francisco. I installed in in late 2020 and to its credit haven’t thought much about it since. Including not doing software updates. (Oops).

Yesterday I tried to upgrade it from version 1.0.10. It went badly, I ended up having to factory reset and rebuild the network configuration from memory. Some notes on that:

Being safer next time

First, how to prevent the mess I found myself in. The main problem is I had no backup of the Network application config. I did have one for the UDM console itself but that doesn’t contain the useful network stuff like wifi SSID, subnet, port forwarding, ... I should have made a backup before doing anything. Modern Unifi systems are backing up to the cloud, maybe automatically, but mine was so old I think I had to have done a manual backup and downloaded it. By the time I thought to do that it was too late.

What went wrong

The update process sucked. It wanted to upgrade itself like six times as it hauled itself forward through versions. Each update took at least 5 minutes, one said it’d take 20 and was more like 45. Each time the Internet connection would go down for a few seconds, twice. Mostly though it looked like things were working.

Until I got to UnifiOS v4.0.6, the current version. That time when it booted the “Network” app that’s most of what I really care about never started. Just spinning, hung in starting. I logged in via ssh to see what was up and couldn’t really figure it out. The mongod was spinning around 100% CPU though. Why Ubiqiuti chose such a weird and unreliable database for this simple application is beyond me.

The Internet is full of advice on how to manually repair corrupted Unifi mongo databases. But I decided to cut my losses and do a factory reset. The appliance said it had a full cloud backup, should be easy right? ha, joke’s on me. That was just a backup of the host OS itself, not the network. After the reset and restore the network was default settings.

I had no network backup. I’m a little confused; the updated Network 8.2.93 app has a manual backup option that downloads a file, but then implies the cloud backup of the console should cover the network too. That didn’t work for me, maybe because the crucial update failed? I was able to do one manual backup of 8.2.93 after configuration. A second one never completed. A third fails immediately. That does not inspire confidence. After a reboot a backup worked.

(I also can’t figure out how to backup the network config on a self-hosted Unifi linux environment running Network 8.0.7. The backup button does not appear under Settings > System. A comment I read online suggests this may be a user permissions problem but I can visually inspect all the settings I want to back up so that seems wrong or dumb. I was finally able to make a backup using the managed utility at https://unifi.ui.com/. I also saw a hint monthly backups were happening and being stored locally, not synced to cloud.)

Rebuilding the network

So I rebuilt the network. Over the years I’ve learned my lesson and keep the router as simple as possible. But I use the non-default 192.168.0.* subnet. Also am forwarding ports for ssh, web servers, tailscale, plex, and syncthing. There’s a lot of fun looking other settings for things like the WiFi radio I didn’t touch.

I had to re-adopt my UAP-AC-Pro access point. In theory my restore for the UDM should have taken care of that. Getting the impression that backup did absolutely nothing useful. At least that’s relatively simple since there’s no significant device configuration. Hold down the reset button on the hardware, then click the “Adopt” button in the webapp.

Some observations

Complaints and disaster aside the latest Network webapp on the UDM is pretty snappy. The old bugs where you’d change something in the config and it wouldn’t take until a reboot seem gone. The app shows lots of interesting things like a visualization of how all your wifi clients are doing. There’s also a neat NetMan mobile app for more wifi testing.

The Unifi network webapp itself is some overgrown dynamic Javascript architecture where page loads aren’t really page loads. It’s perfectly possible to click the “Dashboard” button and see a working new dashboard page even though the router is actually down. Just old data and no immediate confirmation that the router is even up. Really bad choice for a router, as snappy as it may be.

The Dynamic DNS configuration for Afraid has you storing your account password in plaintext. Afraid has long-had a token based authentication mechanism they should be using instead.

By default port 443 is captured by the router itself to get to its own admin page. That’s probably secure, and I think but am not certain it’s not available over the Internet by default. Also you can port forward 443 somewhere else on your LAN if you need. Ubiquiti has a whole remote management API with mobile apps and stuff you’re supposed to use instead of the web server. It’s pretty nice, TBH.

ssh firedrill: patches, fail2ban

Major new ssh vulnerability including a remote root exploit of SSH servers. So far the exploit has only been demonstrated on 32 bit systems and that takes several hours of hammering a race condition. But it’s likely to get worse over time.

The easy fix is to install an update; here’s how to do that in Ubuntu. The openssh release notes are also helpful. They released version 9.8 to fix it. Ubuntu backported that fix to older versions. Unfortunately I have a system stuck at Ubuntu 23.04 which is not getting updates anymore. So I need a temporary workaround.

I went with installing fail2ban. I do not like that system, it’s a gross hack with way too many config options that can completely break your system. But I got it done. The ubuntu fail2ban by default doesn’t ban anything (I think). You copy jail.conf to jail.local and then edit the sshd section to enable it. There’s a bunch of outdated guides, I ended up using the Claude AI to figure it out.

Anyway, end of the day fail2ban scans your ssh log files and creates IP table rules to block aggressive clients. Not a full fix but should make a race condition exploit a lot harder. You can see what fail2ban is doing in the moment with fail2ban-client status sshd or use iptable -L to see the rules it’s creating and removing. Lol, just realized I log in with CGNAT. So some other Starlink user on the same IP address as me could conceivably block me from logging in. Oops.

Another option mentioned in the release is to set sshd’s LoginGraceTime to 0. That means “no limit”, so clients never get dropped if they hang during login. But that now opens you to a DDOS, I think by default sshd allows 100 simultaneous logins and if someone’s trying to exploit the race condition they’d quickly fill all those slots. Not positive.

The last thing I did was look at my bash history to see what hosts I ssh into to make sure they are all updated. Unfortunately you can’t read known_hosts anymore to see where you’ve logged in since the hostnames are hashed. Again Claude AI to the rescue, here’s what it recommended:

history | grep ssh | awk '{for(i=1;i<=NF;i++) if($i~/^[^-].@./) print $i}' | cut -d'@' -f2 | sort -u

I should probably disable ssh entirely on my public interfaces and require tailscale to log in. But despite a year+ of reliability I still don’t fully trust tailscale, what happens if it breaks for some reason and I can’t log in?