Debian Hyper-V Setup Was Slow
So I made it faster. A lot faster.I can now run a full Debian install with SSH Server group selected in 77 seconds. From a regular netinst iso.
No, it isn't normally that fast.
Here is my rough recollection of what it took to make it faster:
- Automate with a preseed ( obviously )
- Automate interaction with Hyper-V itself through C code calling WMI
- Wrote my own custom Go package cache
- Wrote my own VHDX FAT32 image builder from scratch in dependency-free C
- Wrote my own custom C debootstrap. Yeah cdebootstrap exists and I didn't use that.
- Utilize HyperV vmbus
- Avoid loading various modules that aren't needed
- Skip NTP
- Skip AppArmor
- Skip disk detection ( we know where it is being installed to )
- Only run initramfs once at the end
- Unpack debootstrap packages concurrently while extracting the previous ones
- Limit kernel output ( especially not to a slow com port )
- Avoid CD system completely ( package cache can grab packages out of the installer iso )
- Custom sqlite index of packages on installer iso
- Blacklist packages that make no sense for HyperV ( like bluetooth and wireless )
- Take care to bundle together WMI calls where possible
- Force reboot after unmount and sync after install
- Use a tmpfs for debootstrap install followed by 'cp -a', to speed up postinst
- Use win32 gui and never ever ever touch WinUI. ( I started this whole project using WinUI and ewwwwww )
- AND MORE ;)
There is still more to be done. I'm pretty sure I can get Debian installing in under 60 seconds.
Some ideas:
- Ditch networking entirely and use vmbus for ring buffer based mass data transfer ( ~8 seconds saved )
- Ditch stock install of packages by d-i in favor of custom code ( ~5-10 seconds saved )
- Rewrite a bunch of old Debian perl junk in C ( ~1-2 seconds saved )
- Replace installed system kernel with UKI to avoid initramfs ( ~4 seconds saved )
- Hackishly disable unneeded bits of installer kernel ( ~200ms saved )
- Ditch manpages, docs, licenses, copyright notices, etc ( ~2-3 seconds saved )
- Don't boot an installer at all. Native Windows write of installed system ( could reduce install to 20s imo ) This would problematically require writing native implementations of postinst of all the packages used though which I don't want to do.
- Have package cache decompress and recompress in a way that can be decompressed faster ( ~2 seconds saved )
- Have the install running while you are answering UI questions ( making it seem like 0 install time ) This would work fairly easily but wouldn't help with automated installs from a config file, and doesn't seem worth it to me. I want it fast, but 1 minute is fine.
Other people I guess are fine with 5 minute install.
Not me. :D
You may still be asking yourself "But why!?"
Well, you see, I wanted to mess around with having standard Debian Hype-RV instances still use WSLg but without WSL2, because, well, I fucking hate WSL.
Teaser: 77 seconds is awfully slow ;)