KVM上の仮想ホスト(CentOS 7)の電源を入れるとOSが起動せず、
[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions ~ 略 ~]
grub>
のような黒い画面になったときの話です。
↑はイメージです(CentOS 6.7)
ネットを検索して次の 1)~4)を試してみても状態が変わらず、CeontOSのインストールイメージ(DVD)のレスキューモードを起動し、ブートローダーの再インストールを実行後、再度 1)~4)の grub> 操作を実行したら正常起動しました。
※ CentOS7?から GRUB2 になったらしい。 ※ 起動しなくなったCentOSのパーティション構成はこんな感じです。 /dev/vda1=/boot /dev/vda2=swap /dev/vda3=/ /dev/hda IDEタイプHDD /dev/sda SCSIタイプHDD /dev/vda 仮想ディスク ※ lsコマンドでディレクトリを表示できます。 例1)grub> ls (hd0) (hd0,abc3) (hd0,abc2) (hd0,abc1) …grubのコマンド入力時は(hd0,abc1)としなくても(hd0,1)と後ろの数字だけでも良いみたいです。 例2)grub> ls (hd0,abc3)/etc など ※ (hd0,1)は /grub や /vmlinuz-xxxx や initramfs-xxx.img が格納されていた。 hd0 はHDDの番号(ディスクが1本しかないならhd0)、0はパーティション番号 /dev/vda1…(hd0,1) /dev/vda2…(hd0,2) /dev/vda3…(hd0,3) ※catコマンドでファイルの中身が表示できます。 例)grub> cat (hd0,abc3)/etc/fstab など ※ grub> cat /grub2/grub.cfg は空ファイルだった。 1)rootを設定 これをすると (hd0,1) と打たなくても / と打てば通じるようになる。 ←これはやらなかったかもしれない。 grub> set root=(hd0,1) 2)起動するカーネルを指定する。ここで指定するrootはCentOSのルート(/)のパーティション ro は read onlyの意かな? grub> linux (hd0,1)/vmlinuz-3.33.3-33-xxx root=/dev/vda3 ro 3)カーネルと同じバージョンのinitrdファイルを指定する。 grub> initrd /boot/initramfs-3.33.3-33.img 4)システムをブートする。 grub> boot 4.5) 症状が変わらなかったので↓のブートローダーの再インストールを実施。再度ここの 1)か2)からやり直した。 5)(OS正常起動後)GRUBを修正? 起動メニューを反映? ←これは必須なのか不明だが一応実行した。 # grub2-mkconfig -o /boot/grub2/grub.cfg
CentOSインストールイメージの最初のメニュー画面です。
「Troubleshooting」を選択します。
「Rescue a CentOS system」を選択します。
---------------------------------------------------------------------- The rescue environment will now attempt to find your Linux installation and mount it under the directory : /mnt/sysimage. You can then make any changes required to your system. Choose '1' to proceed with this step. You can choose to mount your file systems read-only instead of read-write by choosing '2'. If for some reason this process does not work choose '3' to skip directly to a shell. 1) Continue 2) Read-only mount 3) Skip to shell 4) Quit (Reboot) Please make a sekection from the above: ---------------------------------------------------------------------- 簡単に説明すると、 「Continue」を選択するとファイルシステム(CentOSのルート)を /mnt/sysimage/ ディレクトリに読み書きできる状態でマウント。 「Read-only mount」を選択すると読み取り専用モードでマウント。 「Skip to shell」を選択するとマウントしない(ファイルシステムが破損していると思われる場合はこれを選択)。 「Quit (Reboot)」を選択すると再起動。 ------- 詳しくは Redhatサイトをご参照) https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-rescue-mode.html
1 (Continue)を選択。
「return」キーを押せと言っているので押します。
1)root ディレクトリを /mnt/sysimage/ に変更。 sh-4.2# chroot /mnt/sysimage/ ※ fdiskコマンドでデバイスの構成が分かるかもしれません。 # fdisk -l ~ 省略 ~ デバイス ブート 始点 終点 ブロック Id システム /dev/vda1 * 2048 976895 487424 83 Linux /dev/vda2 976896 4882431 1952768 82 Linux swap / Solaris /dev/vda3 4882432 125820927 60469248 83 Linux 2)GRUB2 ブートローダーを再インストール。ここで install_device はブートデバイス (通常は /dev/sda だけど今回はVM環境なので/dev/vda) ※ 後ろの数字は付けない! /dev/vda1などとはしない。 sh-4.2# /sbin/grub2-install install_device 3)再起動 exit exit この後↑のGRUB操作 1)~5) or 2)~5)を実行して正常起動するか確認。
この症状が出る前にネットワークドライブをOS起動時にマウントしようと /etc/fstab を修正したため(記述ミスがあったと思われる)、これが原因になったのだろうか…。と思い、レスキューモードで起動し、CentOSのルートを /mnt/sysimage/ にマウントしたときにviコマンドで該当部分を削除しておいた。以後、/etc/fstab 編集時は # mount -a コマンドで内容が正しく反映されるか確認している。
GRUB)
https://jp.linux.com/news/linuxcom-exclusive/418274-lco20140625
ブートローダーの再インストール)
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-rescue-mode.html