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

fix(live): Less aggressive kernel driver cleanup #1790

Merged
merged 1 commit into from
Nov 28, 2024
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
3 changes: 2 additions & 1 deletion live/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FLAVOR = openSUSE
# the default OBS project,
# to use a different project run "make build OBS_PROJECT=<project>"
OBS_PROJECT = "systemsmanagement:Agama:Devel"
OBS_PACKAGE = "agama-installer"

# files to copy from src/
COPY_FILES = $(patsubst $(SRCDIR)/%,$(DESTDIR)/%,$(wildcard $(SRCDIR)/*))
Expand Down Expand Up @@ -52,7 +53,7 @@ $(DESTDIR)/%.tar.xz: % $$(shell find % -type f,l)

# build the ISO locally
build: $(DESTDIR)
if [ ! -e $(DESTDIR)/.osc ]; then make clean; osc co -o $(DESTDIR) $(OBS_PROJECT) agama-installer-openSUSE; fi
if [ ! -e $(DESTDIR)/.osc ]; then make clean; osc co -o $(DESTDIR) $(OBS_PROJECT) $(OBS_PACKAGE); fi
$(MAKE) all
(cd $(DESTDIR) && osc build -M $(FLAVOR) images)

Expand Down
93 changes: 93 additions & 0 deletions live/root/tmp/driver_cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#! /usr/bin/env ruby

# This script removes not needed multimedia drivers (sound cards, TV cards,...).
#
# By default the script runs in safe mode and only lists the drivers to delete,
# use the "--delete" argument to really delete the drivers.

require "find"
require "shellwords"

# class holding the kernel driver data
class Driver
# the driver name, full file path, dependencies
attr_reader :name, :path, :deps

def initialize(name, path, deps)
@name = name
@path = path
@deps = deps
end

# load the kernel driver data from the given path recursively
def self.find(dir)
drivers = []
puts "Scanning kernel modules in #{dir}..."

return drivers unless File.directory?(dir)

Find.find(dir) do |path|
if File.file?(path) && path.end_with?(".ko", ".ko.xz", ".ko.zst")
name = File.basename(path).sub(/\.ko(\.xz|\.zst|)\z/, "")
deps = `/usr/sbin/modinfo -F depends #{path.shellescape}`.chomp.split(",")
drivers << Driver.new(name, path, deps)
end
end

return drivers
end
end

# delete the kernel drivers in these subdirectories, but keep the drivers used by
# dependencies from other drivers
delete = [
"kernel/sound",
"kernel/drivers/media",
"kernel/drivers/staging/media"
]

# in the Live ISO there should be just one kernel installed
dir = Dir["/lib/modules/*"].first

# drivers to delete
delete_drivers = []

# scan the drivers in the delete subdirectories
delete.each do |d|
delete_drivers += Driver.find(File.join(dir, d))
end

all_drivers = Driver.find(dir)

# remove the possibly deleted drivers
all_drivers.reject!{|a| delete_drivers.any?{|d| d.name == a.name}}

puts "Skipping dependent drivers:"

# iteratively find the dependant drivers (dependencies of dependencies...)
loop do
referenced = delete_drivers.select do |dd|
all_drivers.any?{|ad| ad.deps.include?(dd.name)}
end

# no more new dependencies, end of the dependency chain reached
break if referenced.empty?

puts referenced.map(&:path).sort.join("\n")

# move the referenced drivers from the "delete" list to the "keep" list
all_drivers += referenced
delete_drivers.reject!{|a| referenced.any?{|d| d.name == a.name}}
end

puts "Drivers to delete:"
delete = ARGV[0] == "--delete"

delete_drivers.each do |d|
if (delete)
puts "Deleting #{d.path}"
File.delete(d.path)
else
puts d.path
end
end
7 changes: 7 additions & 0 deletions live/src/agama-installer.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Nov 28 08:58:21 UTC 2024 - Ladislav Slezák <[email protected]>

- Less aggressive kernel driver cleanup, keep the multimedia
drivers which are needed as dependencies of other drivers
(usually graphic card drivers) (gh#agama-project/agama#1665)

-------------------------------------------------------------------
Wed Nov 13 12:20:23 UTC 2024 - Lubos Kocman <[email protected]>

Expand Down
9 changes: 5 additions & 4 deletions live/src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ rpm -e --nodeps alsa alsa-utils alsa-ucm-conf || true
# and remove the drivers for sound cards and TV cards instead. Those do not
# make sense on a server.
du -h -s /lib/modules /lib/firmware
# delete sound drivers
rm -rfv /lib/modules/*/kernel/sound
# delete TV cards and radio cards
rm -rfv /lib/modules/*/kernel/drivers/media/

# remove the multimedia drivers
/tmp/driver_cleanup.rb --delete
# remove the script, not needed anymore
rm /tmp/driver_cleanup.rb

# remove the unused firmware (not referenced by kernel drivers)
/tmp/fw_cleanup.rb --delete
Expand Down