0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

grub を作り直す

Last updated at Posted at 2025-03-10

環境

  • Ubuntu 22.04 LTS
  • AMD64アーキテクチャ
  • Fujitsu TX1330 M2
  • SATA AHCIモード
  • 3.5インチ 2TBytes ハードディスク x 2
    • hd1 に OS 、データ、アプリなどシステム一式をインストール
    • hd0 を バックアップストレージとして設定

grub がヘン

Ubuntu 22.04 をインストールするときにうかうかしていて、変な設定になってしまった。

  • 3.5インチ ハードディスク の hd0, hd1 がつながっている状態で hd1 にシステムをインストールしてしまった。
    • 2台 接続していないと起動しなくなってしまった。
  • マシンの BIOS 設定が、Legacy ブートになってしまっている。本当は UEFI ブートにしたかった。

hd0 を取り外すと起動しない

/boot パーティション、 root パーティーションは hd1 にあるので、hd0 を取り外しても起動すると思っていたら・・・
image.png

error: unknown filesystem.
entering rescue mode...
grub rescue>

となり、grub 画面で止まってしまった。

grub コンソールを操作

grub rescue> ls
とすると、
(hd0) (hd0,msdos5) (hd0,msdos1)

となったので、

grub rescue> ls (hd0)
(hd0): Filesystem is unknown.
grub rescue> ls (hd0,msdos1)
(hd0,msdos1): Filesystem is unknown.
grub rescue> ls (hd0,msdos5)
(hd0,msdos1): Filesystem is ext2.

いけるかな?

grub rescue> set root=(hd0,msdos5)
grub rescue> set prefix=(hd0,msdos5)/boot/grub
grub rescue> insmod normal
error: symbol `grub_file_filters' not found.

うーん、うまくいかない。

Linux 上で grub の修復

HDD 構成をもとに戻して、Linuxを起動し直す。
その上で、以下のようにやってみる。

残したいハードディスクは hd1 であり、Linux デバイスとしては /dev/sda にあることが確認できた。その上で、

$ sudo grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
$ sudo update-grub

image.png

この状態で、 hd0 を外して起動し直したら Linux が立ち上がるようになった。

Legacy ブートを UEFI ブートに直す

先の修復も、i386-pc platform としての修復だったので UEFI ブートに直す。

まずは BIOS 設定で、Legacy となっていたのを UEFI and Legacy に変えて

image.png

Linux が起動したのを確認。

UEFI 対応ができていないので、

$ ls /boot/efi

としても空っぽ。
この状態で、

$ sudo grub-install --target=x86_64-efi /dev/sda

とすると

grub-install : エラー: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. Please spescify --target or --directory.

と出た。

UEFI 対応の grub に入れ替え

$ sudo apt-get -purge grub\*

として、以下のダイアログで「はい」とすると、

image.png
当然ながら結構いろいろと変化。

image.png
image.png

改めて、

$ sudo apt install grub-efi

念の為に

$ sudo apt autoremove
$ sudo update-grub

image.png

となりました。UEFI 対応のGRUBがインストールされたかな??

$ ls /boot/efi

としても空っぽなので、generate されたのは BIOS 用の grub らしいです。
改めて

$ sudo grub-install --target=x86_64-efi /dev/sda

とすると

Installing for x86_64-efi platform.
grub-install : 警告: EFI variables are not supported on this system..
Installation finushed. No error reported.

となりインストールされたみたいです。
この後BIOS設定を UEFI only とし、
image.png
無事UEFIで起動できるようになりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?