关于ubuntu的grub2引导

我的笔记本是win10,有SSD和机械两个盘,win10装在SSD。在机械盘压缩出了一些空间安装ubuntu双系统的时候没有修改引导安装位置,装到了机械盘的默认位置没有选到/boot里面。后来在win10下把ubuntu的盘格式化重装了一次ubuntu,把引导装到了/boot里。
现在通过win10采用easyBCD引导ubuntu,但是每次开机选择ubuntu后还会再进行一次grub2引导,我修改了配置文件/etc/default/grub,
GRUB_HIDDEN_TIMEOUT=0,
GRUB_TIMEOUT=0,
但开机选择ubuntu后还是会再进行一次grub2引导,怀疑是第一次安装ubuntu时装在机械盘默认位置上的grub2在起作用,请问如何才能将第一次安装ubuntu时安装在机械盘默认位置的grub2残留清除掉?
因为机械盘上装有win10里的部分软件和资料,所以不能格式化机械盘。

第1个回答  2018-03-25

步骤如下:

a  进入grub的命令模式。进入grub界面后按C键进入命令行界面。

b  先熟悉一下grub  的一些命令 grub>help

c  熟悉一下cat命令

d  root指令来指定/boot所在的分区

e  kernel指令来指定linux的内核,及所在的分区

f  用initrd命令来指定initrd文件

g  boot引导系统

cat命令的用法

cat指令是用来查看文件内容的,有时不知道Linux的/boot分区,以及/根分区所在的位置,要查看/etc/fstab的内容来得知, 这时,就要用到cat (hd[0-n],y)/etc/fstab 来获得这些内容;注意要学会用tab键命令补齐的功能;

grub> cat (     按tab 键会出来hd0或hd1之类的;

grub> cat (hd0, 注:输入hd0,然后再按tab键;会出来分区之类的;

grub> cat (hd0,6)

Possible partitions are:

Partition num: 0,  Filesystem type unknown, partition type 0x7

Partition num: 4,  Filesystem type is fat, partition type 0xb

Partition num: 5,  Filesystem type is reiserfs, partition type 0x83

Partition num: 6,  Filesystem type is ext2fs, partition type 0x83

Partition num: 7,  Filesystem type unknown, partition type 0x83

Partition num: 8,  Filesystem type is reiserfs, partition type 0x83

Partition num: 9,  Filesystem type unknown, partition type 0x82

grub> cat (hd0,6)/etc/fstab 注:比如我想查看一下 (hd0,6)/etc/fstab的内容就这样输入;

LABEL=/                 /                       ext3    defaults        1 1

/dev/devpts             /dev/pts                devpts  gid=5,mode=620  0 0

/dev/shm                /dev/shm                tmpfs   defaults        0 0

/dev/proc               /proc                   proc    defaults        0 0

/dev/sys                /sys                    sysfs   defaults        0 0

LABEL=SWAP-hda1         swap                    swap    defaults        0 0

/dev/hdc                /media/cdrecorder       auto    pamconsole,exec,noauto,

managed 0 0

主要查看/etc/fstab中的内容,主要是Linux的/分区及/boot是否是独立的分区;如果没有/boot类似的行,证明/boot和 Linux的/处于同一个硬盘分区;比如上面的例子中LABEL=/ 这行是极为重要的;说明Linux系统就安在标签为LABEL=/的分区中;

如果您的Linux系统/boot和/没有位于同一个分区,可能cat (hd[a-n],y) 查到的是类似下面的;

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

root (hd[0-n,y) 指令来指定/boot所在的分区;

其实这个root (hd[0,n],y)是可以省略的,如果省略了,要在kerenl 命令中指定;前面已经说过 (hd[0-n],y) 硬盘分区的表示方法的用途;主要是用来指定 /boot所在的分区;

eg:

grub> root (hd0,0)

kernel 指令,用来指定Linux的内核,及/所在的分区;

kernel 这个指令可能初学者有点怕,不知道内核在哪个分区,及内核文件名的全称是什么。不要忘记tab键的命令补齐的应用;

如果已经通过root (hd[0-n],y) 指定了/boot所在的分区,语法有两个:

如果/boot和Linux的/位于同一个分区,应该是下面的一种格式;

kernel /boot/vmlinuz在这里按tab键来补齐,就看到内核全称了 ro root=/dev/hd[a-z]X

如果/boot有自己独立的分区,应该是;

kernel /vmlinuz在这里按tab键来补齐,就看到内核全称了 ro root=/dev/hd[a-z]X

在这里 root=/dev/hd[a-z]X 是Linux 的/根所位于的分区,如果不知道是哪个分区,就用tab出来的来计算,一个一个的尝试;或用cat (hd[0-n],y)/etc/fstab 中得到Linux的/所在的分区或分区的标签;

grub> kernel /boot/在这里按tab键;这样就列出/boot中的文件了; 

Possible files are: grub initrd-2.6.11-1.1369_FC4.img System.map-2.6.11-1.1369

_FC4 config-2.6.11-1.1369_FC4 vmlinuz-2.6.11-1.1369_FC4 grubBAK memtest86+-1.55

.1 xen-syms xen.gz

grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/  

[Linux-bzImage, setup=0x1e00, size=0x18e473]

注解: root=LABEL=/ 是Linux的/所在的分区的文件系统的标签;如果您知道Linux的/在哪个具体的分区,用root=/dev/hd[a-z]X来指定也行。比如下面的一行也是可以的;

grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7

也可以把/boot所在的分区的指定 root (hd[0-n],y)这行省掉,直接在kernel 中指定/boot所在的分区;所以就在下面的语法;

如果是/boot和Linux的根同处一个分区;

kernel (hd[0-n],y)/boot/vmlinuz ro root=/dev/hd[a-z]X

比如:

grub>kernel

如果是/boot和Linux所在的根不在一个分区;则是;

kernel (hd[0-n],y)/vmlinuz  ro root=/dev/hd[a-z]X

grub> kernel (hd0,0)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7 

[Linux-bzImage, setup=0x1e00, size=0x18e473]

或下面的输入,以cat 出/etc/fstab内容为准;

grub> kernel (hd0,0)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/

[Linux-bzImage, setup=0x1e00, size=0x18e473]

initrd 命令行来指定initrd文件;

grub> initrd /boot/initrd在这里tab 来补齐;

grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img

[Linux-initrd @ 0x2e1000, 0x10e685 bytes]

如果/boot是独立的一个分区,应该是如下样子的语法;比如下面的;

grub> initrd /initrd在这里tab 来补齐;

grub> initrd /initrd-2.6.11-1.1369_FC4.img

[Linux-initrd @ 0x2e1000, 0x10e685 bytes]

boot 引导系统;

grub>boot

下面是在我机器上的命令:

grub> cat (hd0,0)/etc/fstab

# This file is edited by fstab-sync - see 'man fstab-sync' for details

LABEL=/                 /                       ext3    defaults        1 1

/dev/devpts             /dev/pts                devpts  gid=5,mode=620  0 0

/dev/shm                /dev/shm                tmpfs   defaults        0 0

/dev/proc               /proc                   proc    defaults        0 0

/dev/sys                /sys                    sysfs   defaults        0 0

LABEL=SWAP-hda1         swap                    swap    defaults        0 0

/dev/hdc                /media/cdrecorder       auto    pamconsole,exec,noauto,managed 0 0

grub> root (hd0,0)

Filesystem type is ext2fs, partition type 0x83

grub> kernel /boot/在这里按tab补齐,全列出/boot所有的文件;

Possible files are: grub initrd-2.6.11-1.1369_FC4.img System.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4 vmlinuz-2.6.11-1.1369_FC4  

memtest86+-1.55.1 xen-syms xen.gz

grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/  

[Linux-bzImage, setup=0x1e00, size=0x18e473]

grub> initrd /boot/在这里按tab补齐

Possible files are: grub initrd-2.6.11-1.1369_FC4.img System.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4 vmlinuz-2.6.11-1.1369_FC4 grubBAK

memtest86+-1.55.1 xen-syms xen.gz

grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img 注;输入intrd文件名的全名;

[Linux-initrd @ 0x2e1000, 0x10e685 bytes]

grub> boot

相似回答