Commit 54a235cc authored by Martin Peres's avatar Martin Peres
Browse files

initscript: allow running multiple containers, one after the other

This enables create a chain of containers to run.
parent b6459e85
......@@ -24,7 +24,7 @@ rebuild_container:
test: out/initramfs.linux_amd64.cpio
[ -f "$(KERNEL)" ] || (echo "ERROR: Set the KERNEL parameter, pointing to linux kernel with modules compiled in"; exit 1)
[ -f out/disk.img ] || fallocate -l 128M out/disk.img
qemu-system-x86_64 -drive file=out/disk.img,format=raw,if=virtio -nic user,model=virtio-net-pci -kernel $(KERNEL) -initrd out/initramfs.linux_amd64.cpio -nographic -m 256M -enable-kvm -append "console=ttyS0 b2c.container=docker:// b2c.cache_device=auto"
qemu-system-x86_64 -drive file=out/disk.img,format=raw,if=virtio -nic user,model=virtio-net-pci -kernel $(KERNEL) -initrd out/initramfs.linux_amd64.cpio -nographic -m 256M -enable-kvm -append 'console=ttyS0 b2c.container=docker:// b2c.container="-ti docker://" b2c.cache_device=auto'
-rm out/initramfs.linux_amd64.cpio
......@@ -46,7 +46,11 @@ that needs to be executed. In `grub.cfg`, this could look like this:
Here is a list of options:
* b2c.container: Name of the container that should be executed at boot. Format: See [podman's image format]( Examples:
* b2c.container: Command line of a container to be executed at boot.
  • I think this interface would look nicer if b2c.container would take a delimiter-separated list of containers to run, rather than having to specify it multiple times. I tend to think later parameters override earlier ones from my experience with other tools, I guess YMMV :). Same for post containers and such.

  • Yeah, that could be a good idea, but ... what delimiter should be used?

  • Anything that works, hopefully a comma or a space :)

  • Space and commas can be used as part of a docker command line (remember, b2c.container="-ti alpine:latest /bin/sh" is valid) :s

  • Oh, I didn't realise the interface was that general, in this case, I withdraw my suggestion :)

  • Yeah, I made it very open, so as to even allow sharing data between containers by using -v :D

Please register or sign in to reply
Format: See [podman's image format](
If you set this parameter multiple times, the containers will be executed one
after the other, in the same order as they are specified, as long as the
containers exit with the error code 0. Examples:
* b2c.container=docker://
* b2c.container="-ti docker:// /bin/sh"
* b2c.cache_device: Use a cache to store the image layers, thus saving on network usage:
......@@ -69,7 +69,7 @@ function parse_cmdline {
......@@ -259,8 +259,34 @@ function start_container {
create_container $@ || return 1
log "Start the container"
# HACK: Figure out how to use "podman wait" to wait for the container to be
# ready for execution. Without this sleep, we sometimes fail to attach the
# stdout/err to the container. Even a one ms sleep is sufficient in my
# testing, but let's add a bit more just to be sure
sleep .1
log "About to start executing a container"
podman start -a "$container_id"
return $?
function start_containers {
for container_params in $(echo -e "$@"); do
start_container "$container_params"
if [ $exit_code -eq 0 ] ; then
log "The container run successfully, load the next one!"
log "The container exited with error code $?, aborting..."
return 1
return 0
# Do not print all the early commands
......@@ -288,8 +314,8 @@ mount_cache_partition
# Start the container
start_container $ARG_CONTAINER
start_containers "$ARG_CONTAINER"
# Emergency shell
log "Done executing the container, dropping to an emergency shell"
log "Done executing the containers, dropping to an emergency shell"
exec /bin/busybox sh
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment