Results 1 to 7 of 7

Thread: How to add custom settings to initramfs?

  1. #1

    Default How to add custom settings to initramfs?

    I am trying to apply this (https://github.com/openSUSE/SUSEPrim...river-packages) recommendation. As I understand I need to add the code written there and pack it into my initramfs so that it will be executed by the kernel on every boot.
    How do I do this?

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,817
    Blog Entries
    15

    Default Re: How to add custom settings to initramfs?

    Quote Originally Posted by Merryn View Post
    I am trying to apply this (https://github.com/openSUSE/SUSEPrim...river-packages) recommendation. As I understand I need to add the code written there and pack it into my initramfs so that it will be executed by the kernel on every boot.
    How do I do this?
    Hi
    There are three commands there, just copy/paste and run them as root user (switch to root user via su - );

    Code:
    test -s /etc/modprobe.d/09-nvidia-modprobe-pm-G05.conf  || cp 09-nvidia-modprobe-pm-G05.conf /etc/modprobe.d
    
    if [ ! -s /etc/dracut.conf.d/90-nvidia-dracut-G05.conf ]; then cp 90-nvidia-dracut-G05.conf /etc/dracut.conf.d/ && dracut -f fi
    
    test -s /etc/udev/rules.d/90-nvidia-udev-pm-G05.rules || cp 90-nvidia-udev-pm-G05.rules /etc/udev/rules.d/
    The above three commands do everything for you, the 'dracut' command will rebuild your initrd

    If you remove the trailing \ or you could just pop it in a bash script change permissions and run...

    Code:
    #!/bin/bash
    
    test -s /etc/modprobe.d/09-nvidia-modprobe-pm-G05.conf  || \
      cp 09-nvidia-modprobe-pm-G05.conf /etc/modprobe.d
    if [ ! -s /etc/dracut.conf.d/90-nvidia-dracut-G05.conf ]; then
      cp 90-nvidia-dracut-G05.conf /etc/dracut.conf.d/ && dracut -f
    fi
    test -s /etc/udev/rules.d/90-nvidia-udev-pm-G05.rules || \
      cp 90-nvidia-udev-pm-G05.rules /etc/udev/rules.d/
    Open an editor, or use vi, save above as say myscript, chmod 0755 myscript, then as root user (not sudo, switch to root user via su -) run it ./myscript
    Last edited by malcolmlewis; 09-Feb-2020 at 07:59.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3
    Join Date
    Jan 2017
    Location
    Nürnberg, Germany
    Posts
    221

    Default Re: How to add custom settings to initramfs?

    There are all kinds of neat optimizations you can achieve with dracut; for example,
    Code:
    dracut --hostonly --force --no-compress # run as root
    … tries to create an initrd that is customized to your box, without many of the unneeded drivers, boot-time services, scripts and other stuff omitted.

    You can also specify which of the numerous dracut tasks you won’t ever need in a /etc/dracut.conf.d/01-custom-for-my-box.conf (filename mostly arbitrary):
    Code:
    hostonly="yes"
    compress="cat"
    
    omit_dracutmodules+=" network kernel-network-modules ifcfg img-lib cifs fcoe fcoe-uefi rdma multipath iscsi qemu lvm mdraid dm dmraid cdrom pollcdrom plymouth btrfs wacom convertfs wicked ipv6 mtp-probe warpclock i18n crypt crypt-gpg cryptfs crypt-loop selinux "
    
    omit_drivers+=" usb-storage uas ums-* snd soundcore snd-* hid-wiimote wacom hv_vmbus rmi_core dm-mod iscsi_if iscsi_tcp dm_multipath parport pcmcia jsm cdrom serial pcspkr "
    As you can see, I omit a whole bunch needed only for servers, NAS/SAN stuff and older hardware (cdrom, pollcdrom); and who really needs sound while booting?!
    OTOH, you may need btrfs for booting from/mounting those types of filesystems, and crypt for block-/volume-level encryption, and so on. Your mileage may vary.

    I also never compress my initrd when booting from SSD (compress="cat" in the file above, or --no-compress for the command line), it boots far quicker that way. My fastest boots according to systemd-analyze were 1.143s (cold) and 1.199s (warm) from Grub to desktop manager+network (1 static IPv4 route to DSL router). Those are outliers, though — it's been more like slightly beneath 1.3s on average.

    Finally, to make sure your NVidia stuff has been packed into the initrd, you can list its contents with
    Code:
    lsinitrd | less -N # run as root
    Cheers!

  4. #4
    Join Date
    Sep 2012
    Posts
    5,318

    Default Re: How to add custom settings to initramfs?

    Quote Originally Posted by unix111 View Post
    There are all kinds of neat optimizations you can achieve with dracut; for example,
    Code:
    dracut --hostonly --force --no-compress # run as root
    Hostonly is default in openSUSE anyway; and disabling compression may result in significantly increased time required to load initrd by bootloader. So it is not clear what exactly is being optimized here.
    Finally, to make sure your NVidia stuff has been packed into the initrd
    The whole point of code discussed here is to avoid​ packing nVidia stuff in initrd.

  5. #5

    Default Re: How to add custom settings to initramfs?

    Quote Originally Posted by malcolmlewis View Post
    Hi
    There are three commands there, just copy/paste and run them as root user (switch to root user via su - );

    Code:
    test -s /etc/modprobe.d/09-nvidia-modprobe-pm-G05.conf  || cp 09-nvidia-modprobe-pm-G05.conf /etc/modprobe.d
    
    if [ ! -s /etc/dracut.conf.d/90-nvidia-dracut-G05.conf ]; then cp 90-nvidia-dracut-G05.conf /etc/dracut.conf.d/ && dracut -f fi
    
    test -s /etc/udev/rules.d/90-nvidia-udev-pm-G05.rules || cp 90-nvidia-udev-pm-G05.rules /etc/udev/rules.d/
    The above three commands do everything for you, the 'dracut' command will rebuild your initrd

    If you remove the trailing \ or you could just pop it in a bash script change permissions and run...

    Code:
    #!/bin/bash
    
    test -s /etc/modprobe.d/09-nvidia-modprobe-pm-G05.conf  || \
      cp 09-nvidia-modprobe-pm-G05.conf /etc/modprobe.d
    if [ ! -s /etc/dracut.conf.d/90-nvidia-dracut-G05.conf ]; then
      cp 90-nvidia-dracut-G05.conf /etc/dracut.conf.d/ && dracut -f
    fi
    test -s /etc/udev/rules.d/90-nvidia-udev-pm-G05.rules || \
      cp 90-nvidia-udev-pm-G05.rules /etc/udev/rules.d/
    Open an editor, or use vi, save above as say myscript, chmod 0755 myscript, then as root user (not sudo, switch to root user via su -) run it ./myscript
    Thank you very much, shortly after posting this message I realized I had totally missed the obvious: the code snippet was indeed to be executed from a Terminal. (Let me just point out that the script requires of course to be run from the actual directory containing the adequate files (i.e. 09-nvidia-modporobe...)

    One last question remains, however: Will I have to re-run this script upon every kernel update? (Well I guess NVIDIA proprietary drivers don't belong to Tumbleweed target repos so I will have to install them upon every kernel update too ... )
    Anyway, thanks for the reply !

  6. #6
    Join Date
    Sep 2012
    Posts
    5,318

    Default Re: How to add custom settings to initramfs?

    Quote Originally Posted by Merryn View Post
    Will I have to re-run this script upon every kernel update?
    No, you won't.

  7. #7
    Join Date
    Jan 2017
    Location
    Nürnberg, Germany
    Posts
    221

    Default Re: How to add custom settings to initramfs?

    Quote Originally Posted by arvidjaar View Post
    Hostonly is default in openSUSE anyway; and disabling compression may result in significantly increased time required to load initrd by bootloader. So it is not clear what exactly is being optimized here.
    On my system, boot time improves when the kernel isn’t busy uncompressing its initrd. As I wrote above: Your Mileage May Vary (YMMV), especially if you happen to boot from USB, network or rotating rust. On my SSD-based system, it makes a difference of about half a second. Best to try both ways, measure and compare.

    As for the dracut defaults — when I started with openSUSE 42.1 I don’t think »hostonly« was set as default back then, but I could be wrong.

    Quote Originally Posted by arvidjaar View Post
    The whole point of code discussed here is to avoid​ packing nVidia stuff in initrd.
    Ah, I see. My bad, I should have read OP more closely.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •