[Ubuntu / apt-get] apt-get が使えない - grub-efi-arm64-signed に関するエラーが出る時の対処

# 1. 症状

以下の通り、 `apt-get install` が機能していない。

```bash
$ sudo apt-get install zip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zip is already the newest version (3.0-11build1).
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up grub-efi-amd64-signed (1.187.6~20.04.1+2.06-2ubuntu14.4) ...
Unknown device "/dev/disk/by-id/*": No such file or directory
dpkg: error processing package grub-efi-amd64-signed (--configure):
 installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of shim-signed:
 shim-signed depends on grub-efi-amd64-signed (>= 1.187.2~) | grub-efi-arm64-signed (>= 1.187.2~); however:
  Package grub-efi-amd64-signed is not configured yet.
  Package grub-efi-arm64-signed is not installed.

dpkg: error processing package shim-signed (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                              Errors were encountered while processing:
 grub-efi-amd64-signed
 shim-signed
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

**grub** 関連に問題があるようなので、その辺りの対処をしていく。


# 2. 注意事項

:::note warn
**grub** は OS の起動を司るモジュールであり、これをいじることにより、**マシンがそもそも起動できなくなるおそれもある**。
:::


このようなかなり危険な操作でもあるため、マシンのバックアップをとっておくか、又は壊しても構わないマシンで実施するなどが良いと思います。

環境によってうまくいく、いかないが分かれることもあるかと思いますので、自己責任で実施されてください！>_<;


# 3. 環境情報

```bash
$ apt-get --version
apt 2.0.10 (amd64)
```

```bash
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal
```


# 4. 対処法

以下の記事に、解決策が埋もれていました。

https://bugs.launchpad.net/ubuntu/+source/grub2-signed/+bug/1995753

この記事の #6 のメッセージによると、以下の二つのコマンドで解決するらしい。

- sudo apt remove grub-efi-amd64-signed grub-efi-amd64-bin
- sudo update-grub

実行した結果が以下の通り。

```bash
$ sudo apt remove grub-efi-amd64-signed grub-efi-amd64-bin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  grub-common grub2-common mokutil os-prober
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  grub-efi-amd64 grub-efi-amd64-bin grub-efi-amd64-signed shim-signed
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  shim-signed grub-efi-amd64-signed (due to shim-signed)
0 upgraded, 0 newly installed, 4 to remove and 22 not upgraded.
2 not fully installed or removed.
After this operation, 22.5 MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
 ?] 
```

ここで一度処理が止まるので、メッセージをよく読んで、 OK なら `Yes, do as I say!` と入力して Enter キーを押そう。

```bash
 ?] Yes, do as I say!
(Reading database ... 157190 files and directories currently installed.)
Removing shim-signed (1.40.10+15.8-0ubuntu1) ...
Removing grub-efi-amd64-signed (1.187.6~20.04.1+2.06-2ubuntu14.4) ...
Removing grub-efi-amd64 (2.06-2ubuntu14.4) ...
Removing grub-efi-amd64-bin (2.06-2ubuntu14.4) ...
```

1コマンド目はここで終了。
次に以下のコマンドを実行する。

```bash
$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-200-generic
Found initrd image: /boot/initrd.img-5.4.0-200-generic
Found linux image: /boot/vmlinuz-5.4.0-196-generic
Found initrd image: /boot/initrd.img-5.4.0-196-generic
Adding boot menu entry for UEFI Firmware Settings
done
```

さて、本当に `apt-get` を使えるようになったのか、確認してみよう！


```bash
$ sudo apt-get install zip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zip is already the newest version (3.0-11build1).
The following packages were automatically installed and are no longer required:
  grub-common grub2-common mokutil os-prober
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.
```

`sudo apt autoremove` 実行してと書いてあるので、素直に従うことにしました(\*˘︶˘\*)

```
$ sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  grub-common grub2-common mokutil os-prober
0 upgraded, 0 newly installed, 4 to remove and 22 not upgraded.
After this operation, 15.2 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 156868 files and directories currently installed.)
Removing grub2-common (2.04-1ubuntu26.17) ...
Removing os-prober (1.74ubuntu2) ...
Removing grub-common (2.04-1ubuntu26.17) ...
Removing mokutil (0.6.0-2~20.04.2) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...
Processing triggers for man-db (2.9.1-1) ...
```

OK みたいだね！
一応、もう一回 apt-get の動作を確認しておこう。

```bash
$ sudo apt-get install zip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zip is already the newest version (3.0-11build1).
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.
```

# 5. References

## GRUB について解説している記事

ちょっとわかりやすい。

https://gihyo.jp/admin/serial/01/ubuntu-recipe/0743

## 対処法が載っていた記事 (Q&Aサイト)

https://bugs.launchpad.net/ubuntu/+source/grub2-signed/+bug/1995753

## その他の対処法

この記事でも、同じ問題に対処されていた。

https://zenn.dev/shosampo/articles/4bff9a92c02898

色々と書いてあったのだけれど、

> 私の場合、以下の grub-efi/install_devicesとgrub-efi/install_devices_disks_changed のブロックを削除しました：

という部分で、その2つを削除することにした理由や根拠が書かれていなかったので、自分は真似しようと思えなかった。