kernel-modules-hook icon indicating copy to clipboard operation
kernel-modules-hook copied to clipboard

Use hardlinks, bind mount and systemd-tmpfiles to simplify the logic

Open VannTen opened this issue 3 years ago • 8 comments

Hi folks,

I propose to simplify the logic by relying on bind mount and systemd-tmpfiles instead of cleaning up ourselves.

High-level view of new workflow :

On kernel upgrade / or removal :

  • cp the whole /usr/lib/modules/$(kver) tree using hardlinks before the transaction to /usr/lib/modules/backup-$(kver)
  • after the transaction, bind mount /usr/lib/modules/backup-$(kver) to /usr/lib/modules/$(kver)
  • On next boot, bind mount is gone so : -> we delete recursively dir matching /usr/lib/modules/backup-* -> we delete empty dir matching /usr/lib/modules/* (installed kernel is not emtpy so it will not be deleted, but the mount point for the old kernel is)

That's a pretty big change ; I'm ok forking if you think it does not fit that project.

Thanks.

VannTen avatar Jul 11 '22 15:07 VannTen

Brilliant idea. But there's one little flaw: what if the user would like to revert back to the running kernel without a reboot? The bind mounted old kernel would essentially block the downgrade path.

isjerryxiao avatar Dec 02 '22 14:12 isjerryxiao

Good point.

Maybe it can be solved with another hook which removes the bind mount on upgrade if there is one matching the current kernel.

I'll think about that, a bit busy with life right now.

VannTen avatar Dec 26 '22 15:12 VannTen

Hi o/

So I reworked a bit the hooks:

The pre-hook:

  • check if the path exist -> detect whether we install or remove
  • only copy if the copy does not exist yet (multiple install/uninstall case)
  • checks if there is already a mount only when triggered by "Install" (-> the case where the user reinstall the running kernel after having installed another version)
  • Also, we only copy the kernel/ directy and all modules* files, which should supersede #12 (when other scripts have problem with duplicate pkgbase)

WARNING: I haven't tested it yet.

Thoughts ?

VannTen avatar Feb 08 '23 16:02 VannTen

Great job!

isjerryxiao avatar Feb 13 '23 05:02 isjerryxiao

Your script is faulty in several ways fix: https://github.com/archlinux-jerry/pkgbuilds/commit/512e59c17da6b2e35fc053ac4cc45adda27317b3 and https://github.com/archlinux-jerry/pkgbuilds/commit/d49e7113e283159fc3448acca875e4091b4c064e

isjerryxiao avatar May 30 '23 16:05 isjerryxiao

It's actually worse than that, because rollback is really problematic. You end up with files present conflicting with files pacman want to place in the fs.

A proper solution should be to use depmod to tell the kernel where the modules are, but I need to look at documenation for that and I've been missing the time.

VannTen avatar May 31 '23 07:05 VannTen

I don't see any file conflict.

isjerryxiao avatar May 31 '23 15:05 isjerryxiao

should have removed the mount point after umount https://github.com/archlinux-jerry/pkgbuilds/commit/f69c1abf352613767dc458a61b12b46d3b582b59

isjerryxiao avatar May 31 '23 15:05 isjerryxiao