Skip to content

Commit

Permalink
Merge pull request #701 from amazonlinux/kernel
Browse files Browse the repository at this point in the history
kernel: Create kernel-devel squashfs and bind into host containers
  • Loading branch information
sam-aws authored Feb 7, 2020
2 parents 5f2105c + 9225bdf commit 9f52acf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions macros/shared
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
%_cross_sysusersdir %{_cross_rootdir}%{_sysusersdir}
%_cross_sysctldir %{_cross_rootdir}%{_sysctldir}
%_cross_templatedir %{_cross_datadir}/templates
%_cross_usrsrc %{_cross_prefix}/src
%_cross_licensedir %{_cross_datadir}/licenses
%_defaultlicensedir %{_cross_licensedir}

Expand Down
22 changes: 16 additions & 6 deletions packages/kernel/kernel.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ BuildRequires: hostname
BuildRequires: kmod
BuildRequires: openssl-devel

%global kernel_sourcedir %{_usrsrc}/kernels/%{version}
%global kernel_sourcedir %{_cross_usrsrc}/kernels
%global kernel_libdir %{_cross_libdir}/modules/%{version}

%description
%{summary}.
Expand Down Expand Up @@ -113,11 +114,21 @@ find %{buildroot}%{_cross_prefix} \
# remove x86 intermediate files like generated/asm/.syscalls_32.h.cmd
sed -i '/asm\/.*\.cmd$/d' kernel_devel_files

install -d %{buildroot}%{kernel_sourcedir}
## Create squashfs of kernel-devel files (ie. /usr/src/kernels/<version>)
mkdir src_squashfs
for file in $(cat kernel_devel_files); do
install -D ${file} %{buildroot}%{kernel_sourcedir}/${file}

install -D ${file} src_squashfs/%{version}/${file}
done
mksquashfs src_squashfs kernel-devel.squashfs
install -D kernel-devel.squashfs %{buildroot}%{_cross_datadir}/thar/kernel-devel.squashfs
install -d %{buildroot}%{kernel_sourcedir}

# Replace the incorrect links from modules_install. These will be bound
# into a host container (and unused in the host) so they must not point
# to %{_cross_usrsrc} (eg. /x86_64-thar-linux-gnu/sys-root/...)
rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source

%files
%license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note
Expand Down Expand Up @@ -156,7 +167,6 @@ done

%files devel
%dir %{kernel_sourcedir}
%{kernel_sourcedir}/*
%{kernel_sourcedir}/.config
%{_cross_datadir}/thar/kernel-devel.squashfs

%changelog
7 changes: 7 additions & 0 deletions packages/release/release.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Source1002: configured.target
Source1006: prepare-local.service
Source1007: var.mount
Source1008: opt.mount
Source1009: usr-src-kernels.mount.in
Source1010: var-lib-thar.mount

BuildArch: noarch
Expand All @@ -38,6 +39,7 @@ Requires: %{_cross_os}grub
Requires: %{_cross_os}iproute
Requires: %{_cross_os}kernel
Requires: %{_cross_os}kernel-modules
Requires: %{_cross_os}kernel-devel
Requires: %{_cross_os}bork
Requires: %{_cross_os}moondog
Requires: %{_cross_os}schnauzer
Expand Down Expand Up @@ -83,6 +85,10 @@ EOF

install -d %{buildroot}%{_cross_unitdir}
install -p -m 0644 %{S:1002} %{S:1006} %{S:1007} %{S:1008} %{S:1010} %{buildroot}%{_cross_unitdir}
# Mounting on usr/src/kernels requires using the real path: %{_cross_usrsrc}/kernels
KERNELPATH=$(systemd-escape --path %{_cross_usrsrc}/kernels)
sed -e 's|PREFIX|%{_cross_prefix}|' %{S:1009} > ${KERNELPATH}.mount
install -p -m 0644 ${KERNELPATH}.mount %{buildroot}%{_cross_unitdir}

install -d %{buildroot}%{_cross_templatedir}
install -p -m 0644 %{S:200} %{buildroot}%{_cross_templatedir}/hostname
Expand All @@ -98,6 +104,7 @@ install -p -m 0644 %{S:200} %{buildroot}%{_cross_templatedir}/hostname
%{_cross_unitdir}/prepare-local.service
%{_cross_unitdir}/var.mount
%{_cross_unitdir}/opt.mount
%{_cross_unitdir}/*-kernels.mount
%{_cross_unitdir}/var-lib-thar.mount
%dir %{_cross_templatedir}
%{_cross_templatedir}/hostname
Expand Down
13 changes: 13 additions & 0 deletions packages/release/usr-src-kernels.mount.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Kernel Development Sources
Conflicts=umount.target
Before=local-fs.target umount.target

[Mount]
What=PREFIX/share/thar/kernel-devel.squashfs
Where=PREFIX/src/kernels
Type=squashfs
Options=defaults,ro,loop

[Install]
WantedBy=local-fs.target
10 changes: 10 additions & 0 deletions workspaces/host-ctr/cmd/host-ctr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ func withSuperpowered(superpowered bool) oci.SpecOpts {
Options: []string{"rbind", "ro"},
Destination: "/.thar/rootfs",
Source: "/",
},
{
Options: []string{"rbind", "ro"},
Destination: "/lib/modules",
Source: "/lib/modules",
},
{
Options: []string{"rbind", "ro"},
Destination: "/usr/src/kernels",
Source: "/usr/src/kernels",
}}),
)
}
Expand Down

0 comments on commit 9f52acf

Please sign in to comment.