From b485f729e8ead8339969b44055c1a96fcd255fdd Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Thu, 13 Apr 2017 08:41:38 +0000 Subject: [PATCH] clear-containers: Add script to launch base OS and kernel This commit adds the script qemu.sh that will be used in a docker container (created with Dockerfile). This script will crate qemu instance to lauch a Clear Container base OS with a kernel generated with moby. Signed-off-by: Jose Carlos Venegas Munoz --- projects/clear-containers/README.md | 11 +++++ projects/clear-containers/tools/Dockerfile | 10 +++++ projects/clear-containers/tools/Makefile | 35 ++++++++++++++++ projects/clear-containers/tools/qemu.sh | 49 ++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 projects/clear-containers/tools/Dockerfile create mode 100644 projects/clear-containers/tools/Makefile create mode 100755 projects/clear-containers/tools/qemu.sh diff --git a/projects/clear-containers/README.md b/projects/clear-containers/README.md index fffb76a66..d1904c4b7 100644 --- a/projects/clear-containers/README.md +++ b/projects/clear-containers/README.md @@ -70,6 +70,17 @@ following command: ./bin/moby build ./projects/clear-containers/clear-containers.yml ``` +3. Test kernel + +The Makefile target `qemu-lite` from `projects/clear-containers/tools` +will launch the Clear Containers base OS and the +with kernel built with moby. Use the `root` user to access to the test system, +it will ask to setup a password. + +``` +cd projects/clear-containers/tools +make qemu-lite +``` The file `clear-containers-bzImage` is not a bzImage\*. The file is a vmlinux image, see TODO. The [cc-oci-runtime] project can be diff --git a/projects/clear-containers/tools/Dockerfile b/projects/clear-containers/tools/Dockerfile new file mode 100644 index 000000000..5ffcdcc78 --- /dev/null +++ b/projects/clear-containers/tools/Dockerfile @@ -0,0 +1,10 @@ +FROM fedora:25 + +RUN dnf install -y 'dnf-command(config-manager)' +RUN dnf config-manager --add-repo \ + http://download.opensuse.org/repositories/home:clearlinux:preview:clear-containers-2.1/Fedora\_25/home:clearlinux:preview:clear-containers-2.1.repo + +RUN dnf install -y qemu-lite clear-containers-image linux-container +COPY qemu.sh /bin/qemu.sh +WORKDIR /root +ENTRYPOINT ["qemu.sh"] diff --git a/projects/clear-containers/tools/Makefile b/projects/clear-containers/tools/Makefile new file mode 100644 index 000000000..ada7261e0 --- /dev/null +++ b/projects/clear-containers/tools/Makefile @@ -0,0 +1,35 @@ +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MKFILE_DIR := $(dir $(MKFILE_PATH)) +ifdef http_proxy + BUILD_PROXY = --build-arg http_proxy=$(http_proxy) + RUN_PROXY = --env http_proxy=$(http_proxy) +endif + +ifdef https_proxy + BUILD_PROXY += --build-arg https_proxy=$(https_proxy) + RUN_PROXY += --env https_proxy=$(https_proxy) +endif + +CMDLINE_FILE=clear-containers-cmdline +KERNEL_FILE=clear-containers-bzImage + +IMAGE=qemu-lite + +docker_image: Dockerfile + docker build $(BUILD_PROXY) -t clearcontainers/$(IMAGE) . + +qemu-lite: docker_image $(KERNEL_FILE) $(CMDLINE_FILE) + docker run --privileged --rm -ti \ + -v $$(pwd)/$(CMDLINE_FILE):/root/clear-containers-cmdline \ + -v $$(pwd)/$(KERNEL_FILE):/root/clear-containers-vmlinux \ + clearcontainers/$(IMAGE) \ + bash + +$(KERNEL_FILE): + $(MKFILE_DIR)/../../../bin/moby build $(MKFILE_DIR)/../clear-containers.yml + +push: docker_image + docker push clearcontainers/$(IMAGE) + +clean: + rm -rf *-bzImage *-cmdline *.img diff --git a/projects/clear-containers/tools/qemu.sh b/projects/clear-containers/tools/qemu.sh new file mode 100755 index 000000000..42442903c --- /dev/null +++ b/projects/clear-containers/tools/qemu.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e + +function die { + echo >&2 "$@" + exit 1 +} + +img=/usr/share/clear-containers/clear-containers.img +img=$(readlink -f "$img") +img_size=$(du -b "${img}" | awk '{print $1}') + +kernel="$(pwd)/clear-containers-vmlinux" +kernel_cmdline_file="$(pwd)/clear-containers-cmdline" +[ -f "${img}" ] || die "Image s required" +[ -f "${kernel}" ] || die "Kernel is required" +[ -f ${kernel_cmdline_file} ] || \ + die "Kernel cmdline file is required" + +kernel_cmdline=$(cat "$kernel_cmdline_file") + +cmd="/usr/bin/qemu-lite-system-x86_64" +cmd="$cmd -machine pc-lite,accel=kvm,kernel_irqchip,nvdimm" +cmd="$cmd -device nvdimm,memdev=mem0,id=nv0" +#image +cmd="$cmd -object memory-backend-file,id=mem0,mem-path=${img},size=${img_size}" +#memory +cmd="$cmd -m 2G,slots=2,maxmem=3G" +#kernel +cmd="$cmd -kernel ${kernel}" +cmd="$cmd -append '${kernel_cmdline}'" +#cpu +cmd="$cmd -smp 2,sockets=1,cores=2,threads=1" +cmd="$cmd -cpu host" +#clock +cmd="$cmd -rtc base=utc,driftfix=slew" +cmd="$cmd -no-user-config" +cmd="$cmd -nodefaults" +cmd="$cmd -global" +cmd="$cmd kvm-pit.lost_tick_policy=discard" +#console +cmd="$cmd -device virtio-serial-pci,id=virtio-serial0" +cmd="$cmd -chardev stdio,id=charconsole0,signal=off" +cmd="$cmd -device virtconsole,chardev=charconsole0,id=console0" +cmd="$cmd -nographic" +cmd="$cmd -vga none" + +eval "$cmd"