Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Creating pre and post install scripts when updating kernel

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
9 posts • Page 1 of 1
Author
Message
keremCozin
n00b
n00b
Posts: 23
Joined: Mon Sep 18, 2017 1:15 pm

Creating pre and post install scripts when updating kernel

  • Quote

Post by keremCozin » Tue Jan 02, 2024 4:19 pm

Hello Gentoo community, I'm using gentoo-kernel-bin for my machine and I'm wondering if it's possible to create;
pre-install script to do;

Code: Select all

mount /boot
and then post-install script to do;

Code: Select all

grub-mkconfig -o /boot/grub/grub.cfg && umount /boot
for only gentoo-kernel-bin package?

If it's possible, where to put such scripts and how to create hooks on per-package basis,
I'm assuming it will be bash scripting.
I'm new to programming and such and thus I'd like learn how.

Thanks!
Kerem Caner Özin
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4694
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Tue Jan 02, 2024 4:35 pm

Post-install is easy with scripts inside /etc/kernel/postinst.d directory.
See this topic.

Wiki mentions also /etc/kernel/preinst.d. I haven't used it but I would guess it works quite the same as postinst.d.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
keremCozin
n00b
n00b
Posts: 23
Joined: Mon Sep 18, 2017 1:15 pm

  • Quote

Post by keremCozin » Tue Jan 02, 2024 5:57 pm

Thanks for the reply!
It's exactly what I was looking for.
Kerem Caner Özin
Top
keremCozin
n00b
n00b
Posts: 23
Joined: Mon Sep 18, 2017 1:15 pm

  • Quote

Post by keremCozin » Wed Jan 03, 2024 8:33 am

The scripts in /etc/kernel/postinst.d directory works,
For /etc/kernel/preinst.d directory, I see we have /etc/kernel/install.d directory instead and that's apparently part of systemd. (I use systemd)
Neither of my scripts at /etc/kernel/preinst.d nor /etc/kernel/install.d did work. My system wasn't aware of the scripts in there.
Here what I did for my each folder, and for possible future reference;

At /etc/kernel/postinst.d I've created a file called 99-kernel.install

/etc/kernel/postinst.d/99-kernel.install

Code: Select all

#!/bin/env bash

grub-mkconfig -o /boot/grub/grub.cfg
sleep 2s
echo "Unmounting boot partition..."
umount /boot
chmod +x /etc/kernel/postinst.d/99-kernel.install

Also,
Tried both /etc/kernel/preinst.d and /etc/kernel/install.d directories and created the same file there so in this case,

/etc/kernel/install.d/99-kernel.install

Code: Select all

#!/bin/env bash

if mountpoint -q /boot
then
        echo "Boot partition is already mounted."
else
        echo "Mounting boot partition..."
        mount /boot
fi
chmod +x /etc/kernel/install.d/99-kernel.install

I'm looking for further instructions to make pre-install scripts work.
What can be done here, how can I write custom system hooks, is it possible, is it safe enough?
Thanks again!
Kerem Caner Özin
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4694
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Jan 03, 2024 5:18 pm

One way to achieve it is to go this route.

Try creating /etc/portage/env/sys-kernel/gentoo-kernel-bin/mount_boot.sh
Then put something like this in it:

Code: Select all

pre_pkg_setup() {
    if ! mountpoint -q /boot
    then
        mount /boot || die "Unable to mount /boot."
    fi
}
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
keremCozin
n00b
n00b
Posts: 23
Joined: Mon Sep 18, 2017 1:15 pm

  • Quote

Post by keremCozin » Thu Jan 04, 2024 7:31 am

Thanks a lot! Gentoo linux is full of wonders =)
Kerem Caner Özin
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4694
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Jan 17, 2024 5:35 am

intallkernel seems to be updated to support /etc/kernel/preinst.d now. I haven't tested it yet, but I recently did world update and I now have sys-kernel/installkernel-12.

More info on the wiki.

EDIT: systemd version of installkernel uses /etc/kernel/install.d.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
ZekeMorrin
n00b
n00b
User avatar
Posts: 29
Joined: Sun Oct 15, 2023 2:18 pm
Contact:
Contact ZekeMorrin
Website

  • Quote

Post by ZekeMorrin » Sat Jan 20, 2024 9:02 pm

Zucca wrote:intallkernel seems to be updated to support /etc/kernel/preinst.d now. I haven't tested it yet, but I recently did world update and I now have sys-kernel/installkernel-12.

More info on the wiki.

EDIT: systemd version of installkernel uses /etc/kernel/install.d.
Wonderful, thanks for the heads up o7
Top
Nowa
Developer
Developer
User avatar
Posts: 522
Joined: Wed Jun 25, 2014 7:07 am
Location: Hilversum

  • Quote

Post by Nowa » Mon Jan 22, 2024 11:37 am

keremCozin wrote:The scripts in /etc/kernel/postinst.d directory works,
For /etc/kernel/preinst.d directory, I see we have /etc/kernel/install.d directory instead and that's apparently part of systemd. (I use systemd)
Neither of my scripts at /etc/kernel/preinst.d nor /etc/kernel/install.d did work. My system wasn't aware of the scripts in there.
Here what I did for my each folder, and for possible future reference;

At /etc/kernel/postinst.d I've created a file called 99-kernel.install

/etc/kernel/postinst.d/99-kernel.install

Code: Select all

#!/bin/env bash

grub-mkconfig -o /boot/grub/grub.cfg
sleep 2s
echo "Unmounting boot partition..."
umount /boot
chmod +x /etc/kernel/postinst.d/99-kernel.install

Also,
Tried both /etc/kernel/preinst.d and /etc/kernel/install.d directories and created the same file there so in this case,

/etc/kernel/install.d/99-kernel.install

Code: Select all

#!/bin/env bash

if mountpoint -q /boot
then
        echo "Boot partition is already mounted."
else
        echo "Mounting boot partition..."
        mount /boot
fi
chmod +x /etc/kernel/install.d/99-kernel.install

I'm looking for further instructions to make pre-install scripts work.
What can be done here, how can I write custom system hooks, is it possible, is it safe enough?
Thanks again!
This should also work. I suspect the problem here is that your script has number 99, which means it is executed last. You want it executed first, specifically before the 90-*.install plugins which will actually do the copying to /boot.

Note that preinst.d and postinst.d are for installkernel[-systemd] whereas install.d is for installkernel[+systemd]. All plugins are executed after the install phase of the dist-kernels (i.e. gentoo-kernel) or when running make install. So pre and post refers here to before and after copying to /boot (which is what the main installkernel[-systemd] script will do). Whereas install.d is responsible for the whole chain, pre, copy to /boot, and post. Hope this clears this up.

Please do let me know if the wiki is unclear or confusing with respect to these plugins, you're not the first to have questions about this so I'd love to improve this wiki page where possible.
OS: Gentoo 6.19.3-gentoo-dist, ~amd64, 23.0/desktop/plasma/systemd
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400
Top
Post Reply

9 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic