Skip to content

feat(convert): support Ubuntu cloud images - #166

Closed
imlk0 wants to merge 7 commits into
masterfrom
convert-ubuntu-support
Closed

imlk0 wants to merge 7 commits into
masterfrom
convert-ubuntu-support

Conversation

@imlk0

@imlk0 imlk0 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Ubuntu 24.04 LTS (Noble) cloud image support for cryptpilot-convert and cryptpilot-enhance, stacked on #164.

  • cryptpilot-enhance.sh: DEB-based guests use apt-get for cloud-init/openssh removal, harden the /etc/ssh/sshd_config.d/*.conf drop-ins (Ubuntu's drop-ins are read after the main file and would otherwise override the hardened values), purge the aliyun-assist DEB packages, and run the account-cleanup guest script under POSIX sh. Fixed while porting: the old dpkg-query -W -f='${dpkg-Package}' never worked (invalid field name, and the nested quoting made the host shell expand it) — now uses ${binary:Package} with correct quote-splicing.
  • cryptpilot-convert.sh, DEB install path: apt-get update, pre-install dracut dracut-network lvm2 cryptsetup-bin before dpkg -i (dependency resolution), apt-get -f install after; cryptpilot-fde-guest is excluded from the essential-package apt pass; zram module install is best-effort. Fixed the version-detection bug this PR inherited from master: rpm -q ... || true captured rpm's stdout error text as the version string on hosts that have rpm but no cryptpilot-fde-host package.
  • cryptpilot-convert.sh, GRUB: create a grubenv with saved_entry for images lacking one (Ubuntu cloud images), set GRUB_DEFAULT=saved, and disable os-prober (it scans NBD devices and fails inside containers, leaving grub.cfg without menuentries).
  • cryptpilot-convert.sh, UKI small-ESP resize (new implementation, not a port): when the output ESP is under 250M, sfdisk --dump --json + python3 computes a new layout with the ESP grown to 512M and later partitions shifted (aligned, type/uuid preserved, partition numbers pinned via the <device>pN prefix); the output ESP is then re-created with mkfs.vfat at full size (label preserved) and populated from the source, so dracut can write the UKI without hitting ENOSPC. The plain-dd copy path is unchanged for all non-resize cases.
  • tests/test-convert.sh: --distro <alinux3|ubuntu> and --deb support, Ubuntu image download/grow/prepare, Ubuntu login-prompt detection, skip enhance when --input is a custom image.
  • CI: a test-convert (grub/uki) job in build-deb.yml running against the prepared noble test image, and an ubuntu mode in build-test-image.yml producing that image. No libguestfs dependencies (the current convert pipeline does not use it).

Supersedes the Ubuntu half of #110.

Test plan

  • Full DEB set (0.9.3) built in an ubuntu:noble container via dpkg-buildpackage.
  • End-to-end convert of a Noble cloud image, GRUB mode: rc=0; EFI (p15, 106M) has shim/grub/BOOTX64.EFI, boot partition (p16) carries the fresh initramfs, fresh 1024-byte grubenv with saved_entry=6.8.0-117-generic, os-prober drop-in in place, version detection fails cleanly (empty version + warning, not rpm's error text).
  • End-to-end convert, UKI mode with --uki-stub-version 258: rc=0; the resize fired ("Growing EFI partition p15 to 512M"), output ESP is 512M with the ~80M UKI at EFI/BOOT/BOOTX64.EFI, all PARTUUIDs preserved, rootfs shrank 9G to 8.6G.
  • Rebased onto current master (post-perf(convert): reduce rootfs copies from 3 to 1 #164, includes fix(convert): support GCP-style images with a separate ESP grub.cfg and vendor kernels #130 and the zram/saved_entry fixes); conflicts resolved keeping master's behavior; GRUB e2e re-run green after the rebase.
  • bash -n, shellcheck (convert/enhance/test-convert), cargo fmt --check clean.
  • CI: the new build-deb test-convert legs against the prepared noble image (first run on this PR).

Known follow-ups

  • The resize path re-creates the ESP, so the FAT filesystem serial changes (label and PARTUUID are preserved; Ubuntu mounts the ESP by LABEL, so this is invisible on Noble). An fstab referencing the ESP by FAT UUID would break; noted for a future change if that ever surfaces.

imlk0 added 7 commits October 30, 2026 12:27
Use apt-get instead of yum for DEB-based guests when removing
cloud-init and openssh-server, purge the aliyun-assist DEB package,
and fix the sshd_config.d drop-in files Ubuntu ships, which are read
after sshd_config and would override the hardened values. Make the
account-cleanup guest script POSIX sh so it runs on guests without
bash, and replace history -c (which only clears the customize
session) with removal of the history files.

The dpkg-query package-list field is ${binary:Package}; the
${dpkg-Package} spelling used previously expands to nothing on
noble, so the aliyun purge was a silent no-op there.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Refresh the apt indexes and pre-install dracut, dracut-network, lvm2
and cryptsetup-bin before dpkg -i, so the cryptpilot-fde-guest deb
resolves its dependencies instead of failing configuration. Skip
cryptpilot-fde-guest in the essential-package apt-get pass: a version
string detected on an RPM-based host matches no apt candidate and
fails the whole install. Make the zram module install best-effort;
Ubuntu kernels without a linux-image-*-generic name would otherwise
abort the conversion.

Also fix the cryptpilot-fde-host version probe: rpm writes its
"package is not installed" message to stdout, so "|| true" inside the
command substitution captures that text as the version on hosts that
have rpm but no cryptpilot-fde-host. Move the fallback outside the
substitution, matching the pattern already used by the RPM installer.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Ubuntu cloud images ship without a grubenv block and without
GRUB_DEFAULT=saved. cryptpilot-fde-host show-reference-value reads
saved_entry, so create the 1024-byte grubenv when missing, pick the
newest non-rescue kernel (stripping the vmlinuz- prefix to match
Ubuntu's menuentry format) and set GRUB_DEFAULT=saved in
/etc/default/grub and its grub.d drop-ins.

Disable os-prober before running grub-mkconfig: it scans every block
device and fails with "Device or resource busy" inside containers
with NBD devices attached, leaving a grub.cfg without menuentries.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Some cloud images ship an ESP too small for a UKI plus the scratch
space firmware needs while booting it (Ubuntu noble: ~106M). In UKI
mode, when the output ESP is below 250M, rewrite the output partition
table with the ESP grown to 512M at its current start and every later
partition shifted behind it, preserving type, uuid and size, with
starts aligned to 2048 sectors as elsewhere. The last partition
shrinks only when the shifted layout would run past the disk end.

The layout is parsed from sfdisk --dump --json and emitted as a fresh
sfdisk script via python3, and each entry keeps its "<device>pN :"
prefix so sfdisk preserves the original partition numbers. Partition
UUIDs survive because the guest grub.cfg references them.

Since the partition was enlarged, dd of the source ESP would restore
the small vfat superblock and leave dracut hitting ENOSPC, so
copy_partitions instead creates a fresh vfat spanning the enlarged
partition (keeping the source label, which Ubuntu's fstab mounts the
ESP by) and copies the source content. The plain dd path is unchanged
for every other case.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Add --distro <alinux3|ubuntu> and --deb/--package as alternatives to
--rpm. For Ubuntu, download the pinned noble 20260518 cloud image,
grow it to 10G and relocate the backup GPT: the stock image is too
small for the converted layout, and the conversion installs dracut
itself so no guest preparation is needed. A custom --input image
counts as already prepared and skips cryptpilot-enhance.

Detect a successful Ubuntu boot from "Welcome to Ubuntu", a ttyN
login: line, or systemd reaching multi-user, since Ubuntu cloud
images do not print the alinux login banner on the serial console.
Raise the boot timeout to 15 minutes for TCG runners.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
build-deb.yml gains a test-convert job (needs build and test) with a
grub/uki matrix that runs tests/test-convert.sh with the freshly built
cryptpilot-fde-guest deb against the prepared noble test image. The
tool list is minimal: the harness needs wget, qemu-utils, cryptsetup,
lvm2, e2fsprogs, gdisk, parted and dosfstools (the UKI ESP
re-creation); cryptpilot-convert installs anything else itself. No
libguestfs is needed, the current convert pipeline does not use it.

build-test-image.yml gains a distro input: "ubuntu" prepares a Noble
cloud image (pinned 20260518 daily) by setting a root password,
growing the disk to 10G with a GPT repair, and pre-installing dracut
and systemd-boot-efi via qemu-nbd + chroot, then packages the result
as the ghcr test image like the direct mode does.

Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Assisted-by: Claude Code:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,您的请求已接收,请耐心等待结果。

@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。

@imlk0

imlk0 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of a clean-room rewrite: the script changes here are being redone from scratch on a fresh branch against current master (tests/CI will follow in a separate PR stacked on it).

@imlk0 imlk0 closed this Oct 30, 2026
@imlk0
imlk0 deleted the convert-ubuntu-support branch October 30, 2026 07:52
@imlk0 imlk0 mentioned this pull request Oct 30, 2026
6 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants