从 12.04 升级到 14.04 后 grub-install 失败(grub-pc 损坏)

从 12.04 升级到 14.04 后 grub-install 失败(grub-pc 损坏)

我刚刚从 Ubuntu 12.04 升级到 14.04,但是在安装过程中 grub-install 失败:

在此处输入图片描述

在此处输入图片描述

我继续安装,希望之后能修复 grub 问题。但是,我遇到了一些困难。我没有重新启动系统,因为我担心它无法重新启动。

这是我在尝试安装 grub 时经常遇到的错误:

 $ sudo grub-install /dev/mapper/isw_cjccfdbihf_Volume0p1 
 Installing for i386-pc platform.
 grub-install: error: cannot find a GRUB drive for /dev/mapper/isw_cjccfdbihf_Volume0p1.  Check your device.map.

(我也尝试过sudo grub-install /dev/sda但是也失败了并且出现完全相同的错误消息。)

该机器似乎使用 RAID 1 设置。以下是一些信息:

$ ls -algh /dev/mapper/
total 0
drwxr-xr-x  2 root     120 Aug 12 19:41 .
drwxr-xr-x 16 root    5.2K Aug 12 20:27 ..
crw-------  1 root 10, 236 Jul 28 10:30 control
lrwxrwxrwx  1 root       7 Aug 12 19:41 isw_cjccfdbihf_Volume0p1 -> ../dm-1
lrwxrwxrwx  1 root       7 Aug 12 19:41 isw_cjccfdbihf_Volume0p2 -> ../dm-2
lrwxrwxrwx  1 root       7 Aug 12 19:41 isw_cjccfdbihf_Volume0p5 -> ../dm-3

$ sudo grub-probe -t device /boot/grub
/dev/mapper/isw_cjccfdbihf_Volume0p1

$ sudo fdisk -l

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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 identifier: 0x0003b681

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   468514815   234256384   83  Linux
/dev/sda2       468516862   488390655     9936897    5  Extended
/dev/sda5       468516864   488390655     9936896   82  Linux swap / Solaris

Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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 identifier: 0x0003b681

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   468514815   234256384   83  Linux
/dev/sdb2       468516862   488390655     9936897    5  Extended
/dev/sdb5       468516864   488390655     9936896   82  Linux swap / Solaris

Disk /dev/mapper/isw_cjccfdbihf_Volume0p1: 239.9 GB, 239878537216 bytes
255 heads, 63 sectors/track, 29163 cylinders, total 468512768 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 identifier: 0x00000000

Disk /dev/mapper/isw_cjccfdbihf_Volume0p1 doesn't contain a valid partition table
fdisk: unable to read /dev/mapper/isw_cjccfdbihf_Volume0p2: Inappropriate ioctl for device

特别是最后两行似乎表明了一个更深层次的问题。:-(

错误消息grub-install还提到了 device.map 文件。

$ cat /boot/grub/device.map
cat: /boot/grub/device.map: No such file or directory

我尝试生成它但也没有帮助(错误消息没有改变):

$ sudo grub-mkdevicemap
$ cat /boot/grub/device.map
 (hd0)  /dev/disk/by-id/ata-WDC_WD2500AAJS-00YZCA0_WD-WCAYU7549707
 (hd1)  /dev/disk/by-id/ata-WDC_WD2500AAJS-00YZCA0_WD-WCAYU7501473

您有什么建议我下一步该尝试什么吗?任何帮助我都非常感谢。

更新:

$ debconf-show grub-pc
debconf: DbDriver "passwords" warning: could not open /var/cache/debconf    /passwords.dat: Permission denied
* grub-pc/install_devices: /dev/disk/by-id/dm-name-isw_cjccfdbihf_Volume0
  grub-pc/kopt_extracted: false
  grub-pc/partition_description:
* grub2/linux_cmdline:
  grub-pc/install_devices_empty: false
  grub-pc/timeout: 10
  grub-pc/install_devices_failed_upgrade: true
* grub2/linux_cmdline_default: quiet splash
  grub-pc/postrm_purge_boot_grub: false
  grub-pc/hidden_timeout: true
  grub-pc/disk_description:
  grub-pc/mixed_legacy_and_grub2: true
  grub2/kfreebsd_cmdline_default: quiet splash
  grub2/device_map_regenerated:
* grub-pc/install_devices_failed: true
  grub-pc/chainload_from_menu.lst: true
  grub-pc/install_devices_disks_changed:
  grub2/kfreebsd_cmdline:

请注意以下这一行:grub-pc/install_devices: /dev/disk/by-id/dm-name-isw_cjccfdbihf_Volume0

现在的内容/etc/fstab

proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/mapper/isw_cjccfdbihf_Volume01 /               ext4    errors=remount-ro 0       1
/dev/mapper/isw_cjccfdbihf_Volume0p5 none            swap    sw              0       0

2012 年的备份文件显示交换条目略有不同(Volume05 而不是 Volume0p5),这表明名称可能已更改:

 # Note that this is an old file at the time the system was installed (Ubuntu 10.04 or 10.10)
 # (This is also the time from which the original grub configuration is from, isn't it?!)
 /dev/mapper/isw_cjccfdbihf_Volume01 /               ext4    errors=remount-ro 0       1
 /dev/mapper/isw_cjccfdbihf_Volume05 none            swap    sw              0       0

因此,也许这与“_Volume01”与“_Volume0p1”与“_Volume0”有关。/etc/fstab显示“01”,ls /dev/mapper返回映射“0p1”、“0p2”和“0p5”(交换),最后debconf-show grub-pc显示“Volume0”。我认为这种不一致是问题的根源。

现在我想知道:

  1. grub-pc/install_devices输出中的行应该debconf-show grub-pc是什么?
  2. 我如何更改 Grub 设置,以便尝试不同的值?

我还刚刚注意到 grub-pc 的安装已损坏:

$ sudo dpkg-reconfigure grub-pc
/usr/sbin/dpkg-reconfigure: grub-pc is broken or not fully installed

答案1

以下是我解决问题的方法:

在安静的时刻,我有时间冒停机的风险。所以我用 Ubuntu 14.04 Live CD 重新启动系统并重新安装了 Grub。我没有遇到问题,之后系统正常启动。

以下是一般描述:https://help.ubuntu.com/community/Grub2/Installing#via_the_LiveCD_terminal

根据记忆,以下是我在具体情况下使用的命令:

从 Live CD 启动并执行以下命令:

 $ sudo su
 $ mount /dev/mapper/isw_cjccfdbihf_Volume0p1 /mnt

 (Sorry, I'm not 100% sure whether the target was /dev/mapper/isw_cjccfdbihf_Volume0p1 or
  /dev/sda. I think it was /dev/mapper/isw_cjccfdbihf_Volume0p1.)
 $ grub-install --root-directory=/mnt /dev/mapper/isw_cjccfdbihf_Volume0p1
 $ reboot

之后,系统重新启动。最后,我可以用 来完成中断的安装sudo apt-get install

目前,/etc/fstab仍列出/dev/mapper/isw_cjccfdbihf_Volume01根目录。我仍然不知道这是否正确,但我还没有尝试将其更改为/dev/mapper/isw_cjccfdbihf_Volume0p1以查看重启后它是否仍然有效。

答案2

在 RAID 设置中安装 grub2 失败,因为设备命名随着更新而发生了某种变化,但尚未重新启动的运行系统使用了不同的命名方案。

如果 grub-install 失败,只需取消它并重新启动即可。之前安装的 grub 仍然指向有效内核,可以毫无问题地启动。重新启动后,grub 可以毫无问题地安装。

答案3

太棒了。我只需要更改一件事就可以避免执行grub-install命令时出现此错误:

/usr/bin/grub-bios-setup: warning: Embedding is not possible. GRUB
can only be installed in this setup by using blocklists. However,
blocklists are UNRELIABLE and their use is discouraged..
/usr/bin/grub-bios-setup: error: will not proceed with blocklists.

使用上面的命令,我更改了 grub-install 命令以将 GRUB 安装到 MBR 而不是分区,如下所示(删除“p1”):

$ grub-install --root-directory=/mnt /dev/mapper/isw_cjccfdbihf_Volume0

否则,它确实让我省去了很多麻烦。我非常感激。

答案4

对我来说,这些答案都不起作用,所以我重新启动并使用了启动修复盘修复了这个问题。这有效。呼...!

相关内容