Rebuilding a Linux box with nobody at the keyboard
Ubuntu 26.04 installed overnight on my home Linux box with no USB stick: the old system booted the installer ISO from its own disk, the answers came over HTTP from my other box, and it took three goes.
My home Linux box went from Ubuntu 22.04 to a fresh 26.04 overnight with no USB stick and nobody sitting at it. The old system booted the official installer ISO from its own disk, the installer fetched its answers over HTTP from my other box, and it installed onto the machine’s second NVMe drive. The old system is still on the first one.
I didn’t want a copy of the other box’s system. I wanted a real Ubuntu install, then the packages, settings and data brought across, so nothing on the new system is there because the old one happened to have it.
Before anything was wiped
The second drive held storage, so that went first: 388,212 files copied onto the main disk and checked with sha256sum -c, no failures, and an rsync --checksum dry run over the rest that listed nothing different.
The ISO was checked against Ubuntu’s signed checksums before it went anywhere near GRUB:
gpgv --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg SHA256SUMS.gpg SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMS
Booting the installer without a stick
GRUB can loop-mount an ISO and boot the kernel inside it. One entry in /etc/grub.d/40_custom on the old system:
menuentry "Ubuntu 26.04 autoinstall" {
loopback loop /ubuntu-server.iso
linux (loop)/casper/vmlinuz iso-scan/filename=/ubuntu-server.iso ip=dhcp autoinstall "ds=nocloud;s=http://OTHER_BOX:PORT/" ---
initrd (loop)/casper/initrd
}
With GRUB_DEFAULT=saved, grub-reboot "Ubuntu 26.04 autoinstall" boots that entry once, and the boot after it goes back to the old system.
ds=nocloud;s= points the installer at a folder served by python3 -m http.server on the other box, holding user-data and meta-data. The answers file picks the target disk by its serial number, so it can’t choose the wrong drive, and lays out the same partitions as the other box: root, home and /data.
Three goes
The first stopped before it touched a disk, with “Malformed autoinstall in ‘late-commands’ section”. One late command had a colon followed by a space in it, unquoted, and YAML read the line as a mapping. Every item in that list has to come out of yaml.safe_load as a string, which takes one line of Python to test before serving the file.
The second got as far as partitioning and writing the base system, and then the machine was hard-rebooted in the middle of it. The old system came up as if nothing had happened, because nothing had happened to its disk. grub-reboot again.
The third fetched its answers at 03:23 and installed everything, then failed on a late command that mounted the old root partition read-only: exit 32, “would change RO state”. The ISO had been loop-booted from that partition, so the live system already had it mounted read-write out of sight. A plain mount works. I finished the last few steps by hand from the installer’s error shell over ssh and rebooted into the new system.
Two things were wrong on first boot. The home folder was owned by root and empty, because the installer mounts the home partition over it before it creates the user. And the server installer sets the network up with systemd-networkd where my other box uses NetworkManager. I switched it over ssh with a three-minute systemd-run timer armed to put the old config back, and cancelled the timer when the connection came back.
Matching the other box
A script on the new system pulled from the other one: its apt sources, its manually installed packages (171 to install), its snaps, a list of files under /etc, the three local .debs rebuilt with dpkg-repack, and the services it has enabled. The home folder was 243 GB and the archive under /data another 475 GB.
The server ISO leaves things a desktop doesn’t want, so needrestart, landscape-common, lxd-installer, ubuntu-server and six more came off. That exposed a trap. tmux, htop, git, curl, vim, ufw and 30 others were marked as automatically installed on the new box and manual on the old one, so the next apt autoremove would have taken them. The script now marks manual whatever the source has manual.
The Wi-Fi came from the old disk: 33 profiles copied out of its /etc/NetworkManager/system-connections/. So did Bluetooth. It’s the same adapter, so copying /var/lib/bluetooth/<adapter>/ with bluetoothd stopped brought all 10 pairings back without re-pairing anything.
After that every package on the box I carry was on the home one at the same version, with the same kernel and the same snaps. The final reboot was at 08:04. It came back in under a minute and systemctl --failed was empty.
The 22.04 system is still on the first drive, mounted under /mnt on the new one.
Featured projects
-
Apple News API
Publish articles and live coverage to Apple News from PHP, with the whole Apple News Format built from objects.
-
GitHub Auditor
Health, access and activity reports for more GitHub and Bitbucket repositories than you can keep in your head.
-
PrintMD
Markdown in, and a designed PDF, Word or PowerPoint file out. Its PDF service runs on your own computer.
-
Where Should I Live
Which city would leave you best off? Cities ranked by take-home pay, living costs, visas and the way you live.
-
Solar Calendar
Thirteen months of exactly four weeks, with the year starting on the first Monday on or after the spring equinox.
Latest writing
-
Many sessions at once, and what still needs me
Fifteen coding-agent sessions across two Linux boxes, one session that watches the rest, what it may answer for me, what it never may, and why a yes it passes on gets checked against what I typed.
-
61 public repos of agent tooling, none installed, six ideas kept
One author, 61 public repositories of coding-agent tooling: what I checked before any of it got near my Linux boxes, why none of it was installed, and the six ideas I built my own way.
-
Rules a coding agent cannot talk its way round
The hook that reads every command a coding agent wants to run on my Linux boxes: what it refuses, the 27 proofs that its tests fail when a rule is taken out, and the four lines every report opens with.
-
Dozens of repos, one person
46 repositories and two Linux boxes with nobody else on them: the diary, the decision table, the rebuild guide and the job that keeps both sets of clones in step.