#2728 PR merged: Always include loaded kernel modules

Labels: bug, fixed / solved / done

jsmeix opened issue at 2021-12-15 12:29:

  • Type: Bug Fix

  • Impact: Normal

  • Reference to related issue (URL):
    https://github.com/rear/rear/issues/2727

  • How was this pull request tested?
    Seems to work OK for me - but I can only do a few generic tests.
    In particular with MODULES=( 'loaded_modules' 'wireguard' )
    I get exactly only the loaded kernel modules but no 'wireguard'.

  • Brief description of the changes in this pull request:
    In build/GNU/Linux/400_copy_modules.sh also
    for MODULES=() or MODULES=( 'moduleX' 'moduleY' )
    include the currently loaded kernel modules.

jsmeix commented at 2021-12-15 12:32:

@DEvil0000
could you test it?
I would much appreciate it if you could.

With the change here

MODULES=( 'moduleX' 'moduleY' )

should automatically also include all loaded kernel modules
(plus some more - see the 400_copy_modules.sh code here).

DEvil0000 commented at 2021-12-15 16:45:

MODULES=( 'loaded_modules' 'wireguard' ) caused no modules at all got packed in the ISO. Is this intended?

edit:
MODULES=( 'wireguard' ) did pack/include some loaded modules and wireguard. It somehow did not include module uas which was also loaded.
yes, I am aware that the recovery system does not need to load the same modules - but some are missing in the image.

lsmod before rear mkrescue:

root@vl1bbls1a:~# lsmod 
Module                  Size  Used by
vxlan                  69632  0
ip6_udp_tunnel         16384  1 vxlan
udp_tunnel             16384  1 vxlan
uio                    20480  0
pf_ring               724992  0
cfg80211              708608  0
dm_multipath           32768  0
scsi_dh_rdac           16384  0
scsi_dh_emc            16384  0
scsi_dh_alua           20480  0
amd64_edac_mod         36864  0
edac_mce_amd           32768  1 amd64_edac_mod
kvm_amd                98304  0
kvm                   663552  1 kvm_amd
pcengines_apuv2        16384  0
gpio_keys_polled       16384  0
input_polldev          20480  1 gpio_keys_polled
gpio_amd_fch           16384  3
k10temp                16384  0
fam15h_power           16384  0
ccp                    86016  11 kvm_amd
mac_hid                16384  0
leds_gpio              16384  0
sch_fq_codel           20480  14
sctp                  344064  2
gpio_nct5104d          16384  1
8021q                  32768  0
garp                   16384  1 8021q
mrp                    20480  1 8021q
stp                    16384  1 garp
llc                    16384  2 stp,garp
bonding               167936  0
drm                   491520  0
ip_tables              32768  0
x_tables               40960  1 ip_tables
autofs4                45056  2
btrfs                1261568  0
zstd_compress         167936  1 btrfs
raid10                 61440  0
raid456               155648  0
async_raid6_recov      24576  1 raid456
async_memcpy           20480  2 raid456,async_raid6_recov
async_pq               24576  2 raid456,async_raid6_recov
async_xor              20480  3 async_pq,raid456,async_raid6_recov
async_tx               20480  5 async_pq,async_memcpy,async_xor,raid456,async_raid6_recov
xor                    24576  2 async_xor,btrfs
raid6_pq              114688  4 async_pq,btrfs,raid456,async_raid6_recov
libcrc32c              16384  3 btrfs,raid456,sctp
raid1                  45056  0
raid0                  24576  0
multipath              20480  0
linear                 20480  0
crct10dif_pclmul       16384  1
crc32_pclmul           16384  0
ghash_clmulni_intel    16384  0
aesni_intel           372736  0
crypto_simd            16384  1 aesni_intel
uas                    28672  0
sdhci_pci              53248  0
cryptd                 24576  2 crypto_simd,ghash_clmulni_intel
glue_helper            16384  1 aesni_intel
cqhci                  28672  1 sdhci_pci
ahci                   40960  2
libahci                32768  1 ahci
sdhci                  65536  1 sdhci_pci
r8169                  90112  0
igb                   221184  0
usb_storage            77824  1 uas
i2c_piix4              28672  0
realtek                24576  1
dca                    16384  1 igb
i2c_algo_bit           16384  1 igb
gpio_keys              20480  0

lsmod when rear ISO is booted:

Module                  Size  Used by
nvram                  16384  0
sctp                  344064  2
libcrc32c              16384  1 sctp
gpio_nct5104d          16384  1
8021q                  32768  0
garp                   16384  1 8021q
mrp                    20480  1 8021q
stp                    16384  1 garp
llc                    16384  2 stp,garp
bonding               167936  0
amd64_edac_mod         36864  0
edac_mce_amd           32768  1 amd64_edac_mod
kvm_amd                98304  0
kvm                   663552  1 kvm_amd
crct10dif_pclmul       16384  1
crc32_pclmul           16384  0
ghash_clmulni_intel    16384  0
pcengines_apuv2        16384  0
gpio_keys_polled       16384  0
aesni_intel           372736  0
input_polldev          20480  1 gpio_keys_polled
gpio_amd_fch           16384  3
glue_helper            16384  1 aesni_intel
crypto_simd            16384  1 aesni_intel
cryptd                 24576  2 crypto_simd,ghash_clmulni_intel
sdhci_pci              53248  0
cqhci                  28672  1 sdhci_pci
usb_storage            77824  0
ahci                   40960  0
r8169                  90112  0
k10temp                16384  0
igb                   221184  0
i2c_piix4              28672  0
libahci                32768  1 ahci
fam15h_power           16384  0
realtek                24576  0
sdhci                  65536  1 sdhci_pci
i2c_algo_bit           16384  1 igb
ccp                    86016  1 kvm_amd
dca                    16384  1 igb
mac_hid                16384  0
leds_gpio              16384  0
gpio_keys              20480  0
ip_tables              32768  0
x_tables               40960  1 ip_tables
autofs4                45056  0

I see a modprobe error on boot and modprobe uas does not find the named module.

jsmeix commented at 2021-12-16 09:04:

This specific modules including code in 400_copy_modules.sh
was and still is an endless nightmare.

The only thing that works simple and straightforward is the
MODULES=( 'all_modules' ) case because that does not
need the horrible modinfo_filename() function
which is the actual nightmare because - as far as I know - there is
no simple and straightforward way how to reliably get the right
kernel module file with path (i.e. what we need to copy)
from a kernel module name (i.e. what the user specified or what lsmod shows)

Currently we have the issue
https://github.com/rear/rear/issues/2677
Perhaps you are also hit by it?

DEvil0000 commented at 2021-12-16 13:07:

I think the issue with uas is with line 176. grep of uas and similar short strings are likely to match somewhere even if this is not the module we are looking for. In case of uas it matcheskernel/fs/squashfs/squashfs.ko. I suggest changing the grep to /uas.ko so prepending / and appending .ko.
I am not sure if this is a wise thing to do anyway - read second part about #2677.

I think this issue is related to #2677 but not actually the same bug. modinfo should be fine to search modules (if depmod -a or similar was run correctly before so lookup is fine?). The lookup order for module pathes is defined in a way that build in modules can get 'updated' by packages providing a newer version of the module. So even if it is a built-in one you should first check for a newer version actually used (modinfo maybe)

edit:
please note that lsmod will not show built-in modules normally (loaded or not does not matter)

hpannenb commented at 2021-12-16 19:13:

I agree with @DEvil0000 : The mentioned grep is a too 'lazy' and would lead to the mentioned false positives.

I propose to change the line to something like
grep -q "\/$( echo $module | tr '_-' '..' )\." ...
to search with a prefix / and an extension of a single dot to be open for any module name's extension that might come.
Edit:
The only issue I see is if $module is empty code would continue since there is no entry found in the modules.builtin.

jsmeix commented at 2021-12-22 13:00:

@DEvil0000 @hpannenb
I will work on this one (as time permits) in January.

I wish you a merry Christmas and a happy New Year!

github-actions commented at 2022-02-21 02:09:

Stale pull request message

github-actions commented at 2022-04-23 02:49:

Stale pull request message

jsmeix commented at 2022-05-16 10:24:

With
https://github.com/rear/rear/pull/2728/commits/048db085c1cb0a81186d9675b4126d92223483ab
I have now

grep -q "/$( echo $module | tr '_-' '..' )\." /lib/modules/$KERNEL_VERSION/modules.builtin && continue

There is no need to quote '/' with a preceding backslash
because '/' is no grep meta-character as far as I see
(I did not find a complete list of grep meta-characters)
in contrast to '.' which is a grep meta-character.

There is no need to care about if $module is empty
because the line just before

modinfo $module 1>/dev/null || continue

does that:

# modinfo
modinfo: ERROR: missing module or filename.

jsmeix commented at 2022-05-16 10:33:

@rear/contributors
please have a look here if you see obviously wrong changes.

When there are no objections I would like to merge it
on Wednesday (May 18) afternoon.

DEvil0000 commented at 2022-05-17 14:22:

Changeset looks fine, I however currently have no time to test it.


[Export of Github issue for rear/rear.]