]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
master: Install kernel and create an initramdisk
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 May 2021 15:41:40 +0000 (15:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 May 2021 15:41:40 +0000 (15:41 +0000)
The initramdisk is very minimal and will only come with some basic
kernel modules as well as scripts to mount the squashfs and jump into
it.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/bricklayer-master

index 9f4908f2a5bc92330504fb09947e566363bcf985..b2918c87cd4e2150c092ac22530bcec7dcb3207c 100644 (file)
@@ -25,6 +25,7 @@ PAKFIRE_CONFIG="/etc/pakfire/distros/ipfire3.conf"
 # Packages to install in the live system
 PACKAGES=(
        "@Base"
+       "dracut"
        "kernel"
 )
 
@@ -32,6 +33,7 @@ BUILDSYSTEM_PACKAGES=(
        "@Base"
        "dracut"
        "grub"
+       "dmsetup"
 )
 
 # Compress as best as we can
@@ -201,6 +203,60 @@ make_grub_efi_image() {
        return 0
 }
 
+find_kernel_release() {
+       local file
+       for file in ${buildsystem}/usr/lib/modules/*; do
+               if [ -d "${file}" ]; then
+                       basename "${file}"
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
+install_kernel_image() {
+       local filename="${1}"
+
+       # Find kernel release
+       local kernel_release="$(find_kernel_release)"
+
+       cp "${buildsystem}/boot/vmlinuz-${kernel_release}" "${filename}"
+}
+
+install_initramfs() {
+       local filename="${1}"
+
+       # Find kernel release
+       local kernel_release="$(find_kernel_release)"
+
+       local args=(
+               --verbose
+
+               # Generate a ramdisk that can run on many hosts
+               --no-hostonly
+
+               --kmoddir "/usr/lib/modules/${kernel_release}"
+
+               # Add the live image module to mount our squashfs system
+               --add "dmsquash-live"
+
+               # Only enable these modules
+               --modules "base kernel-modules"
+
+               # Add support for squashfs
+               --filesystems "squashfs"
+       )
+
+       if ! in_buildsystem --bind="${tempdir}" \
+                       dracut "${args[@]}" "${filename}" "${kernel_release}" &>/tmp/dracut.$$; then
+               unlink "${filename}"
+               return 1
+       fi
+
+       return 0
+}
+
 mkimage() {
        local filename="${1}"
        local r=0
@@ -293,6 +349,18 @@ mkimage() {
                )
        fi
 
+       # Install the kernel image
+       if ! install_kernel_image "${tempdir}/boot/vmlinuz"; then
+               rm rf "${tempdir}"
+               return 1
+       fi
+
+       # Create live ramdisk
+       if ! install_initramfs "${tempdir}/boot/initramfs.img"; then
+               rm -rf "${tempdir}"
+               return 1
+       fi
+
        # Create the live system image
        if ! make_live_system_image "${tempdir}/live-os.img"; then
                rm -rf "${tempdir}"