Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Add option to pick an existing bzImage #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ found under
* `/lib/modules/$(uname -r)/include` for the kernel API headers
* `/lib/modules/$(uname -r)/source/include` for the kernel headers

A pre-built bzImage can also be used:
```
S1B_KERNEL_VERSION=4.15.0 S1B_KERNEL_PICK_BZIMAGE=$HOME/git/linux/bzImage-4.15-rkt ./builder
```

Note: at the time of writing, you have to pre-fetch all stage1 dependencies
manually due to https://github.com/coreos/rkt/issues/2241
This is can be done as follows (the version must match
Expand Down
97 changes: 53 additions & 44 deletions builder
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ readonly busybox_mkdir_url="https://busybox.net/downloads/binaries/1.26.2-i686/b

readonly mk="$(which make) -j${S1B_JOBS}"

kernel_config="${dir}/config/linux-${kernel_version}.config"
if [[ ! -f "${kernel_config}" ]]; then
kernel_config="${dir}/config/linux-${kernel_version_minor}.config"
if [[ -z ${S1B_KERNEL_PICK_BZIMAGE} ]]; then
kernel_config="${dir}/config/linux-${kernel_version}.config"
if [[ ! -f "${kernel_config}" ]]; then
echo "couldn't find config for kernel ${kernel_version} or ${kernel_version_minor} in ${dir}/config - aborting" >&2
exit 1
kernel_config="${dir}/config/linux-${kernel_version_minor}.config"
if [[ ! -f "${kernel_config}" ]]; then
echo "couldn't find config for kernel ${kernel_version} or ${kernel_version_minor} in ${dir}/config - aborting" >&2
exit 1
fi
fi
fi

Expand All @@ -71,55 +73,62 @@ test -f "${target_aci}" && {
exit 0
}

# download kernel
test -f "${kernel_dir}/kernel.tar.xz" || curl -LsS "${kernel_url}" -o "${kernel_dir}/kernel.tar.xz"
if [[ -z ${S1B_KERNEL_PICK_BZIMAGE} ]]; then

# unpack kernel
test "$(find "${kernel_source_dir}" -maxdepth 0 -type d -empty 2>/dev/null)" && tar -C "${kernel_source_dir}" --strip-components=1 -xf "${kernel_dir}/kernel.tar.xz"
# download kernel
test -f "${kernel_dir}/kernel.tar.xz" || curl -LsS "${kernel_url}" -o "${kernel_dir}/kernel.tar.xz"

# configure kernel
test -f "${kernel_source_dir}/.config" || sed -e "s/-rkt-v1/${kernel_version_suffix}/g" "${kernel_config}" >"${kernel_source_dir}/.config"
# unpack kernel
test "$(find "${kernel_source_dir}" -maxdepth 0 -type d -empty 2>/dev/null)" && tar -C "${kernel_source_dir}" --strip-components=1 -xf "${kernel_dir}/kernel.tar.xz"

# build kernel
test -f "${kernel_bzimage}" ||
(
cd "${kernel_source_dir}"
curl -LsS "${kernel_reboot_patch_url}" -O
# TODO(schu) fails when patch was applied already
patch --silent -p1 < $(basename "${kernel_reboot_patch_url}")
for patch_url in ${S1B_EXTRA_KERNEL_PATCH_URLS} ; do
curl -LsS "${patch_url}" -O
patch --silent -p1 < $(basename "${patch_url}")
done
for patch_file in ${S1B_EXTRA_KERNEL_PATCH_FILES} ; do
patch --silent -p1 < "${patch_file}"
done
${mk} bzImage
)
# configure kernel
test -f "${kernel_source_dir}/.config" || sed -e "s/-rkt-v1/${kernel_version_suffix}/g" "${kernel_config}" >"${kernel_source_dir}/.config"

# import kernel
rsync -a "${kernel_bzimage}" "${rootfs_dir}/bzImage"
# build kernel
test -f "${kernel_bzimage}" ||
(
cd "${kernel_source_dir}"
curl -LsS "${kernel_reboot_patch_url}" -O
# TODO(schu) fails when patch was applied already
patch --silent -p1 < $(basename "${kernel_reboot_patch_url}")
for patch_url in ${S1B_EXTRA_KERNEL_PATCH_URLS} ; do
curl -LsS "${patch_url}" -O
patch --silent -p1 < $(basename "${patch_url}")
done
for patch_file in ${S1B_EXTRA_KERNEL_PATCH_FILES} ; do
patch --silent -p1 < "${patch_file}"
done
${mk} bzImage
)

# import kernel header
mkdir -p "${rootfs_dir}/${kernel_header_dir}/include/arch/x86/include"
(
cd "${kernel_source_dir}"
# import kernel
rsync -a "${kernel_bzimage}" "${rootfs_dir}/bzImage"

# install kernel api header
${mk} headers_install INSTALL_HDR_PATH="${rootfs_dir}/${kernel_api_header_dir}" >/dev/null
# import kernel header
mkdir -p "${rootfs_dir}/${kernel_header_dir}/include/arch/x86/include"
(
cd "${kernel_source_dir}"

# loosely following arch for the copied kernel headers
# https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/linux#n158
# install kernel api header
${mk} headers_install INSTALL_HDR_PATH="${rootfs_dir}/${kernel_api_header_dir}" >/dev/null

for i in acpi asm-generic config crypto drm generated keys linux math-emu \
media net pcmcia scsi soc sound trace uapi video xen; do
rsync -a "include/${i}" "${rootfs_dir}/${kernel_header_dir}/include/"
done
# loosely following arch for the copied kernel headers
# https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/linux#n158

rsync -a "arch/x86/include/" "${rootfs_dir}/${kernel_header_dir}/include/arch/x86/include/"
)
for i in acpi asm-generic config crypto drm generated keys linux math-emu \
media net pcmcia scsi soc sound trace uapi video xen; do
rsync -a "include/${i}" "${rootfs_dir}/${kernel_header_dir}/include/"
done

find "${rootfs_dir}/${kernel_header_dir}" \( -name '.install' -or -name '..install.cmd' \) -delete
rsync -a "arch/x86/include/" "${rootfs_dir}/${kernel_header_dir}/include/arch/x86/include/"
)

find "${rootfs_dir}/${kernel_header_dir}" \( -name '.install' -or -name '..install.cmd' \) -delete

else
# import pre-built kernel
rsync -a "${S1B_KERNEL_PICK_BZIMAGE}" "${rootfs_dir}/bzImage"
fi

# add busybox mkdir to stage1
mkdir -p "${rootfs_dir}/usr/bin"
Expand Down
3 changes: 3 additions & 0 deletions builder-config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# The directory to store the built aci files
S1B_OUT_DIR="${S1B_OUT_DIR:-${DIR}/aci-files}"

# Skip compilation and pick this pre-built image
S1B_KERNEL_PICK_BZIMAGE="${S1B_KERNEL_PICK_BZIMAGE:-}"

# The kernel version to build and include
S1B_KERNEL_VERSION="${S1B_KERNEL_VERSION:-"4.11.5"}"

Expand Down
Loading