hyperhq / hyperstart

The tiny Init service for HyperContainer
https://www.hypercontainer.io
Apache License 2.0
134 stars 63 forks source link

how to build a local kernel #352

Open telala opened 6 years ago

telala commented 6 years ago

I am using runv and need to use my own kernel for the vm rather than the default one of hyperstart. Then I tried to build my own kernel using hyperstart.

  1. run "make kernel-local" under hyperstart/build, then based on Dockerfile.x86_64, a kernel of 4.12.4 will be created
  2. run "make initrd-local" under hyperstart/build to create the initrd
  3. copy kernel and initrd to /var/lib/hyper

Is this the right way to build local kernel?

bergwolf commented 6 years ago

@telala yes that is the right way. And it depends on hyperd to build the kernel. If you do not have that installed locally, you can change hyperctl to docker in https://github.com/hyperhq/hyperstart/blob/master/build/Makefile.am, and run ./autogen.sh and ./configure to create a Makefile that uses docker instead.

telala commented 6 years ago

@bergwolf got a lot of errors while compiling the kernel while running "make kernel-local". But I can compile the kernel successfully by myself locally.

I changed the dockerfile.x8664 a little as following:

FROM centos:latest MAINTAINER Hyper Developers dev@hyper.sh

RUN yum install -y gcc ncurses-devel make openssl-devel bc perl

ENV KERNEL_VERSION 4.12.4 ENV LOCALVERSION -hyper ENV KERNEL_RELEASE ${KERNEL_VERSION}${LOCALVERSION}

ENV KBUILD_BUILD_USER dev ENV KBUILD_BUILD_HOST hyper.sh ENV KBUILD_BUILD_VERSION 1

RUN mkdir /root/build/ && mkdir /root/build/result/

RUN curl -fSL https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${KERNEL_VERSION}.tar.gz | tar -zx -C /root/build

COPY tkernel2 /root/build/tkernel2

COPY kernel_config /root/build/linux-${KERNEL_VERSION}/.config

COPY kernel_patch/ /root/build/kernel_patch/

RUN cd /root/build/linux-${KERNEL_VERSION}/ && for patch in /root/build/kernel_patch/*.patch; do patch -p1 <$patch || exit 1; done

RUN cd /root/build/tkernel2/ && make -j 8 .........

_

following is the compiling errors:

{standard input}: hAssembler messages: {standard input}:37434: Warning: end of file not at end of a line; newline inserted U{standard input}: Error: open CFI at the end of file; missing .cfi_endproc directive 3gcc: internal compiler error: Killed (program cc1) JPlease submit a full bug report, with preprocessed source if appropriate. <See http://bugzilla.redhat.com/bugzilla for instructions. _make[3]: [drivers/scsi/bfa/bfa_ioc.o] Error 4 make[3]: Waiting for unfinished jobs.... make:  [net] Error 2  make[2]: _ [drivers/scsi/bfa] Error 2 make[1]: [drivers/scsi] Error 2 make: [drivers] Error 2 hyperctl ERROR: The container '4c7588c1312ac9657808957d513e2e24deef34559e9bfa33a34309d039d51c7d' returned a non-zero code: 2 make: *** [kernel-local] Error 255

there are a lot of compiling errors besides the above. Are there any advise?

bergwolf commented 6 years ago

gcc: internal compiler error: Killed (program cc1)

@telala it looks like gcc got oom-killed. Are you using hyperd to build? You might want to try docker instead. I've given the instructions to use docker to build in the last comment

telala commented 6 years ago

@bergwolf after replace hyperctl to docker I can build the kernel and initrd successfully. I noticed that a modules.tar file is created too. How to use the modules.tar?

bergwolf commented 6 years ago

@telala module.tar is included in the initrd file created by make initrd-local.

telala commented 6 years ago

@bergwolf when using the built local kernel to start a container got error: Log file created at: 2018/04/11 19:03:24 Running on machine: localhost Binary: Built with gc go1.8.3 for linux/amd64 Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg E0411 19:03:24.663745 29753 hyperstart.go:410] read tty data failed E0411 19:03:24.664397 29753 hyperstart.go:467] SB[vm-mxBHsSjTaJ] tty socket closed, quit the reading goroutine: EOF E0411 19:03:24.664491 29753 hyperstart.go:150] read init data failed E0411 19:03:24.664531 29753 hyperstart.go:184] SB[vm-mxBHsSjTaJ] error when readVmMessage() for ready message: EOF

any advice?

bergwolf commented 6 years ago

@telala are you able to run with the kernel and initrd in hyperstart w/o modification? If you can, I'd suspect your kernel config options.

telala commented 6 years ago

@bergwolf yes. I just tried to use the original initrd and kernel to start runv it worked.

bergwolf commented 6 years ago

@telala There are certain kernel config options required for the hyperstart guest to boot. Please try to use the kernel config in hyperstart and enable other options you need in your kernel.

telala commented 6 years ago

@bergwolf I tried to use the default kernel 4.12.4 in the Dockerfile and it worked. The local kernel can be started successfully by runv. It should be the kernel config problem. Thanks very much : )