如何在现有的 Lubuntu 安装上安装 grub?

Ion*_*zău 2 boot grub2 lubuntu

我有Lubuntu 16.04一个 USB 闪存。它有点工作,但grub未能安装。

现在我正在努力安装grub.

我现在在现场 cd 中。任何想法我应该做什么?

我尝试挂载分区并运行:

grub-install --root-directory=/mnt /dev/sda
Run Code Online (Sandbox Code Playgroud)

但这失败了

The file /mnt/boot/grub/stage1 not read correctly..
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

ter*_*don 5

您需要挂载本地驱动器,设置 chroot 环境并在其上安装 grub。

  1. 在某处挂载您将使用的分区/(我将调用驱动器/dev/sdb/分区sdb1,系统上的名称可能不同,您需要使用正确的名称):

    sudo mount /dev/sdb1 /mnt/foo
    
    Run Code Online (Sandbox Code Playgroud)
  2. 绑定grub需要访问的目录

    sudo mount --bind /dev /mnt/foo/dev && 
    sudo mount --bind /dev/pts /mnt/foo/dev/pts && 
    sudo mount --bind /proc /mnt/foo/proc && 
    sudo mount --bind /sys /mnt/foo/sys
    
    Run Code Online (Sandbox Code Playgroud)
  3. 设置chroot环境

    sudo chroot /mnt/foo
    
    Run Code Online (Sandbox Code Playgroud)
  4. 创建 grub 的配置文件:

    sudo grub-mkconfig -o /boot/grub/grub.cfg
    
    Run Code Online (Sandbox Code Playgroud)

    如果您安装了多个操作系统,请确保上面的命令列出了所有操作系统。例如:

    $ sudo grub-mkconfig -o /boot/grub/grub.cfg
    Generating grub.cfg ...
    Found background image: /usr/share/images/desktop-base/desktop-grub.png
    Found linux image: /boot/vmlinuz-3.10-2-amd64
    Found initrd image: /boot/initrd.img-3.10-2-amd64
    Found linux image: /boot/vmlinuz-3.2.0-4-amd64
    Found initrd image: /boot/initrd.img-3.2.0-4-amd64
    Found linux image: /boot/vmlinuz-3.2.0-3-amd64
    Found initrd image: /boot/initrd.img-3.2.0-3-amd64
    Found linux image: /boot/vmlinuz-3.2.0-2-amd64
    Found initrd image: /boot/initrd.img-3.2.0-2-amd64
    Found memtest86+ image: /boot/memtest86+.bin
    Found memtest86+ multiboot image: /boot/memtest86+_multiboot.bin
    Found Windows 7 (loader) on /dev/sda2
    done
    
    Run Code Online (Sandbox Code Playgroud)
  5. 现在将 grub 安装到驱动器的 MBR(记住更改/dev/sdb为您真正想要安装它的驱动器)

    grub-install /dev/sdb
    grub-install --recheck /dev/sdb
    
    Run Code Online (Sandbox Code Playgroud)
  6. 退出chroot并卸载所有内容,以便您正在运行的系统恢复正常:

    exit
    sudo umount /mnt/foo/dev/pts /mnt/foo/dev /mnt/foo/proc /mnt/foo/sys /mnt/foo
    
    Run Code Online (Sandbox Code Playgroud)
  7. 尝试从驱动器启动,这次你应该有一个 grub 菜单。