Bash find most recent LTS version

Hi @P1000,

You can check perform kernel installation, checking and more with the mhwd-kernel command:

To list all installed kernels:

$ sudo mhwd-kernel -li

Currently running: 5.10.7-3-MANJARO (linux510)
The following kernels are installed in your system:
* linux510
* linux54

To list all available kernels

$ sudo mhwd-kernel -l

available kernels:
* linux414
* linux419
* linux44
* linux49
* linux510
* linux511
* linux54
* linux59
* linux54-rt
* linux59-rt

To install a kernel:

$ sudo mhwd-kernel -i <kernel_version>

For example:

$ sudo mhwd-kernel -i linux419
[sudo] password for mirdarthos: 

:: Synchronising package databases...
core                                                                                                      167.6 KiB   185 KiB/s 00:01 [----------------------------------------------------------------------------------] 100%
extra                                                                                                    1993.3 KiB  2.01 MiB/s 00:01 [----------------------------------------------------------------------------------] 100%
community                                                                                                   6.4 MiB  6.83 MiB/s 00:01 [----------------------------------------------------------------------------------] 100%
multilib                                                                                                  181.8 KiB  17.7 MiB/s 00:00 [----------------------------------------------------------------------------------] 100%
resolving dependencies...
looking for conflicting packages...

Packages (3) linux419-4.19.167-1  linux419-headers-4.19.167-1  linux419-nvidia-460.32.03-3

Total Download Size:   108.72 MiB
Total Installed Size:  190.69 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
linux419-4.19.167-1-x86_64                                                                                 74.7 MiB  10.0 MiB/s 00:07 [----------------------------------------------------------------------------------] 100%
linux419-headers-4.19.167-1-x86_64                                                                          8.8 MiB  13.3 MiB/s 00:01 [----------------------------------------------------------------------------------] 100%
linux419-nvidia-460.32.03-3-x86_64                                                                         25.2 MiB  12.7 MiB/s 00:02 [----------------------------------------------------------------------------------] 100%
(3/3) checking keys in keyring                                                                                                         [----------------------------------------------------------------------------------] 100%
(3/3) checking package integrity                                                                                                       [----------------------------------------------------------------------------------] 100%
(3/3) loading package files                                                                                                            [----------------------------------------------------------------------------------] 100%
(3/3) checking for file conflicts                                                                                                      [----------------------------------------------------------------------------------] 100%
(3/3) checking available disk space                                                                                                    [----------------------------------------------------------------------------------] 100%
:: Processing package changes...
(1/3) installing linux419                                                                                                              [----------------------------------------------------------------------------------] 100%
Optional dependencies for linux419
crda: to set the correct wireless channels of your country [installed]
(2/3) installing linux419-headers                                                                                                      [----------------------------------------------------------------------------------] 100%
(3/3) installing linux419-nvidia                                                                                                       [----------------------------------------------------------------------------------] 100%
In order to use nvidia module, reboot the system.
:: Running post-transaction hooks...
(1/5) Arming ConditionNeedsUpdate...
(2/5) Updating module dependencies...
(3/5) Updating linux initcpios...
==> Building image from preset: /etc/mkinitcpio.d/linux419.preset: 'default'
-> -k /boot/vmlinuz-4.19-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.19-x86_64.img
==> Starting build: 4.19.167-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [autodetect]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.19-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux419.preset: 'fallback'
-> -k /boot/vmlinuz-4.19-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.19-x86_64-fallback.img -S autodetect
==> Starting build: 4.19.167-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.19-x86_64-fallback.img
==> Image generation successful
(4/5) Updating Kernel initcpios for Nvidia-DRM...
==> Building image from preset: /etc/mkinitcpio.d/linux419.preset: 'default'
-> -k /boot/vmlinuz-4.19-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.19-x86_64.img
==> Starting build: 4.19.167-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [autodetect]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.19-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux419.preset: 'fallback'
-> -k /boot/vmlinuz-4.19-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-4.19-x86_64-fallback.img -S autodetect
==> Starting build: 4.19.167-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-4.19-x86_64-fallback.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'default'
-> -k /boot/vmlinuz-5.10-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-5.10-x86_64.img
==> Starting build: 5.10.7-3-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [autodetect]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.10-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'fallback'
-> -k /boot/vmlinuz-5.10-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-5.10-x86_64-fallback.img -S autodetect
==> Starting build: 5.10.7-3-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.10-x86_64-fallback.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux54.preset: 'default'
-> -k /boot/vmlinuz-5.4-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-5.4-x86_64.img
==> Starting build: 5.4.89-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [autodetect]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.4-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux54.preset: 'fallback'
-> -k /boot/vmlinuz-5.4-x86_64 -c /etc/mkinitcpio.conf -g /boot/initramfs-5.4-x86_64-fallback.img -S autodetect
==> Starting build: 5.4.89-1-MANJARO
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.4-x86_64-fallback.img
==> Image generation successful
(5/5) Updating Grub-Bootmenu
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/Stylish/theme.txt
Found linux image: /boot/vmlinuz-5.10-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.10-x86_64.img
Found initrd fallback image: /boot/initramfs-5.10-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.4-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.4-x86_64.img
Found initrd fallback image: /boot/initramfs-5.4-x86_64-fallback.img
Found linux image: /boot/vmlinuz-4.19-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-4.19-x86_64.img
Found initrd fallback image: /boot/initramfs-4.19-x86_64-fallback.img
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
/usr/bin/grub-probe: warning: unknown device type nvme0n1.
done

To remove a kernel:

$ sudo mhwd-kernel -r <kernel_version>

For example:

$ sudo mhwd-kernel -r linux419

checking dependencies...

Packages (3) linux419-4.19.167-1  linux419-headers-4.19.167-1  linux419-nvidia-460.32.03-3

Total Removed Size:  190.69 MiB

:: Do you want to remove these packages? [Y/n]
:: Running pre-transaction hooks...
(1/1) Removing linux initcpios...
:: Processing package changes...
(1/3) removing linux419-nvidia                                                                                                         [----------------------------------------------------------------------------------] 100%
(2/3) removing linux419-headers                                                                                                        [----------------------------------------------------------------------------------] 100%
(3/3) removing linux419                                                                                                                [----------------------------------------------------------------------------------] 100%
:: Running post-transaction hooks...
(1/3) Arming ConditionNeedsUpdate...
(2/3) Updating module dependencies...
(3/3) Updating Grub-Bootmenu
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/Stylish/theme.txt
Found linux image: /boot/vmlinuz-5.10-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.10-x86_64.img
Found initrd fallback image: /boot/initramfs-5.10-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.4-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.4-x86_64.img
Found initrd fallback image: /boot/initramfs-5.4-x86_64-fallback.img
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
/usr/bin/grub-probe: warning: unknown device type nvme0n1.
done

For more info:

$ sudo mhwd-kernel -h

Usage: mhwd-kernel [option]
-h  --help              Show this help message
-i  --install           Install a new kernel        [kernel(s)] [optional: rmc = remove current kernel]
-l  --list              List all available kernels
-li --listinstalled     List installed kernels
-r  --remove            Remove a kernel             [kernel(s)]

Hope this helps!

3 Likes