Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: Create kernel-devel squashfs and bind into host containers #701

Merged
merged 2 commits into from
Feb 7, 2020
Merged
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
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}netdog
Expand Down Expand Up @@ -84,6 +86,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 @@ -99,6 +105,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