godarch / darch

A tool for building and booting stateless and immutable images, bare metal.
https://godarch.com/
MIT License
832 stars 32 forks source link

Add ability to network boot #37

Open kvaps opened 5 years ago

kvaps commented 5 years ago

Hi @pauldotknopf,

You have started really interesting project! I would like to use it for organize network booting.

I want build stateless bare-metal images with all needed software installed, something like I do with LTSP right now. Read more in my article about use cases:

Client side

My idea is to use darch to build ready images and boot them directly via network If I understood it right, it's it is not possible for now. At least because it is requires darch_rootfs parameter.

Any way it would be nice to add support to work without this parameter, and some extra option to client for render vmlinuz and initrd files without installing into grub on current system.

Server side

I think this feature can be implemented directly with the same grub2, it have all necessary modules for PXE-booting, it also can download over HTTP and supports EFI-systems. Grub is working fine and I glad to use it with LTSP.

On the other hand the second option might be much more interesting. Not so long ago I've found another cool project: pixiecore - it allows you to simple organize network booting environment without any additional configuration. Eg. you don't need to change existing dhcp-servers configuration, configure bootloaders and etc. You just need to run pixieboot binary with providing vmlinuz, initrd and cmdline parameters, and then all machines will be booted into it, that's really amazing, and it would be really nice to integrate it with darch.

Thanks for attention, I would really like to hear your thoughts on this idea.

pauldotknopf commented 5 years ago

Thanks for your interest.

Some comments:

3 files are needed for a boot with Darch.

  1. vmlinux
  2. initrd (with custom initramfs scripts)
  3. rootfs.squash

The darch_rootfs parameter is used by godarch/darch-initramfs-tools from initrd to find the rootfs.squash file.

All 3 of these files must be paired together.

So here are your options.

  1. Move vmlinux and initrd to a network location and get a machine to PXE boot. I haven't done this personally.
  2. Put the rootfs.squash somewhere on the network as well. Update the initrd to download rootfs.squash from the web, instead of using darch_rootfs (easy to do here).

That should be all.

However, I want to make some things clear.

The majority functionality of the darch command is to make it easy to stage images for grub booting, and updating grub. In your case, you'd be just using it to build images, but that could also easily be done with docker and Dockerfiles.

Take a look at our base images on Docker Hub (here). Maybe you'd want to just use docker. You'd have to have your own script that extracts /boot/vmlinux and /boot/initrd from your built images, and extract the entire image into a rootfs.squash. At this point, you'd have all the pieces needed to setup our PXE environment.

With that said, I'd love to support a darch stage upload to a PXE-ready environment.

kvaps commented 5 years ago

So all we need is just to teach initramfs darch script to download rootfs.squash over network, And then we can use simple command to distribute it:

pixiecore boot vmlinuz-linux initramfs-linux.img  --cmdline='darch_rootfs={{ ID "rootfs.squash" }}'

Sounds super easy! I'll try to implement it.

pauldotknopf commented 5 years ago

Great! Keep me updated.

kvaps commented 5 years ago

Ok, first PR is ready, now network booting is working fine: https://github.com/godarch/darch-initramfs-tools/pull/1

Now we should decide what to do with darch_dir and hooks itself, I'd like to pack them as tarball archive and send them from the same http server, what do you think about it?

pauldotknopf commented 5 years ago

That's a good question.

I envisioned hooks being used to "localized" (machine name, static ip, etc) a generic image to a specific machine.

Would you use hooks similarly? Where would you store them? For an individual machine?

kvaps commented 5 years ago

Well, for now I use LTSP and I like how hooks are organized there.

All hooks there are part of init-ltsp system:

One of first hook (05-getltsconffile) is downloading lts.conf file - it is main configuration file which contain variables used by all other hooks.

All hooks there are stored directly in squashed rootfs image. And can be updated only with whole squashed image itself.

In practice, I can say that this approach is not very convenient. Yes, we can to store main configuration separated from the image, but I'd like to move the hooks outside image too.

BTW, I like idea with darch_dir, I'm just not understand why do you mount it as root? What should exactly be stored there except hooks? If it is needed only for hooks, I'd like to pack them and distribute as tarball.

kvaps commented 5 years ago

Alpine linux uses similar logic for booting their apkovl files with the /etc configuration: https://wiki.alpinelinux.org/wiki/PXE_boot#Guide_to_options