LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-07-2022, 02:37 PM   #1
lostintime
Member
 
Registered: Dec 2021
Posts: 201

Rep: Reputation: Disabled
Installing the /patches kernel during installation


Kind of a chicken-and-egg problem.

I am looking for tutorials about installing patches during installation. Or tutorials about remastering a stable release ISO image that uses a newer kernel from /patches.

If the stable release ISO kernel boots then a newer /patches kernel could be installed before rebooting by chrooting after the installer completes.

That approach would not help if the installer fails to boot with the ISO version of the kernel. Seems in that case the remedy is remastering the ISO with the kernel from /patches.

Traditional advice is to use Current, but that approach does not help a user who wants to remain with the stable branch and only needs the newer patched kernel.

Thanks.
 
Old 06-08-2022, 12:45 AM   #2
henca
Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 992

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
I have done all this a long time ago, but my solution is not suitable for a quick tutorial for updating the kernel in a standard Slackware installation. My solution is a heavily modified Slackware installation where a custom kernel is only a small part of all those modifications.

First of all, my installation isos are created using a custom Makefile. The same Makefile builds .iso-files both for CDROM usable for NFS installation and DVD usable for standalone installation.

The standard Slackware installation media has a directory called kernels. That directory contains sub-directories called things like huge.s which contian those kernel configuration files together with the built kernels and a System.map. I keep that directory structure, but might add more directories than huge.s with different config-files and my Makefile scans those directories to create a isolinux/isolinux.cfg making all those kernels choosable at installation. It also updates grub on the iso image to make all kernels bootable also with EFI.

Next to the kernels directories I have added a directory which I call kernel_and_patches. In that directory I put the compressed kernel source file together with a number of patches and two text-files. One textfile describes the purpose of each patch file and goes into the Slackware package description of the kernel package. The other text file lists which modules has been patched and is being used to create a Slackware package with updated kernel modules.

My Makefile unpacks the kernel source, applies all patches and builds one kernel for each config file below the kernels directory and places the bzImage and System.map in that directory structure. The built kernels are also placed in packages which can be used to update existing installations and those packages have scripts to rerun lilo or install for extlinux if EFI is being used. Also a package for the modules affected by the patches are built and that package is used both to update existing installations and installed when using the installation media.

The isolinux/initrd.img has been heavily modified, mostly with the purpose to minimize questions during installation. The installation scripts also makes sure that the same kernel that was choosen during installation is the one being used after installation. Those installation scripts in initrd.img work together with custom setup scripts from a custom package, once again to avoid questions at the end of installation. The custom script for the boot will at the end of the installation install the custom patched kernel together using lilo for MBR boot or extlinux for EFI.

Posting the Makefile here might be partly useful, but much of the magic is done in the customized initrd.img and those setup scripts. Please let me know if you want me to post my custom Makefile.

regards Henrik
 
Old 06-08-2022, 11:07 AM   #3
lostintime
Member
 
Registered: Dec 2021
Posts: 201

Original Poster
Rep: Reputation: Disabled
Thank you for replying. What you described is the basics of what I would do.

I have my own shell script to update official releases. That script includes installing patches on-the-fly. Necessity is the mother of invention and because I use older hardware I never had a need to pursue the idea of modifying the official installation DVD ISO. That might be a side project for this winter.

Please post your script. I suspect I am not the only one who would be interested.
 
Old 06-08-2022, 12:18 PM   #4
henca
Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 992

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Quote:
Originally Posted by lostintime View Post
Please post your script
Ok, here we go:

This is the Makefile:
Code:
PACKAGE_DIRS = $(shell find ../slackware64/ \( -type d -o -type l \) \
                            -exec basename {} \;| \
                       grep -v slackware64 | grep -v PACKAGES.TXT )
KERNELS = $(shell find kernels/ \( -type d -o -type l \) \
                            -exec basename {} \;| \
                       grep -v kernels | grep -v memtest | sort | xargs echo )
BZIMAGES = $(KERNELS:%=kernels/%/bzImage)

DISTRO_NAME = Slack142
KERNEL_VERSION = 4.4.75
KERNEL_COMPRESSION = xz

DVD_IMAGE=/var/tmp/$(DISTRO_NAME)_dvd_install.iso

LINUX_SRC=kernel_and_patches/linux-$(KERNEL_VERSION).tar.$(KERNEL_COMPRESSION)
PATCHES = $(wildcard kernel_and_patches/*.patch)

SKIP_PATCHES=$(shell ./list-older-packages.sh slackware64/patches/)

SKIP_FLAGS=$(SKIP_PATCHES:%=-x %) -x kernel_and_patches/old_stuff

#PKG_BUILD_DIR = /var/tmp/pkg_build
#KERNEL_BUILD_DIR = /var/tmp/kernel_build/linux-$(KERNEL_VERSION)

PKG_BUILD_DIR = /var/tmp/henca/tmp/pkg_build
KERNEL_BUILD_DIR = /var/tmp/kernel_build/linux-$(KERNEL_VERSION)

.INTERMEDIATE: $(KERNEL_BUILD_DIR) $(PKG_BUILD_DIR)

.PRECIOUS: $(KERNEL_BUILD_DIR)

KERNEL_PATCH_PKG_DIR = slackware64/kernel-upgrades
CUS_PKG_DIR = slackware64/cus

PREV_PATCH_NR = $(shell ((ls $(KERNEL_PATCH_PKG_DIR)/*.tgz 2> /dev/null || \
                   echo 1) | \
                   sed -e 's/.tgz//' | \
                   awk 'BEGIN {FS="-"} ; {print $$NF}' | sort | tail -1))

PATCH_NR = $(strip $(shell (ls $(KERNEL_PATCH_PKG_DIR)/*.tgz 2> /dev/null || \
               echo 0) | \
               sed -e 's/.tgz//' | \
               awk 'BEGIN {FS="-"} ; {print $$NF}' | sort | tail -1 | \
               xargs echo 1+ | bc ))
PREV_PATCH_PKG_FILE= kernel-patches-$(KERNEL_VERSION)-x86_64-$(PREV_PATCH_NR).tgz
KERNEL_PATCH_PKG_FILE = kernel-patches-$(KERNEL_VERSION)-x86_64-$(PATCH_NR).tgz
MODULE_PATCH_PKG_FILE = module-patches-$(KERNEL_VERSION)-x86_64-$(PATCH_NR).tgz
PREV_PATCH_PKG = $(KERNEL_PATCH_PKG_DIR)/$(PREV_PATCH_PKG_FILE)
KERNEL_PATCH_PKG= $(shell pwd)/$(KERNEL_PATCH_PKG_DIR)/$(KERNEL_PATCH_PKG_FILE)
MODULE_PATCH_PKG= $(shell pwd)/$(KERNEL_PATCH_PKG_DIR)/$(MODULE_PATCH_PKG_FILE)

# Clean up kernel build directory
all: $(DVD_IMAGE)
	$(RM) -r $(KERNEL_BUILD_DIR) $(PKG_BUILD_DIR)

# Only one kernel can be built at a time
.NOTPARALLEL:

$(DVD_IMAGE): nfs_install.iso isolinux/setpkg.dvd \
              $(filter-out $(wildcard /var/tmp), \
              /var/tmp) \
              $(wildcard slackware64/*/*) \
              $(KERNEL_PATCH_PKG) Makefile
	cd isolinux && ln -sf setpkg.dvd setpkg && cd ..
	mkisofs -o $@ \
	  -R -J -V "Custom $(DISTRO_NAME) `date +%y%m%d`" \
          -joliet-long \
	  -hide-rr-moved -f\
	  -v -d -N -no-emul-boot -boot-load-size 4 -boot-info-table \
	  -sort isolinux/iso.sort \
	  -b isolinux/isolinux.bin \
	  -c isolinux/isolinux.boot \
	  -x initrd_src \
	  -x old \
          $(SKIP_FLAGS) \
          -eltorito-alt-boot -no-emul-boot -eltorito-platform 0xEF \
          -eltorito-boot isolinux/efiboot.img \
	  -A "Custom $(DISTRO_NAME) Install DVD" .
	echo $@ created

/var/tmp:
	mkdir -p $@

nfs_install.iso: isolinux/isolinux.cfg \
                 isolinux/message.txt \
                 isolinux/initrd.img \
                 isolinux/setpkg.nfs \
                 $(wildcard isolinux/*.img  isolinux/*.dsk) 
	cd isolinux && ln -sf setpkg.nfs setpkg && cd ..
	mkisofs -o $@ \
	  -R -J -V "Custom $(DISTRO_NAME) NFS `date +%y%m%d`" \
	  -hide-rr-moved -f\
	  -v -d -N -no-emul-boot -boot-load-size 4 -boot-info-table \
	  -sort isolinux/iso.sort \
	  -b isolinux/isolinux.bin \
	  -c isolinux/isolinux.boot \
	  -x slackware64 \
	  -x nfs_install.iso \
	  -x initrd_src \
          -eltorito-alt-boot -no-emul-boot -eltorito-platform 0xEF \
          -eltorito-boot isolinux/efiboot.img \
	  -A "Custom $(DISTRO_NAME) NFS install CD" . 

isolinux/isolinux.cfg: isolinux/isolinux.cfg.start isolinux/message.txt \
                       $(BZIMAGES)
	cp $@.start $@
	for KERNEL in $(KERNELS); do \
	  echo "label $$KERNEL" >> $@; \
	  echo "kernel /kernels/$$KERNEL/bzImage" >> $@; \
	  echo -n "append initrd=initrd.img load_ramdisk=1 " >> $@; \
          echo -n "prompt_ramdisk=0 rw printk.time=0 nomodeset " >> $@; \
          echo "SLACK_KERNEL=$$KERNEL" >> $@; \
	  echo "label kms_$$KERNEL" >> $@; \
	  echo "kernel /kernels/$$KERNEL/bzImage" >> $@; \
	  echo -n "append initrd=initrd.img load_ramdisk=1 " >> $@; \
          echo -n "prompt_ramdisk=0 rw printk.time=0  " >> $@; \
          echo "SLACK_KERNEL=$$KERNEL" >> $@; \
	done

isolinux/message.txt: isolinux/message.txt.start $(BZIMAGES)
	cp $@.start $@
	echo $(KERNELS) kms_$(KERNELS) memtest | fold -s >> $@

isolinux/initrd.img: initrd_src $(shell find initrd_src -type d -o -type f )
	cd $< && find . | cpio -o -H newc | gzip > ../$@

initrd_src:
ifeq ($(shell whoami),root)
	mkdir $@ && cd $@ && gzip -d < ../isolinux/initrd.img | cpio -i
else
	@echo Run \"make initrd_src\" as root! && false
endif
slack_dirs:
	find slackware64 -type l -exec $(RM) {} \;
	cd slackware64 && \
        ln -s $(foreach DIR, $(PACKAGE_DIRS), ../../slackware64/$(DIR)) .

PATCHED_MODULES=$(shell cat kernel_and_patches/patched_modules.txt)

kernels/%/bzImage: $(KERNEL_BUILD_DIR) kernels/%/config
	echo Compiling $@
	cp $(@D)/config $</.config
	cd $< && make clean && make -j `nproc` bzImage $(PATCHED_MODULES)
	$(RM) $(@D)/System.map.gz
	cp $</arch/x86_64/boot/bzImage $@
	cp $</System.map $(@D)
	gzip -9 $(@D)/System.map

$(KERNEL_BUILD_DIR): $(LINUX_SRC) $(wildcard kernels/*/config) $(PATCHES)
	mkdir -p $(@D)
	cat $< | xzcat | (cd $(@D) && tar -xvf -)
	$(foreach PATCH, $(PATCHES), \
                  cat $(PATCH) | (cd $@ && patch -p1) &&) true;

$(KERNEL_PATCH_PKG): $(KERNEL_BUILD_DIR) $(BZIMAGES) \
                     kernel_and_patches/doinst.sh
	( echo " Patched kernel" && echo && \
           tail -9 kernel_and_patches/patches.txt | \
           awk '{$$1=""; print $$0}' && printf "\n\n\n\n\n\n\n\n\n\n" ) | \
           sed -e 's/^/kernel-patches:/' | head -11 > \
           $(KERNEL_PATCH_PKG:%.tgz=%.txt)
	mkdir -p $(PKG_BUILD_DIR)/install/new_kernels
	cp -rp $(KERNELS:%=kernels/%) $(PKG_BUILD_DIR)/install/new_kernels
	cp kernel_and_patches/doinst.sh $(PKG_BUILD_DIR)/install
	cd $(PKG_BUILD_DIR) && /sbin/makepkg -c n $(KERNEL_PATCH_PKG)
	$(RM) -r $(PKG_BUILD_DIR)
	mkdir -p $(PKG_BUILD_DIR)/lib/modules/$(KERNEL_VERSION)/kernel
	cd $(KERNEL_BUILD_DIR) && tar -cf - $(PATCHED_MODULES) | \
         (cd $(PKG_BUILD_DIR)/lib/modules/$(KERNEL_VERSION)/kernel; tar -xvf -)
	mkdir $(PKG_BUILD_DIR)/install
	echo chroot . /sbin/depmod -a > $(PKG_BUILD_DIR)/install/doinst.sh
	cd $(PKG_BUILD_DIR) && fakeroot /sbin/makepkg -c y $(MODULE_PATCH_PKG)
	find $(CUS_PKG_DIR) -type l -exec rm {} \;
	ln -s ../`basename $(KERNEL_PATCH_PKG_DIR)`/$(MODULE_PATCH_PKG_FILE) \
              $(CUS_PKG_DIR)
	$(RM) -r $(KERNEL_BUILD_DIR)
That Makefile also calls this script list-older-packages.sh:
Code:
#!/bin/bash

if [ $# -eq 1 ]; then
  cd $1
fi

ARRAY=()
ls -t *.t?z | while read package ; do
  # Count number of segments:
  INDEX=1
  while [ ! "$(echo $package | cut -f $INDEX -d -)" = "" ]; do
    INDEX=$(expr $INDEX + 1)
  done
  NAME=$(expr $INDEX - 4)
  NAME="$(echo $package | cut -f 1-$NAME -d -)"
  if [[ " ${ARRAY[@]} " =~ " ${NAME} " ]]; then
    txt=`echo $package | sed -r -e 's/\.t.{1}z/.txt/'`
    asc=${package}.asc
    echo $package $txt $asc
  else
    ARRAY+=(${NAME})
  fi
done
Unfortunately, I don't have the latest version of my Makefile here, the Makefile above is a few years old. Since then I have also added support for making the DVD bootable on UEFI systems. I also have a work in progress to make the Makefile work with Slackware 15.0. One of the changes in 15.0 is that the original initrd.img was compressed with xz.

My Makefile uses some NFS directories for temporary work and final storage, but I have edited that to instead use /var/tmp above.

But again, the produced installation isos are only a small part of all customization. The initrd.img is unpacked to initrd_src and the setup files in that directory are manually modified to let the Makefile create a new initrd.img.

regards Henrik
 
Old 06-08-2022, 12:27 PM   #5
lostintime
Member
 
Registered: Dec 2021
Posts: 201

Original Poster
Rep: Reputation: Disabled
Thank you!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error occurred during initrd creation during installation of openSUSE 11.4 ccurwen Linux - Newbie 3 11-07-2012 12:56 AM
slackpkg error during upgrade patches sophenator Slackware - Installation 1 07-05-2008 10:22 PM
patches for a release version or slackware/slackware-ver.#/patches acummings Slackware 2 07-05-2007 01:05 AM
RedHat patches vs open source patches paulsh2k4 Linux - Software 1 10-14-2004 03:18 AM
Kernel question (about kernel patches) alekoos Linux - Newbie 1 04-29-2004 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration