/boot パーティションをルートパーティションにマージする方法

/boot パーティションをルートパーティションにマージする方法

/bootプライベートパーティションを削除してルートパーティションにマージしようとしています/。私が見つけたhttps://askubuntu.com/questions/741672/how-do-i-merge-my-boot-partition-to-be-a-part-of-the-partitionすでにありますが、それは役に立たないようです。

状況はどうですか?

# uname -a
Linux c02 6.1.0-12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.52-1 (2023-09-07) x86_64 GNU/Linux

# fdisk -l /dev/sda
Disk /dev/sda: 4 TiB, 4398046511104 bytes, 8589934592 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 1673AA12-2A54-4718-AF1E-58FE670A87E3

Device        Start        End    Sectors  Size Type
/dev/sda1      2048       4095       2048    1M BIOS boot
/dev/sda2      4096    2007039    2002944  978M Linux filesystem
/dev/sda3   2007040   10008575    8001536  3.8G Linux swap
/dev/sda4  10008576 8589932543 8579923968    4T Linux filesystem

次の操作でマシンを正常に再起動できました。

# copy content of boot partition to root
cp -a /boot /boot.bak
umount /boot
rm -rf /boot
mv /boot.bak /boot

# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.1.0-12-amd64
Found initrd image: /boot/initrd.img-6.1.0-12-amd64
Found linux image: /boot/vmlinuz-6.1.0-10-amd64
Found initrd image: /boot/initrd.img-6.1.0-10-amd64
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done

ただし、物理ブートパーティションをさらに削除すると、再起動は失敗します。

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): d
Partition number (1-4, default 4): 2

Partition 2 has been deleted.

Command (m for help): w
The partition table has been altered.
Syncing disks.

これにより grub エラーが発生します。

error: no such partition.
grub rescue>

grub再インストールすると、apt-get install --reinstall grub-pc次の grub エラーが発生します。

error: attempt to read or write outside of disk `hd0`.
grub rescue>

どうなりますか?

ベストアンサー1

update-grub実際にはGRUBのみが更新されます。構成ファイル存在する/boot/grub/grub.cfg

GRUBコアイメージ(主にBIOSブートパーティション内の場所)には、パーティション番号とパス名が含まれています。 GRUBは、/boot/grubGRUB構成ファイルとGRUBモジュール(例えばnormal.mod

/bootGRUB は Linux カーネルが起動する前に作業を完了するため、パーティションのマウント解除は GRUB には影響しません。 GRUBコアイメージにエンコードされた情報を更新しなかったため(古いファイルシステムをgrub-install /dev/sdaアンマウントし、その場所に移動して再度実行)、GRUBは削除されるまで古いパーティションを使用し続けます。プログラムを実行する前にGRUB構成を変更すると、変更が実際には適用されないことがわかります。/boot/boot.bak/bootupdate-grub

したがって、次に行う必要はありmv /boot.bak /bootませんが、次のようになりますupdate-grub

grub-install /dev/sda

実行すると、同じ効果を効果的に得ることができますapt-get install --reinstall grub-pc。しかし今、エラーメッセージはattempt to read or write outside of disk 'hd0'。これは、GRUBがBIOSルーチンを使用してディスクにアクセスし、明らかにQEMUのBIOSエミュレーションルーチンが> 2TBのディスクを処理するように更新されていないため、2TBの制限に達することを示しています。

(はい、私はDebian 12のインストールを分析しましたgrub-pc。このような簡単なインストールでは、GRUBコアイメージに含まれる唯一のモジュールは適切なファイルfshelp.modシステムドライバモジュール(たとえば、ext2.mod)適切なパーティションテーブルタイプモジュール(part_msdos.modまたはpart_gpt.mod))です。biosdisk.modBIOSがあります。ahci.modata.modデフォルトのインストールではこれを使用しません。)

残念ながら、ルートファイルシステムのサイズが約4TBの場合は、UEFIモードから起動に切り替える必要があります。セキュアブートをサポートしていないDebianのQEMUを使用してこれを行うには、パッケージをインストールしてovmfVM<os>のXML設定ファイルセクションを次のように変更する必要があります。

<os>
  <type arch='x86_64' machine='pc-q35-5.2'>hvm</type>
  <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE_4M.fd</loader>
  <nvram template='/usr/share/OVMF/OVMF_VARS_4M.fd'>/wherever/you/keep/your/VMs/vmname.nvram.fd</nvram>
  <boot dev='hd'/>
</os>

それではあなたはできます。

  1. 以前のパーティションのBIOSブートとスペースを再利用して/bootEFIシステムパーティションを作成します。
  2. /etc/fstabにインストールするには、1行を追加してください/boot/efi
  3. grub-pcそしてをsumgrub-pc-binに置き換えて、grub-efi-amd64grub-efi-amd64-bin
  4. 走るgrub-install --target=x86_64-efi --force-extra-removable /dev/sda

UEFIモードで正常に起動した後、再度grub-install /dev/sda実行してUEFI NVRAM起動変数が正しく設定されていることを確認してください。次に、efibootmgr実行しているオペレーティングシステム内で標準化された方法で起動設定をインストールして管理する方法を学びます。

ランタイムがまだUEFIモードで実行されていない場合、UEFI GRUBの2番目のコピーはgrub-install --target=x86_64-efiリムーバブルメディア/代替場所にインストールされます。--force-extra-removable/boot/efi/EFI/boot/bootx64.efi

セキュアブートも必要な場合は、NVRAMテンプレートをOVMF_CODE_4M.fd。追加してパッケージ化してからもう一度実行してください。OVMF_CODE_4M.ms.fdOVMF_VARS_4M.fdOVMF_VARS_4M.ms.fdgrub-efi-amd64-signedshim-signedgrub-install --target=x86_64-efi --force-extra-removable /dev/sda

おすすめ記事