Skip to content

Commit

Permalink
Merge pull request clearcontainers#35 from jcvenegas/install
Browse files Browse the repository at this point in the history
Makefile: install kernel and image for CC 3.0
  • Loading branch information
jodh-intel authored Sep 29, 2017
2 parents ddf8570 + 3d01dea commit 54069e1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
63 changes: 62 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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:"
Expand Down Expand Up @@ -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))"

9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54069e1

Please sign in to comment.