Page 1 of 1

rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 2:47 pm
by tony37
I'm sorry to complain, but I think this rebuild_dkms_packages script is, uh, not-so-well-thought-out.
Example with kernels 4.19.0-12-amd64 and 5.8.0-17.2-liquorix-amd64 installed, with for example virtualbox modules in dkms.
When I install the linux-image-5.8.0-3-amd64-unsigned kernel using the kernels section in MXPI, the following happens:
- virtualbox module gets automatically built for the 5.8.0-3 kernel (there is no output of this, but it does happen)
- then the script removes the virtualbox module for all kernels: 4.19.0-12, 5.8.0-17.2-liquorix and 5.8.0-3
- then the virtualbox module gets rebuilt for the current kernel (the liquorix one) and for the kernel considered most recent (also the liquorix one)

End result: the module for the 4.19 kernel got removed and the module for the 5.8.0-3 kernel is not even there (well, it was there, but then it got removed). This is just the most extreme example, a problem in all cases is that modules from older kernels simply get removed.

What I propose is using /usr/lib/dkms/dkms_autoinstaller instead, for example

Code: Select all

/usr/lib/dkms/dkms_autoinstaller start 5.8.0-3-amd64
If the dkms modules have already been built (which was the case here), dkms_autoinstaller just exits with 'ok'.
In case of a meta-package being installed, the name of the installed kernel is not known beforehand. So checking for the most recently installed kernel could be done with:

Code: Select all

/usr/lib/dkms/dkms_autoinstaller start $(ls -t /var/lib/initramfs-tools | head -n1)
(maybe there are better ways to do this, and instructions for $(uname -r) could be added to stay backwards-compatible)
Checking if dkms modules are built for all kernels would be:

Code: Select all

ls /var/lib/initramfs-tools | xargs -n1 /usr/lib/dkms/dkms_autoinstaller start

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 4:25 pm
by dolphin_oracle
great suggestion.

for what its worth, the current script just re-runs the configure step from the apt package's setup routines. so it does whatever those packages do when you install them.

but I like this. i've just about got some stuff figured on the meta-packages. should upload something later today.

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 5:18 pm
by tony37
I'm not that sure finding the most recent kernel with $(ls -t /var/lib/initramfs-tools | head -n1) is really professional, because strictly speaking it finds the kernel whose initramfs has been updated most recently. And if the kernel gets installed together with other packages causing all initramfs's to be updated, it would depend on execution order if the command still works.
Better might be

Code: Select all

$(readlink -f /vmlinuz | sed 's/\/boot\/vmlinuz-//')

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 5:21 pm
by dolphin_oracle
tony37 wrote: Sun Nov 08, 2020 5:18 pm I'm not that sure finding the most recent kernel with $(ls -t /var/lib/initramfs-tools | head -n1) is really professional, because strictly speaking it finds the kernel whose initramfs has been updated most recently. And if the kernel gets installed together with other packages causing all initramfs's to be updated, it would depend on execution order if the command still works.
Better might be

Code: Select all

$(readlink -f /vmlinuz | sed 's/\/boot\/vmlinuz-//')
I just check the depend on the metapackage for what kernel gets installed.

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 5:38 pm
by tony37
Ok, you'll find something.
But there's also the use case that people install a kernel on their own and then afterwards want to execute the rebuild_dkms_packages script...

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 5:43 pm
by dolphin_oracle
tony37 wrote: Sun Nov 08, 2020 5:38 pm Ok, you'll find something.
But there's also the use case that people install a kernel on their own and then afterwards want to execute the rebuild_dkms_packages script...
I put a backup that will rebuild on the current kernel if no kernel is specified.

the user can also specify a kernel package name (which is what we do in mx-packageinstaller-pkglist) for instance.

Code: Select all

rebuild_dkms_packages.sh linux-image-5.8.0-3-amd64
the metapackages won't work in that case though, you need the actual kernel package.

if the package is found not to be installed, nothing happens.

Re: rebuild_dkms_packages.sh script fails

Posted: Sun Nov 08, 2020 6:26 pm
by tony37
I'll check when the update comes, thanks for the work

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 4:05 am
by tony37
Update arrived, looks fine, only thing I can think of is that some people may assume that the script also exists in the /usr/share/mx-packageinstaller-pkglist folder, like here. Maybe have a symlink there?

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 8:54 am
by fehlix
Seems to do it.
On "Liquorix 64 bit" kernel install I see some errors:

Code: Select all

rebuild_dkms_packages.sh linux-image-liquorix-amd64
apt-get -y remove linux-image-liquorix-amd64 linux-headers-liquorix-amd64
apt-get update
2020-11-09 13:10:31.244 DBG default: "update dkms modules for kernel:  5.8.0-17.2-liquorix-amd64"
2020-11-09 13:10:31.247 DBG default: "see log at /var/log/rebuild-dkms.log"
2020-11-09 13:10:31.260 DBG default: "dkms: running auto installation service for kernel 5.8.0-17.2-liquorix-amd64:"
2020-11-09 13:10:31.643 DBG default: "."
2020-11-09 13:10:31.682 DBG default: "update dkms modules for kernel:  liquorix-amd64"
2020-11-09 13:10:31.685 DBG default: "see log at /var/log/rebuild-dkms.log"
2020-11-09 13:10:31.694 DBG default: "dkms: running auto installation service for kernel liquorix-amd64:"
2020-11-09 13:10:32.182 WRN default: "Error!"
2020-11-09 13:10:32.183 WRN default: "echo\nYour kernel headers for kernel liquorix-amd64 cannot be found at\n/lib/modules/liquorix-amd64/build or /lib/modules/liquorix-amd64/source."
2020-11-09 13:10:32.274 WRN default: "Error!"
2020-11-09 13:10:32.274 WRN default: "echo\nYour kernel headers for kernel liquorix-amd64 cannot be found at\n/lib/modules/liquorix-amd64/build or /lib/modules/liquorix-amd64/source.

which might be caused by this line

Code: Select all

rebuild_dkms_packages.sh linux-image-liquorix-amd64
within the postinstall:

Code: Select all

<postinstall>
file=$(apt-cache show linux-image-liquorix-amd64 |grep -m1 Depends) 
file=${file#"Depends:"}
rebuild_dkms_packages.sh $file
rm -f /etc/apt/sources.list.d/mxpitemp.list
rebuild_dkms_packages.sh linux-image-liquorix-amd64
apt-get -y remove linux-image-liquorix-amd64 linux-headers-liquorix-amd64
apt-get update
</postinstall>
So suggest to get rid of the line in question within the postinstall to avoid the error messages.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 9:01 am
by dolphin_oracle
yep, I missed that one! will fix.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 11:54 am
by tony37
I see a problem: there are different packages called 'linux-image-amd64', so when someone has the Debian Backports repo enabled (like me, though I rarely install something from it), then

Code: Select all

apt-cache show linux-image-amd64 |grep -m1 Depends
will result in "linux-image-5.8.0-0.bpo.2-amd64 (= 5.8.10-1~bpo10+1)". For some reason the appended "(= 5.8.10-1~bpo10+1)" doesn't cause problems, but anyway: when I install the 4.19 meta-package I get this:

Code: Select all

update dkms modules for kernel:  5.8.0-0.bpo.2-amd64
see log at /var/log/rebuild-dkms.log
dkms: running auto installation service for kernel 5.8.0-0.bpo.2-amd64:Error! echo
Your kernel headers for kernel 5.8.0-0.bpo.2-amd64 cannot be found at
/lib/modules/5.8.0-0.bpo.2-amd64/build or /lib/modules/5.8.0-0.bpo.2-amd64/source.
Error! echo
Your kernel headers for kernel 5.8.0-0.bpo.2-amd64 cannot be found at
.
/lib/modules/5.8.0-0.bpo.2-amd64/build or /lib/modules/5.8.0-0.bpo.2-amd64/source.
Maybe for the 4.19 kernel you could use

Code: Select all

apt-cache show linux-image-amd64=4.19* |grep -m1 Depends

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 12:38 pm
by dolphin_oracle
ugh.

this is why I used the dpkg-reconfigure commands in the first place.

got the debian kernels updated...thanks for the help with that case

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 12:50 pm
by tony37
A more general command would be:

Code: Select all

file=$(apt-cache show linux-image-amd64=$(dpkg-query -W linux-image-amd64 |awk '{print $2}') |grep -m1 Depends) 
It will find the version of the installed meta-package. Maybe I can find something better still.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 12:54 pm
by dolphin_oracle
tony37 wrote: Mon Nov 09, 2020 12:50 pm A more general command would be:

Code: Select all

file=$(apt-cache show linux-image-amd64=$(dpkg-query -W linux-image-amd64 |awk '{print $2}') |grep -m1 Depends) 
It will find the version of the installed meta-package. Maybe I can find something better still.
I don't understand why the dpkg-query test is past for a kernel that isn't installed. it should have exited without doing anything in that case. still wrong, but less wrong.

Code: Select all

[[ $(dpkg-query --show $1 2>/dev/null && echo $?) ]] || exit 0

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:06 pm
by tony37
dolphin_oracle wrote: Mon Nov 09, 2020 12:54 pm
tony37 wrote: Mon Nov 09, 2020 12:50 pm A more general command would be:

Code: Select all

file=$(apt-cache show linux-image-amd64=$(dpkg-query -W linux-image-amd64 |awk '{print $2}') |grep -m1 Depends) 
It will find the version of the installed meta-package. Maybe I can find something better still.
I don't understand why the dpkg-query test is past for a kernel that isn't installed.
remaining configuration files?

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:15 pm
by dolphin_oracle
I think its because I'm stupid.

the echo succeeds, so the statement is true no matter if the dpkg-query works or not. that should be easy to fix.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:31 pm
by dolphin_oracle
dolphin_oracle wrote: Mon Nov 09, 2020 2:15 pm I think its because I'm stupid.

the echo succeeds, so the statement is true no matter if the dpkg-query works or not. that should be easy to fix.
nope that's not it.

did you have the debian backports kernel installed at some point?

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:39 pm
by dolphin_oracle
dpkg-query --status

is the command we want. the "--show" will pass if a package has been installed but later removed.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:44 pm
by dolphin_oracle
haven't packaged yet, but here's the code.

Code: Select all

#!/bin/bash

#force rebuild of dkms packages (virtualbox, nvidia, fglrx, broadcom, ndiswrapper)
#part of mx-packageinstaller

kernel="$1"

# if parameter passed, then check to see if package is installed, exit if not
if [ -n "$kernel" ]; then
	[[ $(dpkg-query --status $1 2>/dev/null ) ]] || exit 0
fi	

#if no kernel parameter given, assume current kernel
if [ -z "$kernel" ]; then
	kernel="$(uname -r)"
fi

kernel=${kernel#"linux-image-"}
kernel=${kernel%-unsigned}

echo "update dkms modules for kernel: " $kernel |tee /var/log/rebuild-dkms.log
echo "see log at /var/log/rebuild-dkms.log"

/usr/lib/dkms/dkms_autoinstaller start $kernel |tee -a /var/log/rebuild-dkms.log

exit 0

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:49 pm
by tony37
"dpkg-query --status" also gives output for packages with remaining configuration files:

Code: Select all

Status: deinstall ok config-files

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:52 pm
by dolphin_oracle
tony37 wrote: Mon Nov 09, 2020 2:49 pm "dpkg-query --status" also gives output for packages with remaining configuration files:

Code: Select all

Status: deinstall ok config-files
do kernels have left over conf files (that's a real question)?

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 2:53 pm
by tony37
Of course, I have linux-image-4.19.0-11-amd64 there
(easy command to search for such packages: aptitude search '~c')

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 3:08 pm
by dolphin_oracle
ok, then we will go full on fool-proof

Code: Select all

#!/bin/bash

#force rebuild of dkms packages (virtualbox, nvidia, fglrx, broadcom, ndiswrapper)
#part of mx-packageinstaller

kernel="$1"

# if parameter passed, then check to see if package is installed, exit if not
if [ -n "$kernel" ]; then
	[[ ! $(LANG=C dpkg-query --status $1 |grep "install ok installed"  ) ]] || exit 0
fi	

#if no kernel parameter given, assume current kernel
if [ -z "$kernel" ]; then
	kernel="$(uname -r)"
fi

kernel=${kernel#"linux-image-"}
kernel=${kernel%-unsigned}

echo "update dkms modules for kernel: " $kernel |tee /var/log/rebuild-dkms.log
echo "see log at /var/log/rebuild-dkms.log"

/usr/lib/dkms/dkms_autoinstaller start $kernel |tee -a /var/log/rebuild-dkms.log

exit 0

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 3:22 pm
by tony37
Maybe still a mistake, I think it exits if the package is installed and not the reverse

If you leave out the ! it works better:

Code: Select all

[[ $(LANG=C dpkg-query --status $1 |grep "install ok installed"  ) ]] || exit 0
But with a package not installed and also with no config files remaining, I get this message:

Code: Select all

dpkg-query: package 'linux-image-4.19.0-10-amd64' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
edit: The right solution is of course combining the two conditions:

Code: Select all

#!/bin/bash

#force rebuild of dkms packages (virtualbox, nvidia, fglrx, broadcom, ndiswrapper)
#part of mx-packageinstaller

kernel="$1"

# if parameter passed, then check to see if package is installed, exit if not
if [ -n "$kernel" ]; then
	[[ $(dpkg-query --status $1 2>/dev/null ) ]] || exit 0
	[[ $(LANG=C dpkg-query --status $1 |grep "install ok installed"  ) ]] || exit 0
fi	

#if no kernel parameter given, assume current kernel
if [ -z "$kernel" ]; then
	kernel="$(uname -r)"
fi

kernel=${kernel#"linux-image-"}
kernel=${kernel%-unsigned}

echo "update dkms modules for kernel: " $kernel |tee /var/log/rebuild-dkms.log
echo "see log at /var/log/rebuild-dkms.log"

/usr/lib/dkms/dkms_autoinstaller start $kernel |tee -a /var/log/rebuild-dkms.log

exit 0

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 3:41 pm
by tony37
in case you can still use this, an easy way to find the dependency of the installed linux-image-amd64 package:

Code: Select all

dpkg-query -W -f='${Depends}\n' linux-image-amd64

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 4:45 pm
by dolphin_oracle
tony37 wrote: Mon Nov 09, 2020 3:41 pm in case you can still use this, an easy way to find the dependency of the installed linux-image-amd64 package:

Code: Select all

dpkg-query -W -f='${Depends}\n' linux-image-amd64
I used similar in the kernel pm files.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 4:47 pm
by dolphin_oracle
I don't want it it exit if the package is installed. I want it to exit if the package is NOT installed, so that nothing happens if the build fails.

I'll make sure to test it when I'm back at my linux box.

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 5:05 pm
by tony37
this works to check if the package is installed or not:

Code: Select all

if [ -n "$kernel" ]; then
    [[ $(grep -A1 $1 /var/lib/dpkg/status | grep 'install ok installed'  ) ]] || exit 0
fi	

Re: rebuild_dkms_packages.sh script fails

Posted: Mon Nov 09, 2020 6:35 pm
by dolphin_oracle
used your test, and got rid of hte !

Code: Select all

#!/bin/bash

#force rebuild of dkms packages (virtualbox, nvidia, fglrx, broadcom, ndiswrapper)
#part of mx-packageinstaller

kernel="$1"

# if parameter passed, then check to see if package is installed, exit if not
if [ -n "$kernel" ]; then
    [[ -n $(grep -A1 $kernel /var/lib/dpkg/status | grep 'install ok installed'  ) ]] || exit 0
fi	

#if no kernel parameter given, assume current kernel
if [ -z "$kernel" ]; then
	kernel="$(uname -r)"
fi

kernel=${kernel#"linux-image-"}
kernel=${kernel%-unsigned}

echo "update dkms modules for kernel: " $kernel |tee /var/log/rebuild-dkms.log
echo "see log at /var/log/rebuild-dkms.log"

#/usr/lib/dkms/dkms_autoinstaller start $kernel |tee -a /var/log/rebuild-dkms.log

exit 0

Re: rebuild_dkms_packages.sh script fails

Posted: Tue Nov 10, 2020 3:43 am
by tony37
I'm sorry to say, but you have

Code: Select all

file=$(apt-cache show linux-image-amd64=4.19 |grep -m1 Depends)
in kernel_debian_64.pm (and similar in kernel_debian_32.pm) and it should have been

Code: Select all

file=$(apt-cache show linux-image-amd64=4.19* |grep -m1 Depends)
:lipsrsealed:

edit: the deb file also has a folder /share/mx-packageinstaller-pkglist (without /usr)...

Re: rebuild_dkms_packages.sh script fails

Posted: Tue Nov 10, 2020 7:51 am
by dolphin_oracle
fixed them both in package 20.11.03

once it hits the repo, we may see some folks with update issues (failure to download). they will just need to update their sources ("check for updates") and it should be good.