diff --git a/Makefile b/Makefile index 9085163..f2de652 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,31 @@ MK_DIR :=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) OS_BUILDER ?= $(MK_DIR)/scripts/osbuilder.sh +# Installation variables +DESTDIR := +SYSCONFDIR := /etc +CONFIG_FILE = configuration.toml +DESTDIR := +DEFAULTSDIR := /usr/share/defaults +CCDIR := clear-containers +IMAGE := $(WORKDIR)/container.img +VMLINUX := $(WORKDIR)/vmlinux.container +VMLINUZ := $(WORKDIR)/vmlinuz.container + +DESTCONFDIR := $(abspath $(DESTDIR)/$(DEFAULTSDIR)/$(CCDIR)) +DESTSYSCONFDIR := $(abspath $(DESTDIR)/$(SYSCONFDIR)/$(CCDIR)) + +# Main configuration file location for stateless systems +DESTCONFIG := $(abspath $(DESTCONFDIR)/$(CONFIG_FILE)) + +# Secondary configuration file location. Note that this takes precedence +# over DESTCONFIG. +DESTSYSCONFIG := $(abspath $(DESTSYSCONFDIR)/$(CONFIG_FILE)) + +IMAGE_DEST := $(abspath $(DESTSYSCONFDIR)/osbuilder.img) +VMLINUX_DEST := $(abspath $(DESTSYSCONFDIR)/osbuilder-vmlinux) +VMLINUZ_DEST := $(abspath $(DESTSYSCONFDIR)/osbuilder-vmlinuz) + ifdef USE_DOCKER DOCKER_DEPS += docker-build OS_BUILDER = docker run \ @@ -96,6 +121,31 @@ else @$(call check_program,git) endif + +install-image: $(IMAGE) $(DEFAULT_RUNTIME_CONFIG) $(DESTSYSCONFIG) + install -D --owner root --group root --mode 0644 "$(IMAGE)" "$(IMAGE_DEST)" + @echo Adding $(IMAGE_DEST) to configuration. + @sed -i.bak -e 's!^\(image = ".*"\)!# \1\nimage = "$(IMAGE_DEST)"!g' \ + $(DESTSYSCONFIG) + +get-machine-type: $(DESTSYSCONFIG) + @echo Checking machine type ... + $(eval MACHINE_TYPE=$(shell grep -P "^machine_type\s*=\s*" $(DESTSYSCONFIG) | grep -oP '"\K.*(?=")') ) + @echo Machine type is $(MACHINE_TYPE) + +install-kernel: $(VMLINUZ) $(VMLINUX) $(DESTSYSCONFIG) get-machine-type + install -D --owner root --group root --mode 0644 $(VMLINUX) $(VMLINUX_DEST) + install -D --owner root --group root --mode 0644 $(VMLINUZ) $(VMLINUZ_DEST) + @echo Configured to use machine type \"$(MACHINE_TYPE)\" using kernel $(KERNEL_PATH) + @sed -i -e 's!^\(kernel = ".*"\)!# \1\nkernel= "$(KERNEL_PATH)"!g' \ + $(DESTSYSCONFIG) + +$(DESTSYSCONFIG): $(DESTCONFIG) + mkdir -p $(DESTSYSCONFDIR) + @echo Generating $(DESTSYSCONFIG) from $(DESTCONFIG) + @echo "# XXX: WARNING: this config was generated by osbuilder on $$(date) from $(DESTCONFIG)" > $(DESTSYSCONFIG) + @cat $(DESTCONFIG) >> $(DESTSYSCONFIG) + help: @echo "Usage:" @echo "osbuilder Makefile provides the targets:" @@ -129,5 +179,16 @@ help: @echo "kernel: compiles the kernel source from the directory WORKDIR/linux. To get" @echo " the latest kernel use 'make kernel-src'" @echo "clean: removes the directory WORKDIR" - + @echo "" + @echo "install-kernel: install kernel created by the 'kernel' target in " + @echo " VMLINUX_DEST (default: $(VMLINUX_DEST)) and" + @echo " VMLINUZ_DEST (default: $(VMLINUX_DEST))." + @echo " Also, the kernel path is added to runtime config file DESTSYSCONFIG" + @echo " (default: $(DESTSYSCONFIG)), the kernel to be configured will depend" + @echo " in the machine type defined in DESTSYSCONFIG, vmlinux for" + @echo " pc-lite, otherwise vmlinuz." + @echo "" + @echo "install-image: install image created by the 'image' target in " + @echo " VMLINUX_DEST (default: $(VMLINUX_DEST)) and also adds the image to runtime config" + @echo " file DESTSYSCONFIG (default: $(DESTSYSCONFIG))" diff --git a/README.md b/README.md index 79383be..719f7c6 100644 --- a/README.md +++ b/README.md @@ -140,15 +140,14 @@ This section covers using the new resources with `cc-runtime`. #### Installing the new kernel -1. Install the kernel image +1. Install the kernel image (run `make help` for more information) ``` - $ sudo install --owner root --group root --mode 0755 workdir/vmlinuz.container /usr/share/clear-containers/custom-vmlinuz - $ sudo install --owner root --group root --mode 0755 workdir/vmlinux.container /usr/share/clear-containers/custom-vmlinux + $ sudo make install-kernel ``` -1. Update the runtime configuration for the kernel +1. Verify kernel is configured ``` - $ sudo sed -i.bak -e 's!^\(kernel = ".*"\)!# \1\nkernel = "/usr/share/clear-containers/custom-vmlinuz"!g' /usr/share/defaults/clear-containers/configuration.toml + $ cc-runtime cc-env ``` ### Clear Containers 2.x