将 ubuntu 移至单独磁盘后如何修复 grub?

将 ubuntu 移至单独磁盘后如何修复 grub?

先前的设置:

  • windows 10 + ubuntu 16.04 在 ssd1(/dev/nvme0n1) 上使用 grub 双启动。

当前设置:

  • ssd2(/dev/nvme1n1) 仅包含从上面克隆的 Windows 10。启动正常。

  • ssd1(/dev/nvme0n1) 仅包含 ubuntu,其他所有分区均已删除。无法在此处启动。

我希望能够再次进行双启动并从菜单中选择 Windows 10 或 Ubuntu。这是终端在实时 USB 中显示的内容:

ubuntu@ubuntu:~$ sudo fdisk -l
Disk /dev/loop0: 1.5 GiB, 1601015808 bytes, 3126984 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/nvme0n1: 238.5 GiB, 256060514304 bytes, 500118192 sectors
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: F6F46D18-D629-4D34-9F1A-0900B2600555

Device         Start       End   Sectors Size Type
/dev/nvme0n1p1  2048 104859647 104857600  50G Linux filesystem


Disk /dev/nvme1n1: 465.8 GiB, 500107862016 bytes, 976773168 sectors
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: 4C872172-3D07-4489-B670-6FB593A31318

Device            Start       End   Sectors   Size Type
/dev/nvme1n1p1     2048   1026047   1024000   500M EFI System
/dev/nvme1n1p2  1026048   1288191    262144   128M Microsoft reserved
/dev/nvme1n1p3  1288192   3033087   1744896   852M Windows recovery environment
/dev/nvme1n1p4  3033088  23244799  20211712   9.7G Windows recovery environment
/dev/nvme1n1p5 23244800 976773119 953528320 454.7G Microsoft basic data


Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F7921471-F857-4820-9356-237BF02CAD38

Device          Start        End    Sectors   Size Type
/dev/sda1          34     262177     262144   128M Microsoft reserved
/dev/sda2      264192 1919969279 1919705088 915.4G Microsoft basic data
/dev/sda3  1919969280 1953523711   33554432    16G Linux swap

Partition 1 does not start on physical sector boundary.


Disk /dev/sdb: 7.3 GiB, 7813988352 bytes, 15261696 sectors
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: dos
Disk identifier: 0xf5e34067

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1  *     8064 15124991 15116928  7.2G  c W95 FAT32 (LBA)
ubuntu@ubuntu:~$

lsblk:

ubuntu@ubuntu:~$ lsblk -f -o +PARTLABEL /dev/nvme1n1
NAME        FSTYPE LABEL      UUID                                 MOUNTPOINT PARTLABEL
nvme1n1                                                                      
├─nvme1n1p4 ntfs   Image      C66E65726E655BE5                                
├─nvme1n1p2                                                                   Microsoft reserved partition
├─nvme1n1p5 ntfs   OS         01D238F37C836540                                Basic data partition
├─nvme1n1p3 ntfs   WINRETOOLS AEFA63D2FA63957D                                
└─nvme1n1p1 vfat   ESP        9AB9-9DEA                                       EFI system partition
ubuntu@ubuntu:~$ lsblk -f -o +PARTLABEL /dev/nvme0n1
NAME        FSTYPE LABEL UUID                                 MOUNTPOINT                                         PARTLABEL
nvme0n1                                                                                                          
└─nvme0n1p1 ext4         1e27d729-df08-4d63-ad19-402e4c3340cf /media/ubuntu/1e27d729-df08-4d63-ad19-402e4c3340cf
ubuntu@ubuntu:~$

BLKIDD:

ubuntu@ubuntu:~$ blkid
/dev/nvme0n1p1: UUID="1e27d729-df08-4d63-ad19-402e4c3340cf" TYPE="ext4" PARTUUID="97c73deb-1ad6-4fa9-bc50-7dad24f84a68"
/dev/nvme1n1p1: LABEL="ESP" UUID="9AB9-9DEA" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="ac04e9de-aeb3-4595-9498-7e088a2178f7"
/dev/nvme1n1p3: LABEL="WINRETOOLS" UUID="AEFA63D2FA63957D" TYPE="ntfs" PARTUUID="162446b1-0911-41bf-8b91-6e92609105fe"
/dev/nvme1n1p4: LABEL="Image" UUID="C66E65726E655BE5" TYPE="ntfs" PARTUUID="8d16423b-2a17-45f3-ab56-95652bcb47af"
/dev/nvme1n1p5: LABEL="OS" UUID="01D238F37C836540" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="f8fe17da-3179-4c3e-98b0-ba7d0e8ad7ad"
/dev/sda2: LABEL="Data" UUID="86F26B62F26B5609" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="ff2d059c-108b-4e4a-9ef1-1d5645bf4e70"
/dev/sdb1: LABEL="UUI" UUID="0CDF-DB24" TYPE="vfat" PARTUUID="f5e34067-01"
ubuntu@ubuntu:~$

在 /etc/fstab 中:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p6 during installation
UUID=1e27d729-df08-4d63-ad19-402e4c3340cf /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
#UUID=9AB9-9DEA  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda3 during installation
UUID=74c15561-f026-4824-bc85-32e3ee9b5d90 none            swap    sw              0       0
UUID=9AB9-9DEA  /boot/efi   vfat    defaults    0   1

这是 grub.cfg:https://pastebin.com/cL1KFY5c

答案1

将 Ubuntu 从一个驱动器克隆到另一个驱动器或从一个分区克隆到另一个分区的最佳方法是使用重置 UUID 的脚本,/boot/grub/grub.cfg如下/etc/fstab所示:

如果您只是使用不会改变 UUID 的工具进行克隆,则需要boot-repair按照此处演示的方式使用:

运行后,boot-repair您可以获得 7 个 Windows 条目,因此请使用此方法删除多余的条目:

在多个操作系统中,您将获得在 grub 中创建的通用名称,例如:

  • Ubuntu
  • Windows 启动管理器(在 /dev/nvme0n1p2 上)
  • Windows 启动管理器(在 /dev/sda1 上)
  • Ubuntu 18.04 LTS (18.04)(位于 /dev/nvme0n1p6 上)

为了获得用户友好或更有意义的操作系统名称,请使用:

免责声明以上所有链接都是我写的。

相关内容