vtoyboot
vtoyboot copied to clipboard
take argument to specify kernel or handle the case when the currently running kernel is uninstalled from disk
Description
make ./vtoyboot.sh to
take argument to specify kernel
and/or
handle the case when the currently running kernel is uninstalled from disk by finding and using the next-best-available or latest kernel.
The error message thrown will be something like
dracut: Cannot find module directory /lib/modules/6.0.12-300.fc37.x86_64/
dracut: and --no-kernel was not specified
Steps to reproduce
- Uninstall current kernel
rpm -e `rpm -qa | grep -Ei "6.0.12-300" `
. Ensure its module tree no longer exists in/lib/modules/
- Install new kernel
dnf update kernel
- run
./vtoyboot.sh
- vtoyboot.sh will barf in the
distros/*/check.sh
scripts Specifically the commanddracut --list-modules
does not work if--kver <ker-rel-ver>
is not specified See log below: I have dnf upgraded to 6.0.15 but uninstalled the currently running 6.0.12. Not yet rebooted.
Log
[root@sirius bin]# cat /etc/os-release | head -2
NAME="Fedora Linux"
VERSION="37 (Workstation Edition)"
[root@sirius ~]$ uname -a
Linux sirius 6.0.12-300.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 8 16:58:47 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@sirius ~]$ dracut --list-modules | grep -Ei dm
dracut: Cannot find module directory /lib/modules/6.0.12-300.fc37.x86_64/
dracut: and --no-kernel was not specified
[root@sirius ~]$ rpm -qa | grep kernel-6
kernel-6.0.11-200.fc36.x86_64
kernel-6.0.15-300.fc37.x86_64
[root@sirius bin]# dracut --list-modules --kver 6.0.15-300.fc37.x86_64 | grep -Ei dm
rdma
dm
dmraid
dmsquash-live
dmsquash-live-autooverlay
dmsquash-live-ntfs
[root@fedora vtoyboot-1.0.25]# find distros -name check.sh
distros/initramfstool/check.sh
distros/dracut/check.sh
distros/mkinitcpio/check.sh
[root@fedora vtoyboot-1.0.25]# cat distros/dracut/check.sh
#!/bin/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
vtoy_check_dracut() {
if which dracut >/dev/null 2>&1; then
if dracut --list-modules | grep -q '^dm$'; then
[ -n "1" ]; return
fi
fi
[ -z "1" ]
}
Workaround
- Install new kernel first, reboot to it to make it current running kernel. then run vtoyboot.sh
- You could say do this always, but then this easy case could also be handled by the shell script. Though reboot has to be done, one can choose to defer it till later, saves work of having to reboot right away. Saves one extra reboot, because usually after vtoyboot updates initramfs, it is prudent to reboot once anyway and ensure OS is still bootable, and do any fixes while mind is still fresh.
Explanation of how this situation arises
As mine is a home machine, I sometimes take some liberty in upgrading the kernel in a way that may be frowned upon from a enterprise-grade robust upgrade/migration strategy point of view.
Fedora dnf
package manager by default allows keeping of 3 kernels. While this number is configurable, more images take more space in the small boot partition.
When upgrading a new kernel, dnf, by default, usually first-in-first-out-pops-out (uninstalls) the oldest kernel.
Usually, I am okay with this.
I put an exclude=kernel*
in the /etc/dnf/dnf.conf
and manage my kernel upgrades at a time convenient to me.
Sometimes, I want get the latest kernel, but I choose to dispose of a kernel other than the oldest, because the oldest might actually be the most stable or I have built it with some customization.
So, before upgrade, I first uninstall a kernel other than the oldest, one of the first two, one of which is the current running kernel. Then I do the upgrade, ie dnf install a new kernel.
This ensures that there are again 3 kernels to choose to boot with on the next reboot. Therefore dnf does not automatically uninstall a kernel that I wanted to keep around.
Surprising though it might seem, Linux runs fine even when one has uninstalled the running kernel as it is already loaded to memory. The only trouble in doing so is that external kernel-modules no longer exist on disk to load/unload. Usually, one does not intend to remain this way for long and one intends to reboot immediately to the new kernel. But suppose one forgot and chose to keep running this way, then one will be surprised when, say, one inserts a USB dongle with ExFAT partitions and one wonders why the USB volume is not mounting. It will be because the ExFAT kernel-module does not exist in its kernel module directory to be loaded.
[root@sirius bin]# find /lib/modules/6.0.15-300.fc37.x86_64/kernel/fs/ | grep exfat
/lib/modules/6.0.15-300.fc37.x86_64/kernel/fs/exfat
/lib/modules/6.0.15-300.fc37.x86_64/kernel/fs/exfat/exfat.ko.xz
additionally print kernel version no of first kernel initramfs being generated
When running ./vtoyboot.sh
, the first messages it prints includes
Current system use dracut as initramfs tool
updating the initramfs, please wait ...
It would be useful/informative to predetermine which default kernel version that dracut will prepare initramfs for and print its kernel version.
dracut proceeds to update initramfs for other kernels. The subsequent message contains their version numbers.
updating initramfs for 6.0.12-200.fc36..x86_64 please wait ...
: