差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン | |||
| linux:fedora:update_rescue_kernel [2024/02/04 13:48] – 削除 - 外部編集 (Unknown date) 非ログインユーザー | linux:fedora:update_rescue_kernel [2024/02/04 13:48] (現在) – ↷ linux:fedora_update_rescue_kernel から linux:fedora:update_rescue_kernel へページの移動と名称変更しました。 ともやん | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== Fedora Rescue カーネルのアップデート ====== | ||
| + | Fedora のレスキュー用のカーネル(vmlinuz) と RAM ディスク(initramfs) を更新する方法を記載する。\\ | ||
| + | \\ | ||
| + | 結論から言うと以下のコマンドを実行すると Fedora 29 では上手く行きました。\\ | ||
| + | < | ||
| + | $ sudo rm / | ||
| + | $ sudo kernel-install add $(uname -r) / | ||
| + | $ sudo grub2-mkconfig -o / | ||
| + | </ | ||
| + | ※**grub2-mkconfig -o** で指定する grub.cfg の位置は UEFI ブート環境の場合 OS によって違います。\\ | ||
| + | UEFIブート環境以外場合は **/ | ||
| + | UEFIブート環境の場合、RHEL では **/ | ||
| + | UEFIブート環境の場合、CentOS では **/ | ||
| + | \\ | ||
| + | [[https:// | ||
| + | また、以下の kernel-install スクリプトによって dracut-config-rescue パッケージのスクリプトが呼び出されて、レスキューカーネルが生成される様である。\\ | ||
| + | < | ||
| + | $ kernel-install add 4.17.5-200.fc28.x86_64 / | ||
| + | </ | ||
| + | kernel-install スクリプトは /usr/bin にありました。\\ | ||
| + | < | ||
| + | $ which kernel-install | ||
| + | / | ||
| + | $ cat / | ||
| + | </ | ||
| + | <file bash / | ||
| + | # | ||
| + | # -*- mode: shell-script; | ||
| + | # ex: ts=8 sw=4 sts=4 et filetype=sh | ||
| + | # SPDX-License-Identifier: | ||
| + | # | ||
| + | # This file is part of systemd. | ||
| + | # | ||
| + | # Copyright © 2013 Harald Hoyer | ||
| + | # | ||
| + | # systemd is free software; you can redistribute it and/or modify it | ||
| + | # under the terms of the GNU Lesser General Public License as published by | ||
| + | # the Free Software Foundation; either version 2.1 of the License, or | ||
| + | # (at your option) any later version. | ||
| + | # | ||
| + | # systemd 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 Lesser General Public License | ||
| + | # along with systemd; If not, see < | ||
| + | |||
| + | SKIP_REMAINING=77 | ||
| + | |||
| + | usage() | ||
| + | { | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | } | ||
| + | |||
| + | dropindirs_sort() | ||
| + | { | ||
| + | local suffix=$1; shift | ||
| + | local -a files | ||
| + | local f d i | ||
| + | |||
| + | readarray -t files <<<" | ||
| + | for d in " | ||
| + | for i in " | ||
| + | if [[ -e " | ||
| + | echo " | ||
| + | fi | ||
| + | done | ||
| + | done | sort -Vu | ||
| + | )" | ||
| + | |||
| + | for f in " | ||
| + | for d in " | ||
| + | if [[ -e " | ||
| + | echo " | ||
| + | continue 2 | ||
| + | fi | ||
| + | done | ||
| + | done | ||
| + | } | ||
| + | |||
| + | export LC_COLLATE=C | ||
| + | |||
| + | for i in " | ||
| + | if [ " | ||
| + | usage | ||
| + | exit 0 | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | if [[ " | ||
| + | COMMAND=' | ||
| + | else | ||
| + | COMMAND=" | ||
| + | shift | ||
| + | fi | ||
| + | |||
| + | KERNEL_VERSION=" | ||
| + | KERNEL_IMAGE=" | ||
| + | |||
| + | if [[ -f / | ||
| + | read MACHINE_ID < / | ||
| + | fi | ||
| + | |||
| + | if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then | ||
| + | echo "Not enough arguments" | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | if ! [[ $MACHINE_ID ]]; then | ||
| + | BOOT_DIR_ABS=$(mktemp -d / | ||
| + | trap "rm -rf ' | ||
| + | elif [[ -d / | ||
| + | BOOT_DIR_ABS="/ | ||
| + | elif [[ -d / | ||
| + | BOOT_DIR_ABS="/ | ||
| + | elif [[ -d / | ||
| + | BOOT_DIR_ABS="/ | ||
| + | elif mountpoint -q /efi; then | ||
| + | BOOT_DIR_ABS="/ | ||
| + | elif mountpoint -q /boot/efi; then | ||
| + | BOOT_DIR_ABS="/ | ||
| + | else | ||
| + | BOOT_DIR_ABS="/ | ||
| + | fi | ||
| + | |||
| + | export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID | ||
| + | |||
| + | ret=0 | ||
| + | |||
| + | readarray -t PLUGINS <<<" | ||
| + | dropindirs_sort " | ||
| + | "/ | ||
| + | "/ | ||
| + | )" | ||
| + | |||
| + | case $COMMAND in | ||
| + | add) | ||
| + | if [[ ! " | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | mkdir -p " | ||
| + | echo "Could not create boot directory ' | ||
| + | exit 1 | ||
| + | } | ||
| + | |||
| + | for f in " | ||
| + | if [[ -x $f ]]; then | ||
| + | " | ||
| + | x=$? | ||
| + | if [[ $x == $SKIP_REMAINING ]]; then | ||
| + | ret=0 | ||
| + | break | ||
| + | fi | ||
| + | ((ret+=$x)) | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | if ! [[ $MACHINE_ID ]] && ! rmdir " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | rm -rf " | ||
| + | ((ret+=$?)) | ||
| + | fi | ||
| + | ;; | ||
| + | |||
| + | remove) | ||
| + | for f in " | ||
| + | if [[ -x $f ]]; then | ||
| + | " | ||
| + | x=$? | ||
| + | if [[ $x == $SKIP_REMAINING ]]; then | ||
| + | ret=0 | ||
| + | break | ||
| + | fi | ||
| + | ((ret+=$x)) | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | rm -rf " | ||
| + | ((ret+=$?)) | ||
| + | ;; | ||
| + | |||
| + | *) | ||
| + | echo " | ||
| + | exit 1 | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | exit $ret | ||
| + | </ | ||
| + | PLUGINS として / | ||
| + | < | ||
| + | $ ll / | ||
| + | -rw-r--r-- 1 root root 0 10月 5 06:22 20-grubby.install | ||
| + | -rw-r--r-- 1 root root 0 10月 5 06:22 90-loaderentry.install | ||
| + | </ | ||
| + | < | ||
| + | $ ll / | ||
| + | -rwxr-xr-x 1 root root 1662 1月 30 01:05 10-devicetree.install | ||
| + | -rwxr-xr-x 1 root root 5368 10月 5 06:22 20-grub.install | ||
| + | -rwxr-xr-x 1 root root 1905 2月 8 17:08 20-grubby.install | ||
| + | -rwxr-xr-x 1 root root 424 2月 8 03:14 50-depmod.install | ||
| + | -rwxr-xr-x 1 root root 1719 12月 4 19:27 50-dracut.install | ||
| + | -rwxr-xr-x 1 root root 3391 12月 4 19:27 51-dracut-rescue.install | ||
| + | -rwxr-xr-x 1 root root 2106 2月 8 03:14 90-loaderentry.install | ||
| + | </ | ||
| + | dracut-config-rescue-048 は壊れていて動作しないとの事なので確認したところ 049 だったので大丈夫そうである。\\ | ||
| + | < | ||
| + | $ rpm -qa | grep dracut-config-rescue | ||
| + | dracut-config-rescue-049-25.git20181204.fc29.x86_64 | ||
| + | </ | ||
| + | dracut-config-rescue パッケージには以下のファイルが含まれている。\\ | ||
| + | < | ||
| + | $ rpm -ql dracut-config-rescue | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | </ | ||
| + | PLUGINS として呼び出される 51-dracut-rescue.install は以下の様になっている。\\ | ||
| + | < | ||
| + | $ cat / | ||
| + | </ | ||
| + | <file bash / | ||
| + | # | ||
| + | |||
| + | export LANG=C | ||
| + | |||
| + | COMMAND=" | ||
| + | KERNEL_VERSION=" | ||
| + | BOOT_DIR_ABS=" | ||
| + | KERNEL_IMAGE=" | ||
| + | |||
| + | |||
| + | dropindirs_sort() | ||
| + | { | ||
| + | suffix=$1; shift | ||
| + | args=(" | ||
| + | files=$( | ||
| + | while (( $# > 0 )); do | ||
| + | for i in ${1}/ | ||
| + | [[ -f $i ]] && echo ${i##*/} | ||
| + | done | ||
| + | shift | ||
| + | done | sort -Vu | ||
| + | ) | ||
| + | |||
| + | for f in $files; do | ||
| + | for d in " | ||
| + | if [[ -f " | ||
| + | echo " | ||
| + | continue 2 | ||
| + | fi | ||
| + | done | ||
| + | done | ||
| + | } | ||
| + | |||
| + | [[ -f / | ||
| + | |||
| + | if [[ ${KERNEL_INSTALL_MACHINE_ID+x} ]]; then | ||
| + | MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID | ||
| + | elif [[ -f / | ||
| + | read MACHINE_ID < / | ||
| + | fi | ||
| + | |||
| + | if ! [[ $MACHINE_ID ]]; then | ||
| + | exit 0 | ||
| + | fi | ||
| + | |||
| + | if [[ -f / | ||
| + | read -r -d '' | ||
| + | elif [[ -f / | ||
| + | read -r -d '' | ||
| + | fi | ||
| + | |||
| + | if ! [[ " | ||
| + | read -r -d '' | ||
| + | for i in " | ||
| + | [[ " | ||
| + | BOOT_OPTIONS+=(" | ||
| + | done | ||
| + | fi | ||
| + | |||
| + | if ! [[ ${BOOT_OPTIONS[*]} ]]; then | ||
| + | echo "Could not determine the kernel command line parameters." | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | if [[ -d " | ||
| + | BOOT_DIR="/ | ||
| + | BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR} | ||
| + | LOADER_ENTRY=" | ||
| + | KERNEL=" | ||
| + | INITRD=" | ||
| + | else | ||
| + | BLS_DIR="/ | ||
| + | BOOT_DIR_ABS="/ | ||
| + | LOADER_ENTRY=" | ||
| + | KERNEL=" | ||
| + | INITRD=" | ||
| + | fi | ||
| + | |||
| + | ret=0 | ||
| + | |||
| + | case " | ||
| + | add) | ||
| + | [[ -f " | ||
| + | && [[ -f " | ||
| + | |||
| + | # source our config dir | ||
| + | for f in $(dropindirs_sort " | ||
| + | [[ -e $f ]] && . " | ||
| + | done | ||
| + | |||
| + | [[ $dracut_rescue_image != " | ||
| + | |||
| + | [[ -d " | ||
| + | |||
| + | if ! cp --reflink=auto " | ||
| + | echo " | ||
| + | fi | ||
| + | |||
| + | if [[ ! -f " | ||
| + | dracut -f --no-hostonly -a " | ||
| + | ((ret+=$?)) | ||
| + | fi | ||
| + | |||
| + | if [[ " | ||
| + | { | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | } > $LOADER_ENTRY | ||
| + | else | ||
| + | cp -aT " | ||
| + | sed -i ' | ||
| + | fi | ||
| + | |||
| + | ((ret+=$?)) | ||
| + | ;; | ||
| + | |||
| + | remove) | ||
| + | exit 0 | ||
| + | ;; | ||
| + | |||
| + | *) | ||
| + | usage | ||
| + | ret=1;; | ||
| + | esac | ||
| + | |||
| + | exit $ret | ||
| + | </ | ||
| + | initramfs-0-rescue-${MACHINE_ID}.img が存在しない場合に dracut による生成を行う様である。\\ | ||
| + | <code bash> | ||
| + | if [[ ! -f " | ||
| + | dracut -f --no-hostonly -a " | ||
| + | ((ret+=$?)) | ||
| + | fi | ||
| + | </ | ||
| + | initramfs-0-rescue-${MACHINE_ID}.img と vmlinuz-0-rescue-${MACHINE_ID} を削除して、kernel-install スクリプトを以下の様に呼び出してみる事にしました。\\ | ||
| + | < | ||
| + | $ sudo rm / | ||
| + | $ sudo kernel-install add $(uname -r) / | ||
| + | </ | ||
| + | initramfs-0-rescue-${MACHINE_ID}.img と vmlinuz-0-rescue-${MACHINE_ID} が新しい日付で再生成されました。\\ | ||
| + | < | ||
| + | $ ll / | ||
| + | -rw------- 1 root root 72370961 | ||
| + | -rwxr-xr-x 1 root root 8753352 | ||
| + | </ | ||
| + | 再起動してみると grub2 のメニューエントリーが以下の様になってしまいました。\\ | ||
| + | Fedora 29 Rescue が先頭に来ています。\\ | ||
| + | < | ||
| + | Fedora 29 Rescue 74a4a050fda14b66a30a52debdd88dfe (4.20.8-200.fc29.x86_64) | ||
| + | Fedora (4.20.8-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.20.7-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.20.6-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.4.3-300.fc23.x86_64) 23 (Workstation Edition) | ||
| + | Fedora (4.2.5-300.fc23.x86_64) 23 (Workstation Edition) | ||
| + | Fedora (0-rescue-74a4a050fda14b66a30a52debdd88dfe) 23 (Workstation Edition) | ||
| + | </ | ||
| + | grub2-mkconfig で grub2 のメニューエントリーを再生成してみる事にしました。\\ | ||
| + | < | ||
| + | $ sudo grub2-mkconfig -o / | ||
| + | Generating grub configuration file ... | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found Windows Boot Manager on / | ||
| + | Adding boot menu entry for EFI firmware configuration | ||
| + | done | ||
| + | </ | ||
| + | grub2-mkconfig で再生成した grub2 のメニューエントリーは以下の様になっており大丈夫でした。\\ | ||
| + | < | ||
| + | Fedora (4.20.8-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.20.7-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.20.6-200.fc29.x86_64) 29 (Workstation Edition) | ||
| + | Fedora (4.4.3-300.fc23.x86_64) 23 (Workstation Edition) | ||
| + | Fedora (4.2.5-300.fc23.x86_64) 23 (Workstation Edition) | ||
| + | Fedora (0-rescue-74a4a050fda14b66a30a52debdd88dfe) 29 (Workstation Edition) | ||
| + | Windows Boot Manager (on /dev/sda2) | ||
| + | System setup | ||
| + | </ | ||
| + | |||
| + | ===== 参考文献 ===== | ||
| + | [[https:// | ||
| + | [[http:// | ||