initramfs-wrap icon indicating copy to clipboard operation
initramfs-wrap copied to clipboard

Investigate using qemu-system instead of qemu-user

Open mephi42 opened this issue 4 years ago • 0 comments

Pros:

  • Reduce the usage of the complicated fakechroot/fakeroot/debootstrap combo

Cons:

  • Dependency on externally available kernels, or having to build our own
    • Network support is not needed though - downloads would still be handled by debootstrap stage1
  • Install process has to somehow exchange commands and files with the VM.

In order to avoid depending on network and 9p, interaction will have to go purely through tty. This means that at the end, / will be archived and printed. For this either tty has to put into the dumbest mode possible, or the archive bust be base64ed.

Sequence:

  • Download a kernel for the respective arch, cache it in ~/.cache/initramfs-wrap/vmlinux-$ARCH
  • Run debootstrap stage1 under fakeroot
  • Generate minichroot containing only sh and tar (non-stripped chroot won't fit into 256MB during boot). Throw in base64 and gzip if necessary.
  • Generate and add the installer script (can be python if desired, put it into /install)
  • Strip what can be stripped without running anything
  • tar the result, compression may or may not be beneficial - make an experiment
  • Start the VM using rdinit=/bin/sh -- -c "tar -x && exec /install" and pipe tar archive to stdin
  • Echo VM output line by line until it prints a magic sequence
    • This will be done by something like echo $MAGIC; tar -c / | base64; echo $MAGIC in the installer script, so it would be impossible to know the size in advance
  • Wait until the next magic sequence, save everything in between
  • Profit

mephi42 avatar May 04 '20 12:05 mephi42